locallib.php 382 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. //'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'all_submissions' => '$this->all_submissions();',
  278. 'delete_submissions' => '$this->delete_submissions();',
  279. 'download_submissions' => '$this->download_submissions();',
  280. 'open_individual_submission' => '$this->open_individual_submission();',
  281. 'get_individual_submission' => '$this->get_individual_submission();',
  282. 'get_student_submission' => '$this->get_student_submission();',
  283. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  284. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  285. );
  286. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  287. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  288. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  289. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  290. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  291. }
  292. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  293. eval($action_iassign_limit[$this->action]);
  294. }
  295. else { // Student reaches this point
  296. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  297. // Arrive here with: "get_answer"; "view"
  298. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  299. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  300. }
  301. } // function action()
  302. /// This method prints the student submission to a specific exercise
  303. function get_student_submission () {
  304. global $DB;
  305. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  306. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  307. if (!$student || !$exercise) exit;
  308. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  309. if ($iassign_submission)
  310. print($iassign_submission->answer);
  311. die();
  312. }
  313. /// This method prints the teacher exercise
  314. function get_teacher_exercise () {
  315. global $DB, $COURSE;
  316. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  317. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  318. $fs = get_file_storage(); // Get reference to all files in Moodle data
  319. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  320. foreach ($files as $file) {
  321. if ($file->get_filename() != ".") {
  322. print($file->get_content());
  323. }
  324. }
  325. die();
  326. }
  327. /// This method receives the data from auto_eval event
  328. /// @see auto_evaluate()
  329. function post_auto_eval_result () {
  330. global $COURSE, $CFG, $USER, $DB;
  331. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  332. exit;
  333. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  334. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  335. $student = optional_param('student', -1, PARAM_INT);
  336. $grade = optional_param('grade', 0, PARAM_FLOAT);
  337. // 1: Recuperar a nota atual:
  338. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  339. // 2: Atualizar a tabela:
  340. $update_entry = new stdClass();
  341. $update_entry->id = $actual->id;
  342. $update_entry->previous_grade = $actual->grade;
  343. $update_entry->grade = $grade;
  344. // Update the iassign_submission
  345. $DB->update_record("iassign_submission", $update_entry);
  346. }
  347. /// Function to help download all_submissions files
  348. function download_submissions_help ($list) {
  349. global $DB, $CFG, $OUTPUT;
  350. // Get list of iLMs
  351. $ilm_list = $DB->get_records("iassign_ilm");
  352. // Get list of enrolled students:
  353. $params = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  359. $json_obj = new stdclass();
  360. $json_obj->submissions = [];
  361. $csvfields = [];
  362. $csvfields[] = 'submissionid';
  363. $csvfields[] = 'file';
  364. $csvfields[] = 'filesize';
  365. $csvfields[] = 'timestamp';
  366. $csvfields[] = 'humandate';
  367. $csvfields[] = 'grade';
  368. $csvfields[] = 'userid';
  369. $csvfields[] = 'exerciseid';
  370. $json_obj->submissions[] = $csvfields;
  371. $exercise_dir = [];
  372. $exercises_list = [];
  373. foreach ($list as $item) {
  374. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  375. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  376. $exercises_list[] = $temp;
  377. $exercise_dir[] = $temp->id;
  378. }
  379. }
  380. $student_dir = [];
  381. $students_list = [];
  382. foreach ($list as $item) {
  383. if (!in_array($item->userid, $student_dir)) {
  384. $temp = $DB->get_record("user", array("id" => $item->userid));
  385. $students_list[] = $temp;
  386. $student_dir[] = $temp->id;
  387. }
  388. }
  389. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  391. $zip = new zip_archive(); // create ZIP
  392. $zip->open($zip_filename);
  393. foreach($exercises_list as $exercise) {
  394. $dir_ex = iassign_utils::format_filename($exercise->name);
  395. $zip->add_directory(
  396. $dir_ex
  397. );
  398. $extension_ilm = '';
  399. foreach ($ilm_list as $ilm) {
  400. if ($exercise->iassign_ilmid == $ilm->id) {
  401. $extension_ilm = $ilm->extension;
  402. break;
  403. }
  404. }
  405. foreach ($students_list as $student) {
  406. $individual_dir =
  407. $dir_ex . DIRECTORY_SEPARATOR .
  408. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  409. $zip->add_directory(
  410. $individual_dir
  411. );
  412. $i = 1;
  413. foreach($list as $item) {
  414. if ($item->userid == $student->id
  415. && $item->iassign_statementid == $exercise->id) {
  416. $date = new DateTime();
  417. $date->setTimestamp($item->timecreated);
  418. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s') . '.' . $extension_ilm);
  419. $zip->add_file_from_string($new_file, $item->answer);
  420. $temp_json = [];
  421. $temp_json[] = intval($item->id);
  422. $temp_json[] = $new_file;
  423. $temp_json[] = strlen($new_file);
  424. $temp_json[] = intval($item->timecreated);
  425. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  426. $temp_json[] = doubleval($item->grade);
  427. $temp_json[] = intval($item->userid);
  428. $temp_json[] = intval($exercise->id);
  429. $json_obj->submissions[] = $temp_json;
  430. }
  431. }
  432. }
  433. }
  434. $csv_str = "";
  435. foreach($json_obj->submissions as $sub) {
  436. $csv_str .= $this->csvstr($sub) . "\n";
  437. }
  438. $zip->add_file_from_string('index.csv', $csv_str);
  439. $zip->close();
  440. iassign_utils::download_file($zip_filename);
  441. exit;
  442. }
  443. function csvstr(array $fields) : string {
  444. $f = fopen('php://memory', 'r+');
  445. if (fputcsv($f, $fields) === false) {
  446. return false;
  447. }
  448. rewind($f);
  449. $csv_line = stream_get_contents($f);
  450. return rtrim($csv_line);
  451. }
  452. /// Download submissions from table iassign_allsubmissions
  453. function download_submissions () {
  454. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  455. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  456. exit;
  457. $type = optional_param('type', NULL, PARAM_TEXT);
  458. $item = optional_param('item', NULL, PARAM_TEXT);
  459. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  460. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  461. $sub_list = [];
  462. if ($type == 'individual') {
  463. $sub_list[] = $DB->get_record(
  464. 'iassign_allsubmissions', array('id' => $item));
  465. } elseif ($type == 'student') {
  466. $sub_list = $DB->get_records(
  467. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  468. } elseif ($type == 'exercise') {
  469. $sub_list = $DB->get_records(
  470. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  471. } elseif ($type == 'block') {
  472. $exercises_in_block = $DB->get_records(
  473. 'iassign_statement', array('iassignid' => $iassign_id));
  474. foreach ($exercises_in_block as $exercise) {
  475. $temp = $DB->get_records(
  476. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  477. $sub_list = array_merge($sub_list, $temp);
  478. }
  479. }
  480. $this->download_submissions_help($sub_list);
  481. }
  482. /// Delete submissions in table iassign_allsubmissions
  483. function delete_submissions () {
  484. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  485. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  486. exit;
  487. $type = optional_param('type', NULL, PARAM_TEXT);
  488. $item = optional_param('item', NULL, PARAM_TEXT);
  489. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  490. if ($type == 'individual') {
  491. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  492. } elseif ($type == 'student') {
  493. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  494. } elseif ($type == 'exercise') {
  495. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  496. }
  497. }
  498. function get_individual_submission () {
  499. global $DB, $USER;
  500. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  501. exit;
  502. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  503. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  504. print $submission->answer;
  505. }
  506. /// Open individual submission
  507. function open_individual_submission () {
  508. global $DB, $USER, $CFG;
  509. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  510. exit;
  511. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  512. $id = $this->cm->id;
  513. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  514. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  515. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  516. //print_r($atual_submission);
  517. $all_submissions = $DB->get_records('iassign_allsubmissions',
  518. array('iassign_statementid' => $atual_submission->iassign_statementid,
  519. 'userid' => $atual_submission->userid));
  520. $previous = null;
  521. $next = null;
  522. $i = 0;
  523. $found = false;
  524. foreach($all_submissions as $individual) {
  525. if (!$found && $individual->id != $submissionid) {
  526. $previous = $individual;
  527. }
  528. if ($found) {
  529. $next = $individual;
  530. break;
  531. }
  532. if ($individual->id === $submissionid) {
  533. $found = true;
  534. }
  535. $i ++;
  536. }
  537. print '<center style="padding-top: 2rem;">';
  538. if ($previous) {
  539. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  540. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  541. } else {
  542. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  543. }
  544. print ' (' . $i . '/' . count($all_submissions) . ')';
  545. if ($next) {
  546. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  547. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  548. } else {
  549. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  550. }
  551. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  552. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "view", 'Proposition' => $url]);
  553. print '</center>';
  554. }
  555. /// Manage all submissions in exercises to table iassign_allsubmissions
  556. function all_submissions () {
  557. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  558. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  559. exit;
  560. print $OUTPUT->header();
  561. $id = $this->cm->id;
  562. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  563. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  564. print '
  565. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  566. <div class="modal-dialog modal-dialog-centered" role="document">
  567. <div class="modal-content">
  568. <div class="modal-header">
  569. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  570. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  571. <span aria-hidden="true">&times;</span>
  572. </button>
  573. </div>
  574. <div class="modal-body">'
  575. . get_string('all_submissions_manager_confirm', 'iassign')
  576. . '</div>
  577. <div class="modal-footer">
  578. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  579. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  580. </div>
  581. </div>
  582. </div>
  583. </div>';
  584. print '
  585. <script>
  586. var sub_type;
  587. var sub_item;
  588. var sub_el;
  589. var sub_exercise;
  590. function delete_submission (type, item, el, exercise = 0) {
  591. sub_type = type;
  592. sub_item = item;
  593. sub_exercise = exercise;
  594. sub_el = el.closest("tr");
  595. if (!sub_el) sub_el = el.closest("a");
  596. $("#modalConfirm").modal();
  597. }
  598. function confirm_delete () {
  599. var url = "'.$enderecoPOST.'&action=delete_submissions";
  600. var xhttp = new XMLHttpRequest();
  601. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  602. xhttp.send();
  603. $("#modalConfirm").modal("hide");
  604. if ($(sub_el).attr("href"))
  605. $($(sub_el).attr("href")).remove();
  606. if (sub_el) sub_el.remove();
  607. }
  608. function download_submission(type, item, exercise = 0, iassign = 0) {
  609. var url = "'.$enderecoPOST.'&action=download_submissions";
  610. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  611. document.location = url;
  612. }
  613. function open_submission(item) {
  614. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  615. var poupup = window.open(
  616. url,
  617. "popup",
  618. "width=900,height=900");
  619. }
  620. </script>';
  621. // Get list of exercises in the instance:
  622. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  623. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  624. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  625. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  626. // Get list of enrolled students:
  627. $params = array('shortname' => 'student');
  628. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  629. $context = context_course::instance($this->course->id);
  630. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  631. $students_list = $DB->get_records_sql(
  632. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  633. print '<div>';
  634. foreach ($exercises_list as $exercise) {
  635. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  636. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  637. print '
  638. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  639. . $exercise->name
  640. . ' - ' . $iassign_ilm->name
  641. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  642. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  643. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  644. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  645. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  646. . '</a>';
  647. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  648. foreach ($students_list as $student) {
  649. $total = 0;
  650. $student_submissions = [];
  651. foreach ($submissions_list as $submission) {
  652. if ($submission->userid == $student->userid) {
  653. $student_submissions[] = $submission;
  654. $total ++;
  655. }
  656. }
  657. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  658. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  659. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  660. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  661. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  662. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  663. . ' </a>';
  664. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  665. print '<table class="table table-striped table-hover"><thead>
  666. <tr>
  667. <th scope="col">#</th>
  668. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  669. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  670. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  671. </tr>
  672. </thead><tbody>';
  673. $i = 1;
  674. foreach ($student_submissions as $individual) {
  675. $date = new DateTime();
  676. $date->setTimestamp($individual->timecreated);
  677. print '<tr>';
  678. print '<td>'.$i++.'</td>';
  679. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  680. print '<td>'.$individual->grade.'</td>';
  681. print '<td>
  682. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  683. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  684. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  685. print '</tr>';
  686. }
  687. print '</tbody></table>';
  688. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  689. print '</div>';
  690. }
  691. print '</div>';
  692. }
  693. print '</div>';
  694. print $OUTPUT->footer();
  695. }
  696. /// This method runs activities auto evaluation in teacher area
  697. function auto_evaluate () {
  698. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  699. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  700. exit;
  701. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  702. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  703. // Get list of exercises in the instance:
  704. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  705. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  706. // Get list of enrolled students:
  707. $params = array('shortname' => 'student');
  708. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  709. $context = context_course::instance($this->course->id);
  710. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  711. $students_list = $DB->get_records_sql(
  712. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  713. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  714. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  715. print $OUTPUT->header();
  716. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  717. print '<ul style="list-style-type: none; margin: 1em;">';
  718. foreach ($exercises_list as $exercise) {
  719. $matches = [];
  720. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  721. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  722. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  723. if ($matches[0][0]) {
  724. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
  725. } else {
  726. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
  727. }
  728. } else {
  729. if ($matches[0][0]) {
  730. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>' . $exercise->name . '</li>';
  731. } else {
  732. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>(' . $exercise->id . ') - ' . $exercise->name . '</li>';
  733. }
  734. }
  735. }
  736. print '</ul>
  737. <center>
  738. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  739. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  740. <div id="evaluate_message" style="color: red"></div>
  741. <div id="evaluate_alerts"></div>
  742. <div>
  743. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  744. <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
  745. </div>
  746. </center>'; // close "
  747. print ' </div>' + "\n";
  748. print ' <script>';
  749. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  750. print ' var submissions = [';
  751. // Get list of student id have submit for each exercise:
  752. foreach ($exercises_list as $exercise) {
  753. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  754. print '
  755. {
  756. "exerciseid": "' . $exercise->id . '",
  757. "grade": ' . $exercise->grade . ',
  758. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  759. "submited": ['; // "
  760. $params = array('iassign_statementid' => $exercise->id);
  761. $submited = $DB->get_records_sql( // Get userid and his grade
  762. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  763. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  764. foreach ($submited as $ss) {
  765. print($ss->userid . ',');
  766. }
  767. print '],';
  768. print '"allgrades": [';
  769. foreach ($submited as $ss) {
  770. print( $ss->grade . ',');
  771. }
  772. print ']
  773. },'; // close "
  774. } // foreach ($exercises_list as $exercise)
  775. print " ];\n";
  776. print '
  777. var total_submissions = 0;
  778. var selected_exercises;
  779. var count_steps;
  780. var value_by_step;
  781. var stoped = false;
  782. var time_interval = 5000;
  783. var var_interval;
  784. function add_hover_th (id_th, id_li) {
  785. $("#" + id_th).hover(function() {
  786. $("#" + id_li).css("background-color", "#d9d8d8");
  787. $(this).css("background-color", "#d9d8d8");
  788. }, function() {
  789. $("#" + id_li).css("background-color", "");
  790. $(this).css("background-color", "");
  791. });
  792. }
  793. function start_evaluation () {
  794. stoped = false;
  795. $("#progress_bar").css("display", "none");
  796. $("#evaluate_message").text("");
  797. $("#evaluate_alerts").text("");
  798. $(".added-col").remove();
  799. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  800. selected_exercises = [];
  801. var c = 0;
  802. for (var i = 0; i < exercises.length; i++) {
  803. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  804. selected_exercises[c++] = exercises[i];
  805. }
  806. }
  807. if (selected_exercises.length == 0) {
  808. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  809. return;
  810. } else {
  811. $("input:checkbox").attr("disabled", true);
  812. for (var i = 0; i < selected_exercises.length; i++) {
  813. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  814. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  815. $("#table-results tbody tr").each(function(e) {
  816. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  817. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  818. });
  819. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  820. }
  821. $("#button_start").prop("disabled", true);
  822. $("#button_stop").prop("disabled", false);
  823. $("#progress_bar").css("display", "block");
  824. }
  825. total_submissions = selected_exercises.length * students.length;
  826. count_steps = 0;
  827. value_by_step = 100/total_submissions;
  828. actual_exercise = 0;
  829. actual_student = 0;
  830. actual_submission = 0;
  831. get_original_propositions();
  832. var_interval = setInterval(verifyBreak, time_interval);
  833. } // function start_evaluation()
  834. var actual_exercise;
  835. var actual_student;
  836. var actual_submission;
  837. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  838. function run_individual_evaluation () {
  839. if (stoped) return;
  840. // Verify if student really sent his answer
  841. var found = false;
  842. for (var j = 0; j < submissions.length; j++) {
  843. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  844. for (var k = 0; k < submissions[j].submited.length; k++) {
  845. if (students[actual_student] == submissions[j].submited[k]) {
  846. found = true;
  847. break;
  848. }
  849. }
  850. break;
  851. }
  852. }
  853. if (found == false) {
  854. postResultAutoEval();
  855. } else {
  856. // If it was sent, search it...
  857. var final_url = "";
  858. var student_answer = "' . $CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=" . $this->cm->id . '" + "&iassign_student=" + students[actual_student] + "&iassign_exercise=" + selected_exercises[actual_exercise];
  859. for (var j = 0; j < submissions.length; j++) {
  860. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  861. final_url = submissions[j].ilm;
  862. break;
  863. }
  864. }
  865. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  866. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  867. window.frames["ifrm"].location=final_url;
  868. }
  869. } // function run_individual_evaluation()
  870. var break_student = -1;
  871. var break_exercise = -1;
  872. function verifyBreak () {
  873. if (actual_student == break_student && actual_exercise == break_exercise) {
  874. postResultAutoEval(-6);
  875. break_student = -1;
  876. break_exercise = -1;
  877. return;
  878. } else {
  879. break_student = actual_student;
  880. break_exercise = actual_exercise;
  881. }
  882. }
  883. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  884. function getStudentAnswerURL () {
  885. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  886. }
  887. // This function is called by the iLM!!!
  888. function getAutoEvalOriginalData () {
  889. return original_propositions[actual_exercise];
  890. }
  891. function updateProgressBar () {
  892. if (stoped) return;
  893. var temp = (count_steps * value_by_step)|0;
  894. count_steps ++;
  895. temp = temp > 100 ? 100 : temp;
  896. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  897. if (temp >= 100) {
  898. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  899. $("#button_start").prop("disabled", false);
  900. $("#button_stop").prop("disabled", true);
  901. $("input:checkbox").attr("disabled", false);
  902. clearInterval(var_interval);
  903. }
  904. }
  905. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  906. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  907. function postResultAutoEval (grade = null) {
  908. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  909. if (grade == null) {
  910. $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
  911. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  912. } else {
  913. // Verify if the re-evaluation grade is the of that one registered:
  914. var actual_value = 0;
  915. var actual_student_grade = 0;
  916. for (var k = 0; k < submissions.length; k++) {
  917. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  918. actual_value = submissions[k].grade;
  919. for (var h = 0; h < submissions[k].submited.length; h++) {
  920. if (submissions[k].submited[h] == students[actual_student]) {
  921. actual_student_grade = submissions[k].allgrades[h];
  922. break;
  923. }
  924. }
  925. break;
  926. }
  927. }
  928. // @FeedbackConvention
  929. if (grade < 0) {
  930. switch (grade) {
  931. case -1:
  932. // Test-cases are empty:
  933. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
  934. var mm = actual_exercise;
  935. $("#"+id_t).find(".details-button").click(function(e) {
  936. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
  937. });
  938. break;
  939. case -2:
  940. // Test-cases were manually altered by the student (fraud!):
  941. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  942. var mm = actual_exercise;
  943. $("#"+id_t).find(".details-button").click(function(e) {
  944. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  945. });
  946. $.ajax({
  947. dataType: "html",
  948. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+selected_exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
  949. success: function(d) {}
  950. });
  951. break;
  952. case -5:
  953. // Execution failed:
  954. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
  955. var mm = actual_exercise;
  956. $("#"+id_t).find(".details-button").click(function(e) {
  957. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
  958. });
  959. break;
  960. case -6: // iLM not answering was detected in "verifyBreak()"
  961. // The iLM are not answering:
  962. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-clock-o fa-6" aria-hidden="true" style="color: orange; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_title_time', 'iassign').'"></i></i>\');
  963. $("#"+id_t).find(".details-button").click(function(e) {
  964. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  965. });
  966. break;
  967. }
  968. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  969. } else {
  970. console.log((grade), (actual_student_grade));
  971. if ((grade) == (actual_student_grade)) {
  972. $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
  973. } else { // Notas diferem:
  974. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
  975. var mm = actual_exercise;
  976. $("#"+id_t).find(".details-button").click(function(e) {
  977. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  978. });
  979. // Send to the endpoint the post_auto_eval_result to verify:
  980. $.ajax({
  981. dataType: "html",
  982. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=post_auto_eval_result&id=' . $this->cm->id . '&iassign_exercise=" + selected_exercises[actual_exercise] + "&student=" + students[actual_student] + "&grade=" + (grade),
  983. success: function(d) {}
  984. });
  985. }
  986. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  987. }
  988. }
  989. updateProgressBar();
  990. // Does it must continue in the same exercise or stop?
  991. if (actual_student < students.length) {
  992. actual_student ++;
  993. run_individual_evaluation();
  994. } else {
  995. actual_student = 0;
  996. // Does it go to next exercise or is it finished?
  997. if (actual_exercise < selected_exercises.length) {
  998. actual_exercise++;
  999. run_individual_evaluation();
  1000. } else {
  1001. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1002. }
  1003. }
  1004. }
  1005. var original_propositions;
  1006. function get_original_propositions () {
  1007. original_propositions = [];
  1008. var count = 0;
  1009. for (var i = 0; i < exercises.length; i++) {
  1010. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1011. $.ajax({
  1012. dataType: "html",
  1013. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1014. success: function(d) { // variable "d" has the iLM content
  1015. original_propositions[count] = d; // exercise original content
  1016. count ++;
  1017. if (count == selected_exercises.length) {
  1018. run_individual_evaluation();
  1019. }
  1020. }
  1021. });
  1022. }
  1023. }
  1024. }
  1025. function stop_evaluation () {
  1026. stoped = true;
  1027. $("#button_start").prop("disabled", false);
  1028. $("#button_stop").prop("disabled", true);
  1029. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1030. $("input:checkbox").attr("disabled", false);
  1031. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  1032. clearInterval(var_interval);
  1033. }
  1034. var exercises = [ '; // '
  1035. foreach ($exercises_list as $exercise) {
  1036. print $exercise->id . ',';
  1037. }
  1038. print ' ];';
  1039. print ' var students = [ ';
  1040. foreach ($students_list as $student) {
  1041. print $student->userid . ',';
  1042. }
  1043. print '];';
  1044. print ' var ilms = [';
  1045. foreach ($exercises_list as $exercise) {
  1046. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1047. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1048. }
  1049. print ']';
  1050. print '</script>';
  1051. print '
  1052. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1053. <div class="modal-dialog modal-dialog-centered" role="document">
  1054. <div class="modal-content">
  1055. <div class="modal-header">
  1056. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1057. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1058. <span aria-hidden="true">&times;</span>
  1059. </button>
  1060. </div>
  1061. <div class="modal-body">
  1062. ...
  1063. </div>
  1064. <div class="modal-footer">
  1065. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1066. </div>
  1067. </div>
  1068. </div>
  1069. </div>'; //
  1070. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1071. print '<table id="table-results" class="table table-hover m-t-1">
  1072. <thead>
  1073. <tr id="cols-exercises">
  1074. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1075. </tr>
  1076. </thead>
  1077. <tbody>'; // "
  1078. foreach ($students_list as $student) {
  1079. $user = $DB->get_record('user', array('id' => $student->userid));
  1080. $avatar = new user_picture($user);
  1081. $avatar->courseid = $COURSE->id;
  1082. $avatar->link = true;
  1083. print
  1084. '<tr data-student="'.$student->userid.'">
  1085. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1086. </tr>'; // "
  1087. }
  1088. print '</tbody>
  1089. </table>'; // "
  1090. print $OUTPUT->footer();
  1091. } // function auto_evaluate()
  1092. /// This method moves an iAssign activity
  1093. function move_activity () {
  1094. global $USER, $CFG, $DB, $COURSE;
  1095. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1096. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1097. $update_entry_new_iassign = new stdClass();
  1098. $update_entry_new_iassign->id = $iassign_id;
  1099. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1100. // Update the iassign_statement
  1101. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1102. // Update file context
  1103. $c_i = context_module::instance($this->cm->id);
  1104. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1105. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1106. $path_module = context_course::instance($COURSE->id);
  1107. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1108. if ($context_file) {
  1109. $id_context = $context_file->id;
  1110. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1111. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1112. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  1113. foreach ($files as $value) {
  1114. if ($value->get_filename() != ".") {
  1115. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1116. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1117. $updateentry = new stdClass();
  1118. $updateentry->id = $iassign_id;
  1119. $updateentry->file = $newfile->get_itemid();
  1120. $DB->update_record("iassign_statement", $updateentry);
  1121. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. $this->return_home_course('moved_activity');
  1127. exit;
  1128. }
  1129. /// This method duplicates an iAssign activity
  1130. function duplicate_activity () {
  1131. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1132. $id = $this->cm->id;
  1133. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1134. $context = context_module::instance($this->cm->id);
  1135. $contextuser = context_user::instance($USER->id);
  1136. // Get the the iAssign acitivity to be duplicated
  1137. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1138. // Remove the current id of activity
  1139. $iassign_statement->id=0;
  1140. // Get the information about current author, and add this information in author_modified field
  1141. $author = $DB->get_record("user", array('id' => $USER->id));
  1142. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1143. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1144. // Store the activity in the table
  1145. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1146. // Duplicate activity file
  1147. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1148. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  1149. foreach ($files as $value) {
  1150. if ($value->get_filename() != ".") {
  1151. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1152. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1153. $updateentry = new stdClass();
  1154. $updateentry->id = $id_;
  1155. $updateentry->file = $newfile->get_itemid();
  1156. // Update the duplicated iLM iAssign with new file id
  1157. $DB->update_record("iassign_statement", $updateentry);
  1158. }
  1159. }
  1160. }
  1161. // log event --------------------------------------------------------------------------------------
  1162. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1163. $this->return_home_course('duplicated_activity');
  1164. exit;
  1165. }
  1166. // / This method gets the content from comment and register it
  1167. function add_comment () {
  1168. global $USER, $DB;
  1169. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1170. $comment = false;
  1171. if ($submission_comment)
  1172. $comment = $this->write_comment_submission();
  1173. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1174. if (!$id_submission) {
  1175. $iassign_submission =
  1176. $DB->get_record("iassign_submission",
  1177. array(
  1178. "iassign_statementid" => $this->activity->get_activity()->id,
  1179. "userid" => $USER->id
  1180. )
  1181. );
  1182. if ($iassign_submission) {
  1183. $id_submission = $iassign_submission->id;
  1184. }
  1185. }
  1186. echo $this->search_comment_submission($id_submission);
  1187. }
  1188. /// This method gets the content from the iLM and register it
  1189. // It could be the "exercise template" (teacher) or an answer (student)
  1190. function get_answer () {
  1191. global $USER, $CFG, $DB, $OUTPUT;
  1192. $id = $this->cm->id;
  1193. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1194. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1195. if ($submission_ajax == 1) ob_start();
  1196. $comment = false;
  1197. if ($submission_comment)
  1198. $comment = $this->write_comment_submission();
  1199. // receives data of iLM using the current activity
  1200. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1201. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1202. // receives data of submission of current activity
  1203. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1204. // receives post and get
  1205. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1206. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1207. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1208. $iLM_PARAM_ArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // answer file (ATTENTION: do not change format, use RAW in order to ensure the correct content)
  1209. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1210. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1211. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1212. $msg = '';
  1213. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1214. $newentry = new stdClass();
  1215. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1216. $newentry->userid = $this->userid_iassign;
  1217. $newentry->timecreated = time();
  1218. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1219. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1220. $DB->insert_record("iassign_allsubmissions", $newentry);
  1221. }
  1222. // Feedback
  1223. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1224. $str_action = "view"; // repeat
  1225. if (strtolower($iassign_ilm->name) == "igeom") {
  1226. }
  1227. $title = get_string('evaluate_iassign', 'iassign');
  1228. print $OUTPUT->header();
  1229. print $OUTPUT->box_start();
  1230. // Action = { view ; repeat ; viewsubmission }
  1231. // * 'view' => it is impossible to re-send answer (this is correct with iGeom because its model to ensure security - do not allow the learner's access to the "answer model")
  1232. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1233. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1234. $return = $CFG->wwwroot . "/mod/iassign/view.php?action=view&id=" . $id . "&iassign_submission_current=" . $this->iassign_submission_current . "&userid_iassign=" . $this->userid_iassign . "&iassign_current=" . $this->activity->get_activity()->id;
  1235. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1236. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1237. print '<table width=100% >';
  1238. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1239. //TODO alterar aqui???
  1240. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1241. // empty_answer_post = No solution was posted.
  1242. if ($comment)
  1243. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1244. else
  1245. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1246. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1247. } else {
  1248. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1249. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1250. // Correct answer!!
  1251. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1252. $this->write_solution = 1; //
  1253. $status = 3;
  1254. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1255. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1256. // log record
  1257. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_correct', 'iassign') . "&nbsp;-&nbsp;" . get_string('grade_iassign', 'iassign') . ":" . $grade_student;
  1258. // Trigger module viewed event.
  1259. $event = \mod_iassign\event\submission_created::create(array(
  1260. 'objectid' => $this->iassign->id,
  1261. 'context' => $this->context,
  1262. 'other' => $info
  1263. ));
  1264. $event->add_record_snapshot('course', $this->course);
  1265. $event->trigger();
  1266. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1267. // Wrong answer...: get_answer_incorrect
  1268. $status = 2;
  1269. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1270. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1271. // log record
  1272. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1273. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1274. // Trigger module viewed event.
  1275. $event = \mod_iassign\event\submission_created::create(array(
  1276. 'objectid' => $this->iassign->id,
  1277. 'context' => $this->context,
  1278. 'other' => $info
  1279. ));
  1280. $event->add_record_snapshot('course', $this->course);
  1281. $event->trigger();
  1282. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1283. // Presents to the learner the result of the automatic evaluate?
  1284. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1285. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1286. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1287. print '<tr>';
  1288. // log record
  1289. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1290. // Trigger module viewed event.
  1291. $event = \mod_iassign\event\submission_created::create(array(
  1292. 'objectid' => $this->iassign->id,
  1293. 'context' => $this->context,
  1294. 'other' => $info
  1295. ));
  1296. $event->add_record_snapshot('course', $this->course);
  1297. $event->trigger();
  1298. } else { // yes!!!
  1299. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1300. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1301. print '<tr>';
  1302. print $msg;
  1303. }
  1304. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1305. $status = 1;
  1306. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1307. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1308. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1309. print '<tr>';
  1310. // log record
  1311. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1312. $event = \mod_iassign\event\submission_created::create(array(
  1313. 'objectid' => $this->iassign->id,
  1314. 'context' => $this->context,
  1315. 'other' => $info
  1316. ));
  1317. $event->add_record_snapshot('course', $this->course);
  1318. $event->trigger();
  1319. } // if ($iassign_ilm->evaluate == 1)
  1320. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1321. print '</tr></table>';
  1322. print $OUTPUT->box_end();
  1323. // add or update evaluate
  1324. if ($this->write_solution == 1) {
  1325. $timenow = time();
  1326. // new record
  1327. if (!$iassign_submission) {
  1328. $newentry = new stdClass();
  1329. $newentry->userid = $this->userid_iassign;
  1330. // $newentry->userid = $USER->id;
  1331. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1332. $newentry->timecreated = $timenow;
  1333. $newentry->timemodified = $timenow;
  1334. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1335. $newentry->grade = round($grade_student, 2);
  1336. $newentry->status = $status;
  1337. $newentry->experiment = 1;
  1338. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1339. print_error('error_insert', 'iassign');
  1340. } else {
  1341. // Trigger module viewed event.
  1342. $event = \mod_iassign\event\submission_created::create(array(
  1343. 'objectid' => $this->iassign->id,
  1344. 'context' => $this->context
  1345. ));
  1346. $event->add_record_snapshot('course', $this->course);
  1347. $event->trigger();
  1348. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1349. }
  1350. } elseif ($iassign_submission->status != 3) {
  1351. $newentry = new stdClass();
  1352. $newentry->id = $iassign_submission->id;
  1353. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1354. $newentry->userid = $iassign_submission->userid;
  1355. $newentry->timecreated = $iassign_submission->timecreated;
  1356. $newentry->timemodified = $timenow;
  1357. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1358. $newentry->grade = round($grade_student, 2);
  1359. $newentry->status = $status;
  1360. $newentry->experiment = $iassign_submission->experiment + 1;
  1361. if (!$DB->update_record("iassign_submission", $newentry)) {
  1362. print_error('error_update', 'iassign');
  1363. //D depurar...
  1364. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1365. //D $fp = fopen("teste1.txt","w");
  1366. //D fwrite($fp,$stringAux);
  1367. } else {
  1368. // Trigger module viewed event.
  1369. $event = \mod_iassign\event\submission_updated::create(array(
  1370. 'objectid' => $this->iassign->id,
  1371. 'context' => $this->context
  1372. ));
  1373. $event->add_record_snapshot('course', $this->course);
  1374. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1375. }
  1376. } else {
  1377. if ($return_get_answer == 1) {
  1378. $newentry = new stdClass();
  1379. $newentry->id = $iassign_submission->id;
  1380. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1381. $newentry->userid = $iassign_submission->userid;
  1382. $newentry->timecreated = $iassign_submission->timecreated;
  1383. $newentry->timemodified = $timenow;
  1384. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1385. $newentry->grade = round($grade_student, 2);
  1386. $newentry->status = $status;
  1387. $newentry->experiment = $iassign_submission->experiment + 1;
  1388. if (!$DB->update_record("iassign_submission", $newentry))
  1389. print_error('error_update', 'iassign');
  1390. else {
  1391. $event = \mod_iassign\event\submission_updated::create(array(
  1392. 'objectid' => $this->iassign->id,
  1393. 'context' => $this->context
  1394. ));
  1395. $event->add_record_snapshot('course', $this->course);
  1396. $event->trigger();
  1397. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1398. print $OUTPUT->box_start();
  1399. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1400. print $OUTPUT->box_end();
  1401. }
  1402. } elseif ($return_get_answer == 2) {
  1403. print $OUTPUT->box_start();
  1404. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1405. print $OUTPUT->box_end();
  1406. } else {
  1407. print $OUTPUT->box_start();
  1408. print "
  1409. <script type='text/javascript'>
  1410. //<![CDATA[
  1411. function overwrite () {
  1412. document.formEnvio.return_get_answer.value = 1;
  1413. document.formEnvio.submit();
  1414. }
  1415. function nooverwrite () {
  1416. document.formEnvio.return_get_answer.value = 2;
  1417. document.formEnvio.submit();
  1418. }
  1419. //]]>
  1420. </script>";
  1421. $param_aux = "action=overwrite&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1422. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1423. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1424. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1425. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1426. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1427. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1428. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1429. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1430. <input type='hidden' name='return_get_answer'/> ";
  1431. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1432. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1433. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1434. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1435. print " </form>";
  1436. print $OUTPUT->box_end();
  1437. }
  1438. }
  1439. } // if ($this->write_solution == 1)
  1440. print $OUTPUT->footer();
  1441. if ($submission_ajax == 1) {
  1442. ob_end_clean();
  1443. print 'OK';
  1444. }
  1445. die();
  1446. } // function get_answer()
  1447. /// Export in file the answer of student.
  1448. function export_file_answer () {
  1449. global $DB;
  1450. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1451. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1452. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1453. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1454. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1455. $extensions = explode(",", $iassign_ilm->extension);
  1456. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1457. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1458. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1459. header("Pragma: public");
  1460. header("Expires: 0");
  1461. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1462. header("Cache-Control: private", false);
  1463. header("Content-Type: document/unknown");
  1464. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1465. set_time_limit(0);
  1466. print($iassign_submission->answer);
  1467. exit;
  1468. } // function export_file_answer()
  1469. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1470. // @calledby $this->export_package_answer()
  1471. //TODO Precisa terminar! //TODO_HTML
  1472. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1473. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1474. <head>
  1475. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1476. $str_html .= " </head>
  1477. <body>\n";
  1478. $tam = sizeof($array_iassign_name);
  1479. for ($ii=0; $ii<$tam; $ii++) {
  1480. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1481. }
  1482. $str_html .= "
  1483. </body>\n</html>";
  1484. return $str_html;
  1485. }
  1486. /// Export an package (zip) with all answer of students
  1487. // @calledby $this->action()
  1488. function export_package_answer () {
  1489. global $DB, $CFG, $OUTPUT;
  1490. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1491. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1492. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1493. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1494. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1495. $userid = optional_param('userid', NULL, PARAM_INT);
  1496. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1497. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1498. //TODO_HTML echo "username=$username<br/>"; exit;
  1499. $current_date = date('Y_m_d_H');
  1500. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1501. // If temporary directory under Moodle data does not exists => create it
  1502. if (!is_dir($diretorio)) {
  1503. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1504. // created directory with permissions to be seen by everyone
  1505. }
  1506. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1507. if (!is_writable($diretorio)) { // send a highlighted message!
  1508. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1509. exit; // just in case
  1510. }
  1511. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1512. $zip = new zip_archive(); // create ZIP
  1513. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1514. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1515. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1516. $vet_student_filename = array();
  1517. $vet_student_content = array();
  1518. foreach ($iassign_statements as $iassign_statement) {
  1519. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1520. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1521. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1522. $extensions = explode(",", $iassign_ilm->extension);
  1523. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1524. if ($iassign_submission) {
  1525. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1526. $student_content = $iassign_submission->answer;
  1527. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1528. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1529. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1530. if ($resp) {
  1531. $vet_student_filename[] = $student_filename;
  1532. $vet_student_content[] = $student_content;
  1533. }
  1534. else { // send a highlighted message!
  1535. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1536. exit; // just in case
  1537. }
  1538. }
  1539. }
  1540. $zip->close(); // close the ZIP file
  1541. if (count($vet_student_filename)>0) {
  1542. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1543. $result_tf = $vet_result[0];
  1544. $filenameZip = $vet_result[1]->filename;
  1545. }
  1546. iassign_utils::download_file($zip_filename); // download the ZIP file
  1547. exit;
  1548. } // function export_package_answer()
  1549. /// Editing status of interactive activities
  1550. function edit_status () {
  1551. global $USER, $DB, $OUTPUT;
  1552. $newentry = new stdClass();
  1553. $newentry->id = $this->iassign_submission_current;
  1554. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1555. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1556. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1557. $newentry->status = $iassign_submission->status;
  1558. $newentry->teacher = $USER->id;
  1559. if (!$DB->update_record('iassign_submission', $newentry))
  1560. print_error('error_update', 'iassign');
  1561. else {
  1562. // Trigger module viewed event.
  1563. $event = \mod_iassign\event\submission_updated::create(array(
  1564. 'objectid' => $this->iassign->id,
  1565. 'context' => $this->context
  1566. ));
  1567. $event->add_record_snapshot('course', $this->course);
  1568. $event->trigger();
  1569. $this->action = 'viewsubmission';
  1570. $this->view_iassign_current();
  1571. } // if (!$DB->update_record('iassign_submission', $newentry))
  1572. } // function edit_status()
  1573. /// Editing grade of interactive activities
  1574. function edit_grade () {
  1575. global $USER, $DB, $OUTPUT;
  1576. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1577. if ($newgrade && $newgrade >= 0) {
  1578. $newentry = new stdClass();
  1579. $newentry->id = $this->iassign_submission_current;
  1580. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1581. $newentry->teacher = $USER->id;
  1582. if (!$DB->update_record('iassign_submission', $newentry))
  1583. print_error('error_update', 'iassign');
  1584. else {
  1585. // Trigger module viewed event.
  1586. $event = \mod_iassign\event\submission_updated::create(array(
  1587. 'objectid' => $this->iassign->id,
  1588. 'context' => $this->context
  1589. ));
  1590. $event->add_record_snapshot('course', $this->course);
  1591. $event->trigger();
  1592. }
  1593. } // if ($newgrade >= 0)
  1594. $this->action = 'viewsubmission';
  1595. $this->view_iassign_current();
  1596. }
  1597. /// Add or Edit interactive activities
  1598. // @calledby $this->action()
  1599. function add_edit_iassign () {
  1600. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1601. require_once('iassign_form.php');
  1602. $id = $this->cm->id;
  1603. $iassignid = $this->iassign->id;
  1604. $param = new stdClass();
  1605. $param->action = $this->action; // oculto
  1606. $param->id = $id; // oculto
  1607. $COURSE->cm = $id;
  1608. $COURSE->iassignid = $iassignid;
  1609. $COURSE->iassign_file_id = NULL;
  1610. $context = context_module::instance($this->cm->id);
  1611. $contextuser = context_user::instance($USER->id);
  1612. $component = 'mod_iassign';
  1613. $filearea = 'exercise';
  1614. if (!empty($this->iassign_current))
  1615. $COURSE->iassign_id = $this->iassign_current;
  1616. else
  1617. $COURSE->iassign_id = 0;
  1618. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1619. if ($this->action == 'add') {
  1620. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1621. $params = array('iassignid' => $iassignid);
  1622. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1623. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1624. $total_of_activities = count($iassign_statement);
  1625. $param->iassignid = $iassignid;
  1626. $param->name = "";
  1627. $param->oldname = "";
  1628. $param->type_iassign = 3;
  1629. $param->proposition = "";
  1630. $author = $DB->get_record("user", array("id" => $USER->id));
  1631. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1632. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1633. $param->author = $param->author_name;
  1634. $param->author_modified = $param->author_modified_name;
  1635. $COURSE->iassign_list = array();
  1636. $param->iassign_list = array();
  1637. if ($iassign_statement) {
  1638. foreach ($iassign_statement as $iassign) {
  1639. $iassignid = $iassign->id;
  1640. $param->iassign_list[$iassignid] = 0;
  1641. $COURSE->iassign_list[$iassignid] = new stdClass();
  1642. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1643. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1644. $COURSE->iassign_list[$iassignid]->enable = 1;
  1645. } // foreach ($iassign_statement as $iassign)
  1646. }
  1647. $param->iassign_ilmid = 0;
  1648. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1649. $param->file = 0;
  1650. $param->fileold = 0;
  1651. $param->filename = "";
  1652. $param->grade = $iassign_data->grade;
  1653. $param->timemodified = time();
  1654. $param->timecreated = time();
  1655. $param->timeavailable = $iassign_data->timeavailable;
  1656. $param->timedue = $iassign_data->timedue;
  1657. $param->preventlate = $iassign_data->preventlate;
  1658. $param->test = $iassign_data->test;
  1659. $param->special_param1 = 0;
  1660. $param->visible = 1;
  1661. $param->max_experiment = $iassign_data->max_experiment;
  1662. $param->dependency = 0;
  1663. $param->automatic_evaluate = 1;
  1664. $param->show_answer = 1;
  1665. } // if ($this->action == 'add')
  1666. elseif ($this->action == 'edit') {
  1667. $COURSE->iassign_list = array();
  1668. $this_activity = $this->activity->get_activity();
  1669. if ($this_activity != null) {
  1670. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1671. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1672. $param->iassign_id = $iassign_statement_current->id; // oculto
  1673. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1674. $param->name = $iassign_statement_current->name;
  1675. $param->oldname = $iassign_statement_current->name;
  1676. $param->type_iassign = $iassign_statement_current->type_iassign;
  1677. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1678. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1679. //2019 $param->proposition = $iassign_statement_current->proposition;
  1680. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1681. $param->author_name = $iassign_statement_current->author_name; // oculto
  1682. $param->author = $iassign_statement_current->author_name;
  1683. $author = $DB->get_record("user", array('id' => $USER->id));
  1684. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1685. $param->author_modified = $param->author_modified_name;
  1686. $dependency = explode(';', $iassign_statement_current->dependency);
  1687. $param->iassign_list = array();
  1688. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1689. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1690. $array_dependency = array();
  1691. $subdependency = "";
  1692. $sub_subdependency = "";
  1693. // dependent on this exercise
  1694. if ($iassign_statement_dependency) {
  1695. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1696. // to whom this exercise depends
  1697. foreach ($inter as $tmp)
  1698. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1699. $list_dependency = $subdependency . $sub_subdependency;
  1700. $array_dependency = explode(";", $list_dependency);
  1701. }
  1702. // Get all activity with the same iLM - iassignid
  1703. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  1704. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1705. $total_of_activities = count($all_others_iassign_statement) + 1;
  1706. $inter = array();
  1707. if ($all_others_iassign_statement) {
  1708. foreach ($all_others_iassign_statement as $iassign)
  1709. if (in_array($iassign->id, $dependency))
  1710. $inter[] = $iassign->id;
  1711. }
  1712. if ($all_others_iassign_statement) {
  1713. foreach ($all_others_iassign_statement as $iassign) {
  1714. $iassignid = $iassign->id;
  1715. $COURSE->iassign_list[$iassignid] = new stdClass();
  1716. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1717. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1718. if (in_array($iassignid, $dependency))
  1719. $param->iassign_list[$iassignid] = 1;
  1720. else
  1721. $param->iassign_list[$iassignid] = 0;
  1722. if (in_array($iassignid, $array_dependency))
  1723. $COURSE->iassign_list[$iassignid]->enable = 0;
  1724. else
  1725. $COURSE->iassign_list[$iassignid]->enable = 1;
  1726. } // foreach ($all_others_iassign_statement as $iassign)
  1727. }
  1728. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1729. $param->fileold = 0;
  1730. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1731. $param->filename = '';
  1732. $param->grade = $iassign_statement_current->grade;
  1733. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1734. $param->timeavailable = $iassign_statement_current->timeavailable;
  1735. $param->timedue = $iassign_statement_current->timedue;
  1736. $param->preventlate = $iassign_statement_current->preventlate;
  1737. $param->test = $iassign_statement_current->test;
  1738. $param->special_param1 = $iassign_statement_current->special_param1;
  1739. $param->position = $iassign_statement_current->position; // oculto
  1740. $param->visible = $iassign_statement_current->visible;
  1741. $param->max_experiment = $iassign_statement_current->max_experiment;
  1742. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1743. $param->show_answer = $iassign_statement_current->show_answer;
  1744. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1745. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1746. if ($files) {
  1747. foreach ($files as $file) {
  1748. if ($file->get_filename() != '.') {
  1749. $param->filename = $file->get_filename();
  1750. $param->file = $file->get_id();
  1751. $param->fileold = $file->get_id();
  1752. $COURSE->iassign_file_id = $file->get_id();
  1753. }
  1754. }
  1755. }
  1756. //TODO //MOOC2014 -- inicio
  1757. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1758. //D if ($iassign_ilm_configs) {
  1759. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1760. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1761. //D } //MOOC2014 -- fim
  1762. } // if ($this_activity != null)
  1763. } // elseif ($this->action == 'edit')
  1764. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1765. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1766. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1767. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1768. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1769. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1770. $param->position = $total_of_activities;
  1771. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1772. $mform->set_data($param);
  1773. if ($mform->is_cancelled()) {
  1774. $this->return_home_course('iassign_cancel');
  1775. exit;
  1776. }
  1777. else { // if ($mform->is_cancelled())
  1778. $result = $mform->get_data();
  1779. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1780. if ($result) {
  1781. $result->context = $context;
  1782. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1783. $result->grade = 0;
  1784. if ($result->type_iassign == 1) {
  1785. $result->automatic_evaluate = 0;
  1786. $result->show_answer = 0;
  1787. }
  1788. elseif ($result->automatic_evaluate == 0)
  1789. $result->show_answer = 0;
  1790. // $_POST['iassign_list']
  1791. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1792. if ($result->iassign_list) {
  1793. foreach ($result->iassign_list as $key => $value)
  1794. $result->dependency .= $key . ';';
  1795. }
  1796. else
  1797. $result->dependency = 0;
  1798. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1799. //TODO Then get it directly from the form data $_POST!
  1800. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1801. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1802. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1803. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1804. if ($this->action == 'add') {
  1805. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1806. if ($iassign_statement_name) {
  1807. $this->return_home_course('error_iassign_name');
  1808. die();
  1809. }
  1810. // Really insert the new iActivity in table '*_iassign_statement'
  1811. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1812. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1813. // Trigger module viewed event.
  1814. $event = \mod_iassign\event\iassign_created::create(array(
  1815. 'objectid' => $iassignid,
  1816. 'context' => $context
  1817. ));
  1818. $event->add_record_snapshot('course', $this->course);
  1819. $event->trigger();
  1820. $this->return_home_course('iassign_add');
  1821. } // if ($this->action == 'add')
  1822. elseif ($this->action == 'edit') {
  1823. $iassignid = $this->activity->update_iassign($result);
  1824. $this->activity->update_calendar($iassignid, $result->oldname);
  1825. // Trigger module viewed event.
  1826. $event = \mod_iassign\event\iassign_updated::create(array(
  1827. 'objectid' => $iassignid,
  1828. 'context' => $context
  1829. ));
  1830. $event->add_record_snapshot('course', $this->course);
  1831. $event->trigger();
  1832. $this->return_home_course('iassign_update');
  1833. } // elseif ($this->action == 'edit')
  1834. die();
  1835. } // if ($result)
  1836. } // else if ($mform->is_cancelled())
  1837. print $OUTPUT->header();
  1838. $mform->display();
  1839. print $OUTPUT->footer();
  1840. die();
  1841. } // function add_edit_iassign()
  1842. /// Search for dependencies
  1843. function search_dependency ($search_iassing_id, $iassign_statement) {
  1844. global $DB, $OUTPUT;
  1845. $dependency = "";
  1846. if ($iassign_statement)
  1847. foreach ($iassign_statement as $iassign) {
  1848. $inter_dependency = explode(';', $iassign->dependency);
  1849. if (in_array($search_iassing_id, $inter_dependency)) {
  1850. $dependency .= $iassign->id . ";";
  1851. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1852. } // if (in_array($search_iassing_id, $inter_dependency))
  1853. } // foreach ($iassign_statement as $iassign)
  1854. return $dependency;
  1855. }
  1856. /// Search for "sub"dependency
  1857. function search_sub_dependency ($search_iassing_id) {
  1858. global $DB, $OUTPUT;
  1859. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1860. $dependency = "";
  1861. if ($iassign_statement) {
  1862. $inter_dependency = explode(';', $iassign_statement->dependency);
  1863. foreach ($inter_dependency as $tmp) {
  1864. if ($tmp != 0)
  1865. $dependency .= $tmp . ";";
  1866. $dependency .= $this->search_sub_dependency($tmp);
  1867. } // foreach ($inter_dependency as $tmp)
  1868. } // if ($iassign_statement)
  1869. return $dependency;
  1870. }
  1871. // Warning message
  1872. static function warning_message_iassign ($strcode) {
  1873. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1874. }
  1875. /// Update grade of iAssign
  1876. // Called always any iAssign activity is created
  1877. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1878. static function update_grade_iassign ($iassignid) {
  1879. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1880. require_once($CFG->libdir . '/gradelib.php');
  1881. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1882. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1883. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1884. // Each iAssign item is associated with one item on the "gradebook"
  1885. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1886. //$sum_grade = 0;
  1887. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1888. //foreach($grade as $tmp) {
  1889. // $sum_grade += $tmp->grade;
  1890. // }
  1891. //1 Solution 1
  1892. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1893. //1 $sum_grade = 0; //1
  1894. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1895. //2 Solution 2
  1896. $array_sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3"); //2
  1897. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1898. if (key($array_sum_grade))
  1899. $sum_grade = key($array_sum_grade); //2
  1900. else
  1901. $sum_grade = 0; //2
  1902. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1903. $grades = NULL;
  1904. $params = array('itemname' => $grade_iassign->name);
  1905. $params['iteminstance'] = $iassignid;
  1906. $params['gradetype'] = GRADE_TYPE_VALUE;
  1907. //2016 if ($sum_grade != 0) {
  1908. $params['grademax'] = $sum_grade;
  1909. $params['rawgrademax'] = $sum_grade;
  1910. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1911. $params['grademin'] = 0;
  1912. // @calls /lib/gradelib.php: call to grade_item->insert()
  1913. //TODO: is there any error here in Moodle version 3.0?
  1914. //TODO: Incorrect property 'grademax' found when inserting grade object
  1915. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1916. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1917. }
  1918. /// Update grade of student
  1919. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1920. global $CFG, $DB, $OUTPUT;
  1921. require_once($CFG->libdir . '/gradelib.php');
  1922. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1923. // Review all the student submission for this iAssign activity
  1924. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1925. $total_grade = 0;
  1926. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1927. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1928. if ($iassign_submission)
  1929. $total_grade += $iassign_submission->grade;
  1930. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1931. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1932. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1933. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1934. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1935. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1936. $array_sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3"); //2
  1937. if (key($array_sum_grade))
  1938. $sum_grade = key($array_sum_grade); //2
  1939. else
  1940. $sum_grade = 0; //2
  1941. $grades['userid'] = $userid;
  1942. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1943. $params = array('itemname' => $grade_iassign->name);
  1944. $params['iteminstance'] = $iassignid;
  1945. $params['gradetype'] = GRADE_TYPE_VALUE;
  1946. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1947. $params['grademax'] = $sum_grade;
  1948. $params['rawgrademax'] = $sum_grade;
  1949. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1950. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1951. }
  1952. /// Display caption of icons
  1953. function view_legend_icons () {
  1954. global $USER, $CFG, $DB, $OUTPUT;
  1955. $id = $this->cm->id;
  1956. if ($this->action == 'print')
  1957. print '<table border=1 width=100%><tr>';
  1958. else
  1959. print '<table width=100%><tr>';
  1960. print '<td >';
  1961. if ($this->action != 'print')
  1962. print $OUTPUT->help_icon('legend', 'iassign');
  1963. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1964. // $imagetext = '');
  1965. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1966. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1967. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1968. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1969. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1970. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1971. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1972. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1973. print '</td>' . "\n";
  1974. if ($this->action != 'print') {
  1975. $link_print = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=print&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('print') . '&nbsp;' . get_string('print', 'iassign') . "</a>";
  1976. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('graphic', 'iassign') . "</a>";
  1977. $link_export = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=export_csv&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('export_ilm') . '&nbsp;' . get_string('export_csv', 'iassign') . "</a>";
  1978. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1979. $link_all_submissions_manager = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=all_submissions&iassignid=" . $this->iassign->id . "'><i class='fa fa-files-o' aria-hidden='true' style='color: red'></i>&nbsp;" . get_string('all_submissions_manager', 'iassign') . "</a>";
  1980. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1981. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1982. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1983. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1984. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1985. } // if ($this->action != 'print')
  1986. print '</tr></table>' . "\n";
  1987. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1988. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1989. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats_student&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('results', 'iassign') . "</a>";
  1990. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1991. print '</tr></table>' . "\n";
  1992. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1993. else
  1994. print '</td></tr></table>' . "\n";
  1995. } // function view_legend_icons()
  1996. /// Display activity current
  1997. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1998. function view_iassign_current () {
  1999. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2000. $id = $this->cm->id;
  2001. $iassignid = $this->iassign->id;
  2002. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2003. $iassign = $DB->get_record("iassign", array("id" => $iassignid)); // from table '*_iassign': id course name intro introformat activity_group grade timeavailable timedue preventlate test max_experiment
  2004. // Get data of current activity : table '*_iassign_statement' = id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid file grade timemodified timecreated ...
  2005. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2006. if (!$iassign_statement_activity_item) {
  2007. print $OUTPUT->header();
  2008. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2009. print $OUTPUT->footer();
  2010. exit;
  2011. }
  2012. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2013. $ilm_name = '';
  2014. if ($ilm->ilm)
  2015. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2016. // Do not allow the learner resent his solution only is iGeom iLM ("igeom") - why? iGeom acitivity "model answer" is not sent with the learner solution
  2017. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2018. // log record
  2019. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2020. //Trigger module viewed event.
  2021. $event = \mod_iassign\event\submission_viewed::create(array(
  2022. 'objectid' => $iassign->id,
  2023. 'context' => $this->context,
  2024. 'other' => $info
  2025. ));
  2026. $event->add_record_snapshot('course', $this->course);
  2027. $event->trigger();
  2028. // Search of iLM data used in the current activity
  2029. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2030. // Add actual activity to navbar:
  2031. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2032. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2033. print $OUTPUT->header();
  2034. if ($this->action == 'viewsubmission') {
  2035. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2036. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2037. else
  2038. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2039. } else {
  2040. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2041. }
  2042. if ($iassign_submission)
  2043. $this->update_comment($iassign_submission->id);
  2044. $file = $iassign_statement_activity_item->file;
  2045. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2046. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2047. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2048. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2049. $this->bottonPost = 0; // hide submit button
  2050. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2051. $this->view_iassign = false; // disable visualization of activity
  2052. $repeat = "";
  2053. $last_iassign = "";
  2054. $student_answer = "";
  2055. $comment = "";
  2056. // *** Teacher access (view learner's submission)
  2057. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2058. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2059. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2060. // ---> access teacher for test
  2061. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2062. $this->bottonPost = 1;
  2063. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2064. $this->activity->view_dates();
  2065. $USER->iassignEdit = $this->bottonPost;
  2066. $this->activity->show_info_iassign();
  2067. if ($iassign_submission) {
  2068. //xxx $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2069. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2070. } else {
  2071. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2072. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2073. }
  2074. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2075. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2076. // Prepare tags to present the iLM
  2077. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2078. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2079. // *** (end) Teacher access (view the activity)
  2080. // *** Teacher access (view learner's submission to the activity)
  2081. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2082. // It is teacher or 'nonediting teacher' that can evaluate
  2083. // ----> area teacher evaluate
  2084. $row = optional_param('row', 0, PARAM_INT);
  2085. $column = optional_param('column', 0, PARAM_INT);
  2086. $link_next = iassign_icons::insert('right_disable');
  2087. $link_previous = iassign_icons::insert('left_disable');
  2088. $link_up = iassign_icons::insert('up_disable');
  2089. $link_down = iassign_icons::insert('down_disable');
  2090. // next_activity
  2091. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2092. $url_next = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  2093. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2094. }
  2095. // previous_activity
  2096. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2097. $url_previous = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  2098. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2099. }
  2100. // previous_student
  2101. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2102. $url_down = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  2103. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2104. }
  2105. // next_student
  2106. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2107. $url_up = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  2108. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2109. }
  2110. if ($iassign_submission) {
  2111. $student_answer = $iassign_submission->answer;
  2112. }
  2113. $last_iassign = get_string('last_iassign', 'iassign');
  2114. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2115. // Messages related to due date (and user role)
  2116. $this->activity->view_dates();
  2117. print $OUTPUT->box_start();
  2118. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2119. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2120. print $OUTPUT->user_picture($user_data);
  2121. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2122. print '</td>' . "\n";
  2123. print '<td width=20% align=right>' . "\n";
  2124. print '<table width=50 cellpadding="0">';
  2125. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2126. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2127. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2128. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2129. print '</table>' . "\n";
  2130. print '</td></tr></table>' . "\n";
  2131. print $OUTPUT->box_end();
  2132. print $OUTPUT->box_start();
  2133. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2134. print '<td width=60% valign="top">' . "\n";
  2135. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2136. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2137. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2138. $resp = get_string('yes');
  2139. else
  2140. $resp = get_string('no');
  2141. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2142. if ($iassign_statement_activity_item->show_answer == 1)
  2143. $resp = get_string('yes');
  2144. else
  2145. $resp = get_string('no');
  2146. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2147. print '</td>';
  2148. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2149. print '<td width=40% valign="top" align="left">';
  2150. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2151. // check status of solution sent by the student
  2152. if ($iassign_submission) {
  2153. switch ($iassign_submission->status) {
  2154. case 3 :
  2155. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2156. break;
  2157. case 2 :
  2158. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2159. break;
  2160. case 1 :
  2161. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2162. break;
  2163. default :
  2164. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2165. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2166. } // switch ($iassign_submission->status)
  2167. }
  2168. else { // if ($iassign_submission)
  2169. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2170. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2171. }
  2172. // update_status
  2173. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2174. $edit_status = $CFG->wwwroot . "/mod/iassign/view.php?action=edit_status&id=" . $id . "&userid_iassign=" . $this->userid_iassign . "&iassign_current=" . $this->activity->get_activity()->id . "&iassign_submission_current=" . $this->iassign_submission_current . "&row=" . ($row) . "&column=" . ($column);
  2175. print " <script type='text/javascript'>
  2176. //<![CDATA[
  2177. function overwriteStatus (newstatus) {
  2178. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2179. document.formEditStatus.return_status.value=newstatus;
  2180. document.formEditStatus.submit();
  2181. }
  2182. else
  2183. document.formEditStatus.return_status.value=-1;
  2184. }
  2185. //]]>
  2186. </script>";
  2187. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2188. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2189. print " <select name='status' onchange= 'overwriteStatus(this.value)'>\n" . " <option value=\"3\">" . get_string('correct', 'iassign') . "</option>\n" . " <option value=\"2\">" . get_string('incorrect', 'iassign') . "</option>\n" . " <option value=\"1\">" . get_string('post', 'iassign') . "</option>\n" . " <option value=\"0\">" . get_string('not_post', 'iassign') . "</option>\n" . " <option value=\"-1\" selected>" . get_string('newsituation', 'iassign') . "</option>\n" . " </select>\n";
  2190. print " <input type='hidden' name='return_status'>\n";
  2191. print "</form>\n";
  2192. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2193. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2194. $edit_grade = $CFG->wwwroot . "/mod/iassign/view.php?action=edit_grade&id=" . $id . "&userid_iassign=" . $this->userid_iassign . "&iassign_current=" . $this->activity->get_activity()->id . "&iassign_submission_current=" . $this->iassign_submission_current . "&row=" . ($row) . "&column=" . ($column);
  2195. print "
  2196. <script type='text/javascript'>
  2197. //<![CDATA[
  2198. function overwriteGrade (newgrade,maxgrade) {
  2199. if (newgrade<0 || newgrade>maxgrade) {
  2200. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2201. document.formEditGrade.return_grade.value=-1;
  2202. document.formEditGrade.submit();
  2203. }
  2204. else {
  2205. document.formEditGrade.return_grade.value=newgrade;
  2206. document.formEditGrade.submit();
  2207. }
  2208. }
  2209. //]]>
  2210. </script>";
  2211. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2212. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2213. print " <input type='text' name='grade' size='6'>";
  2214. print " <input type='hidden' name='return_grade'> ";
  2215. print " <input type=button value='" . get_string('confirm', 'iassign') . "' onClick = 'overwriteGrade(grade.value," . $iassign_statement_activity_item->grade . ")' " . " title='" . get_string('confirm_new_grade', 'iassign') . "'>\n";
  2216. print "</form>";
  2217. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2218. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2219. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2220. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2221. if ($teacher)
  2222. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2223. } // if ($iassign_submission->experiment > 0)
  2224. print '</td>';
  2225. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2226. print '</tr></table>';
  2227. print $OUTPUT->box_end();
  2228. $USER->iassignEdit = $this->bottonPost;
  2229. if ($iassign_submission && $allow_resubmission) {
  2230. // Put the iLM to
  2231. print $OUTPUT->box_start();
  2232. print '<p><strong>' . $last_iassign . '</strong></p>';
  2233. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2234. $enderecoPOST = "";
  2235. // Prepare tags to present the iLM
  2236. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2237. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2238. print $OUTPUT->box_end();
  2239. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2240. // ATTENTION: exception used by iGeom (exercise with "script")
  2241. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2242. if (substr($ilm_name, 0, 5)=="igeom") {
  2243. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2244. $loadTeacherActivity = true;
  2245. }
  2246. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2247. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2248. // Prepare tags to present the iLM
  2249. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2250. }
  2251. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2252. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2253. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2254. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2255. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2256. // *** (end) Teacher access (view learner's submission to the activity)
  2257. // *** Student access (view the activity)
  2258. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2259. // It could be the learner (he could send or resend the activity)
  2260. // ---> access student
  2261. $time_now = time();
  2262. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2263. // activity of type example - not submit button for submission
  2264. $this->view_iassign = true;
  2265. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2266. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2267. // activity of type test - iLM automatic evaluator - submit button for submission
  2268. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2269. $this->bottonPost = 1;
  2270. $this->view_iassign = true;
  2271. } else
  2272. $this->view_iassign = false;
  2273. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2274. // activity of type exercise (learner can send his answer, if yet open...)
  2275. $this->view_iassign = true;
  2276. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2277. $this->view_iassign = false;
  2278. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2279. $this->bottonPost = 1; // allow the submit button
  2280. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2281. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2282. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2283. if (!$iassign_submission) {
  2284. $str_iassign_submission_id = '';
  2285. $str_iassign_submission_answer = '';
  2286. }
  2287. else {
  2288. $str_iassign_submission_id = $iassign_submission->id;
  2289. $str_iassign_submission_answer = $iassign_submission->answer;
  2290. }
  2291. if ($this->action != 'repeat') {
  2292. $repeat = "<a href='view.php?action=repeat&id="
  2293. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2294. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2295. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2296. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2297. }
  2298. $this->bottonPost = 1;
  2299. $this->write_solution = 1; // can register his submission
  2300. $student_answer = $str_iassign_submission_answer;
  2301. }
  2302. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2303. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2304. $last_iassign = get_string('last_iassign', 'iassign');
  2305. if ($iassign_submission) {
  2306. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2307. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2308. $student_answer = $iassign_submission->answer;
  2309. } else {
  2310. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2311. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2312. }
  2313. }
  2314. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2315. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2316. $this->bottonPost = 1;
  2317. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2318. } else {
  2319. $last_iassign = get_string('last_iassign', 'iassign');
  2320. if ($iassign_submission) {
  2321. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2322. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2323. $student_answer = $iassign_submission->answer;
  2324. } else {
  2325. // Symbol of "redo activity"
  2326. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2327. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2328. }
  2329. }
  2330. } // elseif ($iassign_statement_activity_item->test == 1)
  2331. elseif ($iassign_statement_activity_item->test == 0)
  2332. $this->view_iassign = false;
  2333. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2334. if ($iassign_submission)
  2335. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2336. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2337. else
  2338. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2339. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2340. $this->activity->view_dates();
  2341. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2342. print $OUTPUT->box_start();
  2343. print '<table width=100% border=0 valign="top">' . "\n";
  2344. print '<tr><td width=60% valign="top">' . "\n";
  2345. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2346. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2347. $flag_dependency = true;
  2348. if ($iassign_statement_activity_item->type_iassign == 3) {
  2349. if ($iassign_statement_activity_item->dependency == 0) {
  2350. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2351. } else {
  2352. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2353. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2354. foreach ($dependencys as $dependency) {
  2355. if ($dependency) {
  2356. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2357. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2358. if ($dependencysubmissions) {
  2359. if ($dependencysubmissions->status == 3)
  2360. $icon = iassign_icons::insert('correct');
  2361. elseif ($dependencysubmissions->status == 2) {
  2362. $icon = iassign_icons::insert('incorrect');
  2363. $flag_dependency = false;
  2364. } elseif ($dependencysubmissions->status == 1) {
  2365. $icon = iassign_icons::insert('post');
  2366. $flag_dependency = false;
  2367. } elseif ($dependencysubmissions->status == 0) {
  2368. $icon = iassign_icons::insert('not_post');
  2369. $flag_dependency = false;
  2370. }
  2371. } else {
  2372. $icon = iassign_icons::insert('not_post');
  2373. $flag_dependency = false;
  2374. } // if ($dependencysubmissions)
  2375. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2376. } // if ($dependency)
  2377. } // foreach ($dependencys as $dependency)
  2378. } // if ($iassign_statement_activity_item->dependency == 0)
  2379. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2380. if ($flag_dependency == false) {
  2381. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2382. $this->view_iassign = false;
  2383. print '</tr></table>' . "\n";
  2384. }
  2385. else {
  2386. $this->view_iassign = true;
  2387. print '</td>' . "\n";
  2388. } // if ($flag_dependency == false)
  2389. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2390. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2391. // receiver=1 - message to teacher
  2392. // receiver=2 - message to student
  2393. if ($iassign_submission) {
  2394. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2395. if ($verify_message)
  2396. $comment = iassign_icons::insert('comment_unread');
  2397. }
  2398. print '<td width=40% valign="top" align="left">';
  2399. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2400. if ($iassign_statement_activity_item->show_answer == 1) {
  2401. // check status of solution sent by the student
  2402. if ($iassign_submission) {
  2403. switch ($iassign_submission->status) {
  2404. case 3 :
  2405. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2406. break;
  2407. case 2 :
  2408. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2409. break;
  2410. case 1 :
  2411. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2412. break;
  2413. default :
  2414. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2415. $repeat = "";
  2416. $last_iassign = "";
  2417. } // switch ($iassign_submission->status)
  2418. } else {
  2419. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2420. $repeat = "";
  2421. $last_iassign = "";
  2422. }
  2423. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2424. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2425. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2426. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2427. if ($iassign_statement_activity_item->max_experiment == 0)
  2428. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2429. else {
  2430. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2431. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2432. $repeat = "";
  2433. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2434. $this->bottonPost = 0;
  2435. $this->write_solution = 0;
  2436. }
  2437. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2438. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2439. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2440. if ($teacher)
  2441. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2442. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2443. } // if ($iassign_statement_activity_item->show_answer==1)
  2444. else {
  2445. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2446. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2447. $repeat = "";
  2448. $last_iassign = "";
  2449. } elseif ($iassign_submission->status == 1) {
  2450. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2451. }
  2452. }
  2453. print '</td>';
  2454. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2455. print '</tr></table>' . "\n";
  2456. // Presents the iLM
  2457. print '<table width=100% border=0 valign="top">' . "\n";
  2458. print '<td width=80% align="left">';
  2459. print '<strong>' . $last_iassign . ' ' . get_string('repeat_msg', 'iassign') . '</strong></td>' . "\n"; // If you want to do this activity from the beginning again, use the \"Redo button\".
  2460. print '<td width=20% align="rigth">';
  2461. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2462. print $repeat; // symbol of "redo activity"
  2463. print '</td></tr></table>' . "\n";
  2464. //2019 print $OUTPUT->box_end(); // closing Box 5 but sometimes it does reach this point - see it at the end of 'if ($this->view_iassign)'
  2465. $output = '';
  2466. if (!$iassign_ilm) {
  2467. $iassign_ilm = new stdClass();
  2468. $iassign_ilm->file_jar = "";
  2469. }
  2470. $output .= $OUTPUT->box_start();
  2471. $USER->iassignEdit = $this->bottonPost;
  2472. // ---
  2473. // Presents the iLM
  2474. // Prepare tags to present the iLM
  2475. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2476. $student_answer = ""; //?
  2477. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2478. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2479. $student_answer = "";
  2480. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2481. } else {
  2482. // When student is redoing his activity
  2483. // ATTENTION: exception used by iGeom (exercise with "script")
  2484. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2485. if (substr($ilm_name, 0, 5)=="igeom") {
  2486. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2487. $loadTeacherActivity = true;
  2488. }
  2489. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2490. }
  2491. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2492. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2493. //1 $history_comment = '';
  2494. //1 if ($iassign_submission) {
  2495. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2496. //1 }
  2497. //1 if (!empty($history_comment)) {
  2498. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2499. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2500. //1 $output .= $history_comment;
  2501. //1 $output .= "</table>\n";
  2502. //1 }
  2503. //1 $output .= "</form></center>\n";
  2504. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2505. //1 }
  2506. $output .= $OUTPUT->box_end();
  2507. print $output;
  2508. } // if ($this->view_iassign)
  2509. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2510. } // if ($this->view_iassign)
  2511. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2512. else
  2513. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2514. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2515. print '<table width=100% border=0 valign="top">' . "\n";
  2516. print '<tr><td width=60% valign="top">' . "\n";
  2517. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2518. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2519. print '</tr></table>' . "\n";
  2520. $student_answer = "";
  2521. $enderecoPOST = "";
  2522. // Prepare tags to present the iLM
  2523. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2524. print $output;
  2525. }
  2526. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2527. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2528. if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2529. // Put a block with area to sent/answer comments
  2530. $output = '';
  2531. $history_comment = '';
  2532. $row = optional_param('row', 0, PARAM_INT);
  2533. $column = optional_param('column', 0, PARAM_INT);
  2534. if ($iassign_submission) {
  2535. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2536. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2537. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2538. }
  2539. else {
  2540. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2541. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2542. }
  2543. $output .= $OUTPUT->box_start();
  2544. //if (!empty($history_comment)) {
  2545. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2546. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2547. $output .= "</table>";
  2548. print " <script type='text/javascript'>
  2549. //<![CDATA[
  2550. function submit_comment(url) {
  2551. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2552. var formData = new FormData();
  2553. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2554. var request = new XMLHttpRequest();
  2555. request.open('POST', url);
  2556. document.getElementById('comments_history').innerHTML = '';
  2557. request.onload = function (e) {
  2558. if (request.readyState === 4) {
  2559. if (request.status === 200) {
  2560. document.getElementById('comments_history').innerHTML = request.responseText;
  2561. document.getElementById('check-message-success').style.visibility = 'visible';
  2562. setTimeout(function(){
  2563. document.getElementById('check-message-success').style.visibility = 'hidden';
  2564. }, 3000);
  2565. }
  2566. }
  2567. };
  2568. document.formEnvioComment.submission_comment.value = '';
  2569. request.send(formData);
  2570. }
  2571. //]]>
  2572. </script>";
  2573. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2574. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2575. $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
  2576. $output .= "</form> </center>\n";
  2577. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2578. // }
  2579. $output .= $OUTPUT->box_end();
  2580. print $output;
  2581. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2582. // final block 'studant'
  2583. print $OUTPUT->footer();
  2584. die();
  2585. } // function view_iassign_current()
  2586. /// Export the data from performance report into CSV file format
  2587. function export_csv () {
  2588. global $USER, $CFG, $DB, $OUTPUT;
  2589. $str = "";
  2590. $fields = "student_id, student_name";
  2591. // Finding all iassign activities for the iassign:
  2592. $id = $this->cm->id;
  2593. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2594. $c = 1;
  2595. foreach ($iassign_list as $iassign) {
  2596. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2597. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2598. $c ++;
  2599. }
  2600. // Finding enrolled students:
  2601. $params = array('shortname' => 'student');
  2602. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2603. $context = context_course::instance($this->course->id);
  2604. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2605. $students = $DB->get_records_sql(
  2606. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2607. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2608. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2609. foreach ($students as $student) {
  2610. $str .= $student->userid . ',';
  2611. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2612. foreach ($iassign_list as $iassign) {
  2613. $str .= ',' . $iassign->id . ',';
  2614. $str .= '"' . $iassign->name . '",';
  2615. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2616. if ($student_submissions) {
  2617. $str .= $student_submissions->experiment . ',';
  2618. $str .= $student_submissions->grade . ',';
  2619. switch ($student_submissions->status) {
  2620. case 3:
  2621. $str .= '"correct",';
  2622. break;
  2623. case 2:
  2624. $str .= '"incorrect",';
  2625. break;
  2626. case 1:
  2627. $str .= '"post",';
  2628. break;
  2629. case 0:
  2630. $str .= '"not_post",';
  2631. break;
  2632. }
  2633. } else {
  2634. $str .= ',,"not_post",';
  2635. }
  2636. $str .= $iassign->iassign_ilmid . ',';
  2637. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2638. $str .= '"' . $ilm_activity->name . '"';
  2639. }
  2640. $str .= "\n";
  2641. }
  2642. $str = $fields . "\n" . $str;
  2643. header("Content-type: text/csv");
  2644. header("Content-disposition: attachment; filename=report.csv");
  2645. header("Pragma: no-cache");
  2646. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2647. header('Content-Length: ' . strlen($str));
  2648. header('Connection: close');
  2649. print $str;
  2650. flush();
  2651. } // function export_csv()
  2652. /// Display report of performance
  2653. function report () {
  2654. global $USER, $CFG, $DB, $OUTPUT;
  2655. $id = $this->cm->id;
  2656. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2657. if ($this->action != 'print') {
  2658. $title = get_string('report', 'iassign');
  2659. print $OUTPUT->header();
  2660. } // if ($this->action != 'print')
  2661. print $OUTPUT->box_start();
  2662. $this->view_legend_icons();
  2663. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2664. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2665. print $OUTPUT->box_end();
  2666. if ($this->action == 'print')
  2667. print '<table border=1 width="100%">' . "\n";
  2668. else
  2669. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2670. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2671. // $num = array();
  2672. $i = 1;
  2673. $num = array();
  2674. foreach ($iassign_list as $iassign) {
  2675. $test_exercise = "";
  2676. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2677. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2678. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2679. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2680. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2681. $num[$i] = new stdClass();
  2682. $num[$i]->name = $iassign->name;
  2683. $num[$i]->id = $i;
  2684. $num[$i]->iassignid = $iassign->id;
  2685. print ' <tr >' . "\n";
  2686. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2687. print "<td class=\"cell c0 actvity\">";
  2688. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2689. print ' </tr>' . "\n";
  2690. $i ++;
  2691. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2692. } // foreach ($iassign_list as $iassign)
  2693. print "</table>";
  2694. print "<p></p>";
  2695. if ($this->action == 'print')
  2696. print '<table border=1 width="100%">' . "\n";
  2697. else
  2698. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2699. $context = context_course::instance($this->course->id);
  2700. if ($i > 1) {
  2701. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2702. $params = array('shortname' => 'student');
  2703. $role = $DB->get_record_sql(
  2704. "SELECT s.id, s.shortname FROM {role} s " .
  2705. " WHERE s.shortname = :shortname", $params);
  2706. // $students = $DB->get_records_sql("SELECT s.userid, a.firstname, a.lastname FROM {$CFG->prefix}role_assignments s, {$CFG->prefix}user a WHERE s.contextid = '$context->id' AND s.userid = a.id AND s.roleid = '$role->id' ORDER BY a.firstname ASC,a.lastname ASC");
  2707. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2708. $students = $DB->get_records_sql(
  2709. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2710. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2711. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2712. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2713. for ($j = 1; $j < $i; $j ++) {
  2714. $sum_iassign_correct[$j] = 0;
  2715. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2716. }
  2717. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2718. $sum_iassign = $j - 1;
  2719. print '</tr>' . "\n";
  2720. $total = 0;
  2721. $sum_student = 0;
  2722. $comment = iassign_icons::insert('comment_read');
  2723. $sum_comment = 0;
  2724. $sum_correct_iassign = array();
  2725. $sum_correct_student = array();
  2726. $USER->matrix_iassign = array();
  2727. if ($students) {
  2728. $w = 0;
  2729. foreach ($students as $tmp) {
  2730. $users_array[$w] = $tmp;
  2731. $w ++;
  2732. }
  2733. for ($x = 0; $x < $w; $x ++) {
  2734. print '<tr>' . "\n";
  2735. $sum_student ++;
  2736. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2737. print ' <td >' . $name . '</td>' . "\n";
  2738. $total_student = 0;
  2739. $tentativas = 0;
  2740. for ($j = 1; $j < $i; $j ++) {
  2741. $sum_comment = 0;
  2742. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2743. print ' <td valign="bottom" align="center">' . "\n";
  2744. if ($student_submissions) {
  2745. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2746. $tentativas = $student_submissions->experiment;
  2747. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2748. $params = array('iassign_submissionid' => $student_submissions->id);
  2749. $student_submissions_comment = $DB->get_record_sql(
  2750. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2751. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2752. if ($student_submissions_comment)
  2753. foreach ($student_submissions_comment as $tmp)
  2754. $sum_comment = $tmp;
  2755. // informations to previous activities
  2756. if ($j - 1 < 1 || $j == $i)
  2757. $iassign_previous = "-1";
  2758. else
  2759. $iassign_previous = $num[$j - 1]->iassignid;
  2760. if ($x - 1 < 0 || $x == $w)
  2761. $user_previous = "-1";
  2762. else
  2763. $user_previous = $users_array[$x - 1]->userid;
  2764. // next
  2765. if ($i - 1 > $j)
  2766. $iassign_next = $num[$j + 1]->iassignid;
  2767. else
  2768. $iassign_next = "-1";
  2769. if ($w - 1 > $x)
  2770. $user_next = $users_array[$x + 1]->userid;
  2771. else
  2772. $user_next = "-1";
  2773. $position = "&row= $x&column=$j";
  2774. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2775. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2776. $url .= $position;
  2777. // receiver=1 - message to teacher
  2778. // receiver=2 - message to student
  2779. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2780. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2781. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2782. $verify_message = $DB->get_record_sql(
  2783. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2784. "WHERE iassign_submissionid = :iassign_submissionid " .
  2785. " AND return_status= :return_status " .
  2786. " AND receiver= :receiver", $params);
  2787. if ($verify_message)
  2788. foreach ($verify_message as $tmp)
  2789. $sum_verify_message = $tmp;
  2790. if ($sum_verify_message > 0)
  2791. $comment = iassign_icons::insert('comment_unread');
  2792. else
  2793. $comment = iassign_icons::insert('comment_read');
  2794. if ($student_submissions->status == 3) {
  2795. $sum_iassign_correct[$j] ++;
  2796. $total_student ++;
  2797. $feedback = iassign_icons::insert('correct');
  2798. }
  2799. elseif ($student_submissions->status == 2) {
  2800. $feedback = iassign_icons::insert('incorrect');
  2801. }
  2802. elseif ($student_submissions->status == 1) {
  2803. $feedback = iassign_icons::insert('post');
  2804. }
  2805. elseif ($student_submissions->status == 0) {
  2806. $feedback = iassign_icons::insert('not_post');
  2807. }
  2808. if ($this->action != 'print') {
  2809. print '<table><tr>';
  2810. if ($tentativas > 0)
  2811. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2812. else
  2813. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2814. print '<td> &nbsp; </td>';
  2815. print '</tr>' . "\n";
  2816. if ($sum_comment > 0 && $sum_verify_message > 0)
  2817. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2818. else if ($sum_comment > 0)
  2819. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2820. print '</table>' . "\n";
  2821. }
  2822. if ($this->action == 'print')
  2823. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2824. } // if ($student_submissions)
  2825. else { // if ($student_submissions)
  2826. // informations to browse previous activities
  2827. if ($j - 1 < 1 || $j == $i)
  2828. $iassign_previous = "-1";
  2829. else
  2830. $iassign_previous = $num[$j - 1]->iassignid;
  2831. if ($x - 1 < 0 || $x == $w)
  2832. $user_previous = "-1";
  2833. else
  2834. $user_previous = $users_array[$x - 1]->userid;
  2835. // next
  2836. if ($i - 1 > $j)
  2837. $iassign_next = $num[$j + 1]->iassignid;
  2838. else
  2839. $iassign_next = "-1";
  2840. if ($w - 1 > $x)
  2841. $user_next = $users_array[$x + 1]->userid;
  2842. else
  2843. $user_next = "-1";
  2844. $position = "&row= $x&column=$j";
  2845. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2846. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2847. $url .= $position;
  2848. $feedback = iassign_icons::insert('not_post');
  2849. if ($this->action == 'print')
  2850. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2851. else {
  2852. print '<table><tr>';
  2853. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2854. print '<td> &nbsp; </td>';
  2855. print '</tr><tr>' . "\n";
  2856. print '<td> &nbsp;</td>';
  2857. if ($sum_comment > 0)
  2858. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2859. else
  2860. print '<td> &nbsp;</td>';
  2861. print '</tr></table>';
  2862. }
  2863. } // else if ($student_submissions)
  2864. $USER->matrix_iassign[$x][$j] = new stdClass();
  2865. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2866. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2867. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2868. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2869. if ($student_submissions)
  2870. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2871. else
  2872. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2873. print '</td>' . "\n";
  2874. } // for ($j=1; $j<$i; $j++)
  2875. $total = $total + $total_student;
  2876. $porcentagem = ($total_student / ($j - 1)) * 100;
  2877. if ($tentativas != 0 && $tentativas != null) {
  2878. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2879. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2880. }
  2881. else {
  2882. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2883. }
  2884. print '</tr>' . "\n";
  2885. $sum_correct_student[$sum_student] = new stdClass();
  2886. $sum_correct_student[$sum_student]->name = $name;
  2887. $sum_correct_student[$sum_student]->sum = $total_student;
  2888. } // for ($x = 0; $x < $w; $x ++)
  2889. for ($i = 1; $i < $j; $i ++) {
  2890. if (is_null($sum_iassign_correct[$i]))
  2891. $sum_iassign_correct[$i] = 0;
  2892. $sum_correct_iassign[$i] = new stdClass();
  2893. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2894. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2895. }
  2896. // print '</tr></table>' . "\n";
  2897. }
  2898. } // if ($i>1)
  2899. else {
  2900. print_string('no_activity', 'iassign');
  2901. }
  2902. print "</table>\n";
  2903. if ($this->action != 'print')
  2904. print $OUTPUT->footer();
  2905. die();
  2906. } // function report()
  2907. /// Display graphics of performance
  2908. function stats () {
  2909. global $USER, $CFG, $DB, $OUTPUT;
  2910. $id = $this->cm->id;
  2911. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2912. if ($this->action != 'printstats')
  2913. $title = get_string('graphic', 'iassign');
  2914. $num = array();
  2915. $sum_correct_iassign = array();
  2916. $sum_correct_student = array();
  2917. $sum_student = 0;
  2918. $i = 1;
  2919. foreach ($iassign_list as $iassign) {
  2920. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2921. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2922. $sum_iassign_correct[$i] = 0;
  2923. $num[$i] = new stdClass();
  2924. $num[$i]->name = $iassign->name;
  2925. $num[$i]->id = $i;
  2926. $num[$i]->iassignid = $iassign->id;
  2927. $i ++;
  2928. } // if ($iassign->type_iassign == 3)
  2929. } // foreach ($iassign_list as $iassign)
  2930. $sum_iassign = $i - 1;
  2931. $context = context_course::instance($this->course->id);
  2932. if ($i > 1) {
  2933. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2934. $params = array('shortname' => 'student');
  2935. $role = $DB->get_record_sql(
  2936. "SELECT s.id, s.shortname FROM {role} s " .
  2937. " WHERE s.shortname = :shortname", $params);
  2938. // $students = $DB->get_records_sql("SELECT s.userid, a.firstname, a.lastname FROM {$CFG->prefix}role_assignments s, {$CFG->prefix}user a WHERE s.contextid = '$context->id' AND s.userid = a.id AND s.roleid = '$role->id' ORDER BY a.firstname ASC,a.lastname ASC");
  2939. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2940. $students = $DB->get_records_sql(
  2941. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2942. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2943. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2944. $total = 0;
  2945. $sum_student = 0;
  2946. $j = 0;
  2947. $sum_correct_iassign = array();
  2948. $sum_correct_student = array();
  2949. $sum_experiment = array();
  2950. if ($students) {
  2951. foreach ($students as $users) {
  2952. $sum_student ++;
  2953. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2954. // rows
  2955. $total_student = 0;
  2956. for ($j = 1; $j < $i; $j ++) {
  2957. $total_experiment = 0;
  2958. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2959. if ($student_submissions) {
  2960. if ($student_submissions->status == 3) {
  2961. $sum_iassign_correct[$j] ++;
  2962. $total_student ++;
  2963. } // if ($student_submissions->status == 3)
  2964. $total_experiment += $student_submissions->experiment;
  2965. }
  2966. $sum_experiment[$j] = $total_experiment;
  2967. } // for ($j=1; $j<$i; $j++)
  2968. $total = $total + $total_student;
  2969. $sum_correct_student[$sum_student] = new stdClass();
  2970. $sum_correct_student[$sum_student]->name = $name;
  2971. $sum_correct_student[$sum_student]->sum = $total_student;
  2972. } // foreach ($students as $users)
  2973. }
  2974. for ($i = 1; $i < $j; $i ++) {
  2975. if (is_null($sum_iassign_correct[$i]))
  2976. $sum_iassign_correct[$i] = 0;
  2977. $sum_correct_iassign[$i] = new stdClass();
  2978. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2979. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2980. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2981. } // for ($i = 1; $i < $j; $i++)
  2982. } // if ($i > 1)
  2983. if ($this->action != 'printstats') {
  2984. $title = get_string('graphic', 'iassign');
  2985. print $OUTPUT->header();
  2986. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('view_report') . '&nbsp;' . get_string('report', 'iassign') . "</a>";
  2987. $link_print_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=printstats&&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('print') . '&nbsp;' . get_string('print', 'iassign') . "</a>";
  2988. print '<table width=100%><tr>';
  2989. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2990. print '<td width=15% align="right">' . $link_report . '</td>';
  2991. print '</td></tr></table>' . "\n";
  2992. print "<br><br>";
  2993. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2994. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2995. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2996. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2997. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2998. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2999. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3000. print '</tr>' . "\n";
  3001. $sum_correct = 0;
  3002. if ($sum_correct_iassign) {
  3003. foreach ($sum_correct_iassign as $iassign) {
  3004. if (is_null($iassign->experiment))
  3005. $iassign->experiment = 0;
  3006. $bar = "";
  3007. $sum = $iassign->sum;
  3008. $percent = ($sum / $sum_student) * 100;
  3009. $text = number_format($percent, 1) . '%';
  3010. $sum_correct += $sum;
  3011. if ($sum > 0) {
  3012. for ($i = 1; $i < $percent * 2; $i ++)
  3013. $bar .= iassign_icons::insert('hbar_blue');
  3014. $bar .= iassign_icons::insert('hbar_blue_r');
  3015. } // if ($sum > 0)
  3016. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3017. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3018. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3019. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3020. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3021. print '</tr>' . "\n";
  3022. } // foreach ($sum_correct_iassign as $iassign)
  3023. }
  3024. print "</table>";
  3025. print "<br><br>";
  3026. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3027. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3028. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3029. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3030. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3031. print '</tr>' . "\n";
  3032. $sum_correct = 0;
  3033. foreach ($sum_correct_student as $student) {
  3034. $bar = "";
  3035. $sum = $student->sum;
  3036. $percent = ($sum / $sum_iassign) * 100;
  3037. $text = number_format($percent, 1) . '%';
  3038. $sum_correct += $sum;
  3039. if ($sum > 0) {
  3040. for ($i = 1; $i < $percent * 2; $i ++)
  3041. $bar .= iassign_icons::insert('hbar_blue');
  3042. $bar .= iassign_icons::insert('hbar_blue_r');
  3043. } // if ($sum > 0)
  3044. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3045. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3046. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3047. print '</tr>' . "\n";
  3048. } // foreach ($sum_correct_student as $student)
  3049. print "</table>\n";
  3050. print "<br><br>\n";
  3051. $var = 0;
  3052. $cv = 0;
  3053. $dv = 0;
  3054. $avg = 0;
  3055. if ($sum_correct_student) {
  3056. $avg = $sum_correct / $sum_student;
  3057. if ($avg > 0) {
  3058. foreach ($sum_correct_student as $student)
  3059. $var += pow($student->sum - $avg, 2);
  3060. $var = $var / $sum_student;
  3061. $dv = sqrt($var);
  3062. $cv = ($dv / $avg) * 100;
  3063. }
  3064. }
  3065. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3066. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3067. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3068. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3069. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3070. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3071. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3072. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3073. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3074. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3075. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3076. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3077. print "</table>\n";
  3078. print $OUTPUT->footer();
  3079. } else {
  3080. print "<STYLE TYPE='text/css'>
  3081. <!--
  3082. .boldtable {
  3083. font-family:sans-serif;
  3084. font-size:10pt;
  3085. }
  3086. -->
  3087. </STYLE>\n";
  3088. print '<table border=1 width=100%>' . "\n";
  3089. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3090. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3091. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3092. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3093. print '</tr>' . "\n";
  3094. $sum_correct = 0;
  3095. foreach ($sum_correct_iassign as $iassign) {
  3096. $bar = "";
  3097. $sum = $iassign->sum;
  3098. $percent = ($sum / $sum_student) * 100;
  3099. $text = number_format($percent, 1) . '%';
  3100. $sum_correct += $sum;
  3101. if ($sum > 0) {
  3102. for ($i = 1; $i < $percent * 2; $i ++)
  3103. $bar .= iassign_icons::insert('hbar_blue');
  3104. $bar .= iassign_icons::insert('hbar_blue_r');
  3105. } // if ($sum > 0)
  3106. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3107. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3108. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3109. print '</tr>' . "\n";
  3110. } // foreach ($sum_correct_iassign as $iassign)
  3111. print "</table>";
  3112. print "<br><br>";
  3113. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3114. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3115. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3116. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3117. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3118. print '</tr>' . "\n";
  3119. $sum_correct = 0;
  3120. foreach ($sum_correct_student as $student) {
  3121. $bar = "";
  3122. $sum = $student->sum;
  3123. $percent = ($sum / $sum_iassign) * 100;
  3124. $text = number_format($percent, 1) . '%';
  3125. $sum_correct += $sum;
  3126. if ($sum > 0) {
  3127. for ($i = 1; $i < $percent * 2; $i ++)
  3128. $bar .= iassign_icons::insert('hbar_blue');
  3129. $bar .= iassign_icons::insert('hbar_blue_r');
  3130. } // if ($sum > 0)
  3131. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3132. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3133. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3134. print '</tr>' . "\n";
  3135. } // foreach ($sum_correct_student as $student)
  3136. print "</table>\n";
  3137. print "<br/><br/>\n";
  3138. $var = 0;
  3139. $cv = 0;
  3140. $dv = 0;
  3141. $avg = 0;
  3142. if ($sum_correct_student) {
  3143. $avg = $sum_correct / $sum_student;
  3144. if ($avg > 0) {
  3145. foreach ($sum_correct_student as $student)
  3146. $var += pow($student->sum - $avg, 2);
  3147. $var = $var / $sum_student;
  3148. $dv = sqrt($var);
  3149. $cv = ($dv / $avg) * 100;
  3150. }
  3151. }
  3152. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3153. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3154. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3155. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3156. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3157. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3158. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3159. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3160. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3161. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3162. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3163. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3164. print "</table>\n";
  3165. } // if ($this->action != 'printstats')
  3166. die();
  3167. }
  3168. /// Display graphics of performance for students
  3169. function stats_students () {
  3170. global $USER, $CFG, $DB, $OUTPUT;
  3171. $id = $this->cm->id;
  3172. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3173. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3174. $title = get_string('results', 'iassign');
  3175. $sum_correct = 0;
  3176. $sum_incorrect = 0;
  3177. $sum_post = 0;
  3178. $sum_nopost = 0;
  3179. $sum_iassign = count($iassign_statement_list);
  3180. $bar_nopost = "";
  3181. $bar_correct = "";
  3182. $bar_incorrect = "";
  3183. $bar_post = "";
  3184. $text_nopost = "";
  3185. $text_correct = "";
  3186. $text_incorrect = "";
  3187. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3188. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3189. if ($iassign_submission) {
  3190. if ($iassign_submission->status == 3)
  3191. $sum_correct ++;
  3192. elseif ($iassign_submission->status == 2)
  3193. $sum_incorrect ++;
  3194. elseif ($iassign_submission->status == 1)
  3195. $sum_post ++;
  3196. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3197. $sum_nopost ++;
  3198. } // if ($iassign_submission)
  3199. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3200. if ($sum_iassign > 0) {
  3201. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3202. $text_correct = number_format($percent_correct, 1) . '%';
  3203. }
  3204. if ($sum_correct > 0) {
  3205. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3206. $bar_correct .= iassign_icons::insert('hbar_green');
  3207. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3208. } // if ($sum_correct > 0)
  3209. if ($sum_iassign > 0) {
  3210. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3211. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3212. }
  3213. if ($sum_incorrect > 0) {
  3214. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3215. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3216. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3217. } // if ($sum_incorrect > 0)
  3218. if ($sum_iassign > 0) {
  3219. $percent_post = ($sum_post / $sum_iassign) * 100;
  3220. $text_post = number_format($percent_post, 1) . '%';
  3221. }
  3222. if ($sum_post > 0) {
  3223. for ($i = 1; $i < $percent_post * 2; $i ++)
  3224. $bar_post .= iassign_icons::insert('hbar_blue');
  3225. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3226. } // if ($sum_post > 0)
  3227. if ($sum_iassign > 0) {
  3228. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3229. $text_nopost = number_format($percent_nopost, 1) . '%';
  3230. }
  3231. if ($sum_nopost > 0) {
  3232. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3233. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3234. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3235. } // if ($sum_nopost > 0)
  3236. print $OUTPUT->header();
  3237. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3238. print '<table width=100%><tr>';
  3239. print '<td align="right">' . $link_return . '</td>' . "\n";
  3240. print '</td></tr></table>' . "\n";
  3241. print "<br/><br/>\n";
  3242. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3243. print '<tr><th colspan=3 class="header c1">' . "\n";
  3244. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3245. // $imagetext = '');
  3246. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3247. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3248. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3249. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3250. print '</tr>' . "\n";
  3251. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3252. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3253. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3254. print '</tr>' . "\n";
  3255. if ($sum_post) {
  3256. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3257. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3258. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3259. print '</tr>' . "\n";
  3260. } // if ($sum_post)
  3261. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3262. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3263. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3264. print '</tr>' . "\n";
  3265. print "</table>";
  3266. print "<br><br>";
  3267. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3268. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3269. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3270. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3271. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3272. $sum_grade = 0;
  3273. $sum_grade_student = 0;
  3274. $avg = 0;
  3275. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3276. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3277. if (!$iassign_submission) {
  3278. $iassign_submission = new stdClass();
  3279. $iassign_submission->grade = 0;
  3280. }
  3281. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3282. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3283. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3284. print '</tr>' . "\n";
  3285. $sum_grade += $iassign_statement_activity_item->grade;
  3286. $sum_grade_student += $iassign_submission->grade;
  3287. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3288. if ($sum_grade > 0)
  3289. $avg = $sum_grade_student / $sum_grade * 100;
  3290. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3291. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3292. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3293. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3294. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3295. print "</table>";
  3296. print $OUTPUT->footer();
  3297. die();
  3298. } // function stats_students()
  3299. /// Display page of iAssign's activity
  3300. function view_iassigns () {
  3301. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3302. $id = $this->cm->id;
  3303. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3304. $notice = optional_param('notice', '', PARAM_TEXT);
  3305. if (strpos($notice, 'error'))
  3306. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3307. else if ($notice != '')
  3308. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3309. print $OUTPUT->box_start();
  3310. print '<table width=100% border=0><tr>' . "\n";
  3311. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3312. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3313. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3314. $link_add = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=add&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('add_iassign') . get_string('add_iassign', 'iassign') . "</a>";
  3315. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('view_report') . get_string('report', 'iassign') . "</a>";
  3316. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3317. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3318. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3319. // Has capability to see "report": teacher or up
  3320. print '<td width=10% align="left">' . "\n";
  3321. print $link_help;
  3322. print '</td>' . "\n";
  3323. print '<td width=10% align="left">' . "\n";
  3324. print $link_report;
  3325. print '</td>' . "\n";
  3326. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3327. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3328. print '<td width=15% align="left">' . "\n";
  3329. print $link_add;
  3330. print "</td>\n";
  3331. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3332. //print '</tr></table>' . "\n";
  3333. print '<div style="float: right;">';
  3334. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3335. if ($iassign_list) {
  3336. print '<td align="right">' . "\n";
  3337. // $USER->iassignEdit == 0 view 'Turn editing off'
  3338. // $USER->iassignEdit == 1 view 'Turn editing on'
  3339. if (!isset($USER->iassignEdit))
  3340. $USER->iassignEdit = 0;
  3341. if ($USER->iassignEdit == 0) {
  3342. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3343. $botton = 1;
  3344. } // if ($USER->iassignEdit == 0)
  3345. elseif ($USER->iassignEdit == 1) {
  3346. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3347. $botton = 0;
  3348. } // elseif ($USER->iassignEdit == 1)
  3349. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3350. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3351. print " <input type=submit value='$bottonEdit_message'/>\n";
  3352. print "</form>\n";
  3353. print "</td>\n";
  3354. } // if ($iassign_list)
  3355. }
  3356. print '</tr></table>' . "\n";
  3357. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3358. // $this->view_legend_icons();
  3359. print $OUTPUT->box_end();
  3360. $iassign_array_exercise = array();
  3361. $i_exercise = 0;
  3362. $iassign_array_test = array();
  3363. $i_test = 0;
  3364. $iassign_array_example = array();
  3365. $i_example = 0;
  3366. $iassign_array_general = array();
  3367. $i_general = 0;
  3368. if ($iassign_list) {
  3369. if ($this->iassign->activity_group == 0) {
  3370. foreach ($iassign_list as $iassign) {
  3371. $iassign_array_general[$i_general] = $iassign;
  3372. $i_general ++;
  3373. }
  3374. } // if ($this->iassign->activity_group == 0)
  3375. else {
  3376. foreach ($iassign_list as $iassign) {
  3377. if ($iassign->type_iassign == 3) {
  3378. $iassign_array_exercise[$i_exercise] = $iassign;
  3379. $i_exercise ++;
  3380. } // if ($iassign->type_iassign == 3)
  3381. if ($iassign->type_iassign == 2) {
  3382. $iassign_array_test[$i_test] = $iassign;
  3383. $i_test ++;
  3384. } // if ($iassign->type_iassign == 2)
  3385. if ($iassign->type_iassign == 1) {
  3386. $iassign_array_example[$i_example] = $iassign;
  3387. $i_example ++;
  3388. } // if ($iassign->type_iassign == 1)
  3389. }
  3390. }
  3391. if ($iassign_array_exercise) {
  3392. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3393. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3394. }
  3395. if ($iassign_array_test) {
  3396. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3397. $this->show_iassign($title, $iassign_array_test, $i_test);
  3398. }
  3399. if ($iassign_array_example) {
  3400. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3401. $this->show_iassign($title, $iassign_array_example, $i_example);
  3402. }
  3403. if ($iassign_array_general) {
  3404. $title = "";
  3405. $this->show_iassign($title, $iassign_array_general, $i_general);
  3406. }
  3407. } else { // if ($iassign_list)
  3408. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3409. }
  3410. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3411. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3412. print $OUTPUT->box_start();
  3413. print '<table width=100% border=0><tr>' . "\n";
  3414. print '<td width=10% align="left">' . "\n";
  3415. print $link_report;
  3416. print '</td>' . "\n";
  3417. print '</tr></table>' . "\n";
  3418. print $OUTPUT->box_end();
  3419. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3420. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3421. print $OUTPUT->box_start();
  3422. print '<table width=100% border=0><tr>' . "\n";
  3423. print '<td align="left">' . "\n";
  3424. print $link_add;
  3425. print '</td>' . "\n";
  3426. print '</tr></table>' . "\n";
  3427. print $OUTPUT->box_end();
  3428. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3429. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3430. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3431. $this->view_legend_icons();
  3432. } // function view_iassigns()
  3433. /// Display all iAssigns
  3434. function show_iassign ($title, $iassign_array, $i) {
  3435. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3436. $id = $this->cm->id;
  3437. print $OUTPUT->box_start();
  3438. print " <script type='text/javascript'>
  3439. //<![CDATA[
  3440. function validate_move () {
  3441. var radios = document.getElementsByName('iassign_destiny');
  3442. var formValid = false;
  3443. //alert('aqui validate_move()');
  3444. var i = 0;
  3445. while (!formValid && i < radios.length) {
  3446. if (radios[i].checked) formValid = true;
  3447. i++;
  3448. }
  3449. if (!formValid) {
  3450. document.getElementById('move_dest').classList.add('alert-danger');
  3451. }
  3452. return formValid;
  3453. }
  3454. var modal;
  3455. function load_move(id_ias) {
  3456. document.form_move_activity.iassign_current.value = id_ias;
  3457. modal.style.display = 'block';
  3458. var radios = document.getElementsByName('iassign_destiny');
  3459. var i = 0;
  3460. while (i < radios.length) {
  3461. radios[i].checked = false;
  3462. i++;
  3463. }
  3464. document.getElementById('move_dest').classList.remove('alert-danger');
  3465. }
  3466. function load_modal_elements() {
  3467. modal = document.getElementById('myModal');
  3468. var span = document.getElementById('close_modal');
  3469. span.onclick = function() {
  3470. modal.style.display = 'none';
  3471. }
  3472. window.onclick = function(event) {
  3473. if (event.target == modal) {
  3474. modal.style.display = 'none';
  3475. }
  3476. }
  3477. }
  3478. window.onload = load_modal_elements;
  3479. //]]>
  3480. </script>\n";
  3481. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3482. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3483. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3484. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3485. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3486. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3487. <input type='hidden' name='iassign_current' value='' />";
  3488. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3489. $section = $course_sections[0];
  3490. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3491. for ($k = 0; $k < count($ids_sections); $k++) {
  3492. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3493. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3494. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3495. if ($c_cm) {
  3496. if ($ccm->instance == $c_cm->instance) {
  3497. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3498. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3499. }
  3500. else {
  3501. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3502. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3503. }
  3504. }
  3505. }
  3506. $radio_buttons .= "</ul>";
  3507. }
  3508. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3509. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3510. </form>
  3511. </div></div> </div></div>\n";
  3512. print " <style>.modal {
  3513. display: none;
  3514. position: fixed;
  3515. z-index: 1;
  3516. left: 0;
  3517. top: 0;
  3518. width: 100%;
  3519. height: 100%;
  3520. overflow: scroll;
  3521. background-color: rgb(0,0,0);
  3522. background-color: rgba(0,0,0,0.4);
  3523. }
  3524. .modal-content {
  3525. background-color: #fefefe;
  3526. margin: 15% auto;
  3527. padding: 10px 10px;
  3528. border: 1px solid #888;
  3529. width: 50%;
  3530. }
  3531. #close_modal {
  3532. color: #aaa;
  3533. float: right;
  3534. font-size: 28px;
  3535. font-weight: bold;
  3536. margin-top: -15px;
  3537. margin-right: -3px;
  3538. }
  3539. #close_modal:hover,
  3540. #close_modal:focus {
  3541. color: black;
  3542. text-decoration: none;
  3543. cursor: pointer;
  3544. }
  3545. #modal_title {
  3546. min-height: 3rem;
  3547. color: initial;
  3548. background: initial;
  3549. font-size: 1.5rem;
  3550. line-height: 1.5;
  3551. padding: 15px;
  3552. border-bottom: 1px solid #e5e5e5;
  3553. }
  3554. .input_move {
  3555. width: 90%;
  3556. padding: 2px;
  3557. }
  3558. .input_move:hover {
  3559. background: #eff0ef;
  3560. }
  3561. </style>";
  3562. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3563. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3564. for ($j = 0; $j < $i; $j ++) {
  3565. $iassign_current = $iassign_array[$j]->id;
  3566. // receiver=1 - message to teacher
  3567. // receiver=2 - message to student
  3568. $sum_comment = 0;
  3569. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3570. foreach ($iassign_submissions as $iassign_submission) {
  3571. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3572. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3573. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3574. if ($verify_message)
  3575. foreach ($verify_message as $tmp)
  3576. $sum_comment += $tmp;
  3577. } // foreach ($iassign_submissions as $iassign_submission)
  3578. if ($sum_comment == 0)
  3579. $comment_unread = "";
  3580. else {
  3581. $comment_unread_message = get_string('comment_unread', 'iassign');
  3582. if ($sum_comment == 1)
  3583. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3584. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3585. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3586. }
  3587. if ($j == $i - 1)
  3588. $iassign_down = $iassign_array[$j]->id;
  3589. else
  3590. $iassign_down = $iassign_array[$j + 1]->id;
  3591. if ($j > 0)
  3592. $iassign_up = $iassign_array[$j - 1]->id;
  3593. else
  3594. $iassign_up = $iassign_array[$j]->id;
  3595. if ($iassign_array[$j]->visible == 0)
  3596. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'><font color='#bbbbbb'>" . $iassign_array[$j]->name . "</font></a>";
  3597. else
  3598. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3599. $links .= $comment_unread;
  3600. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3601. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3602. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3603. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3604. if ($j==0) // first activity
  3605. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3606. else
  3607. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3608. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3609. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3610. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3611. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3612. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3613. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3614. if (count($iassign_array) > 1) {
  3615. if ($j == 0)
  3616. $links .= $link_down;
  3617. elseif ($j == $i - 1)
  3618. $links .= $link_up;
  3619. else
  3620. $links .= $link_up . $link_down;
  3621. } // if (count($iassign_array) > 1)
  3622. $links .= $link_edit . $link_delete;
  3623. if ($iassign_array[$j]->visible == 0)
  3624. $links .= $link_visible_show;
  3625. else
  3626. $links .= $link_visible_hide;
  3627. $links .= $link_duplicate_activity . $link_move_activity;
  3628. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3629. print '<p>' . $links . '</p>' . "\n";
  3630. }
  3631. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3632. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3633. print '<table width=100% ><tr>' . "\n";
  3634. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3635. print '</tr></table>' . "\n";
  3636. for ($j = 0; $j < $i; $j ++) {
  3637. $icon_status = "";
  3638. $icon_comment = "";
  3639. if ($iassign_array[$j]->visible == 1) {
  3640. $iassign_current = $iassign_array[$j]->id;
  3641. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3642. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3643. $icon_status = "";
  3644. $icon_comment = "";
  3645. if ($iassign_submission) {
  3646. // receiver=1 - message to teacher
  3647. // receiver=2 - message to student
  3648. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$iassign_submission->id' and return_status= 0 and receiver=2");
  3649. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3650. $verify_message = $DB->get_record_sql(
  3651. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3652. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3653. if ($verify_message)
  3654. foreach ($verify_message as $tmp)
  3655. $sum_comment = $tmp;
  3656. if ($sum_comment > 0) {
  3657. $comment_unread_message = get_string('comment_unread', 'iassign');
  3658. if ($sum_comment == 1)
  3659. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3660. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3661. }
  3662. // $icon_comment = iassign_icons::insert('comment_unread');
  3663. if ($iassign_array[$j]->type_iassign == 3) {
  3664. if ($iassign_array[$j]->show_answer == 1) {
  3665. if ($iassign_submission->status == 3)
  3666. $icon_status = iassign_icons::insert('correct');
  3667. elseif ($iassign_submission->status == 2)
  3668. $icon_status = iassign_icons::insert('incorrect');
  3669. elseif ($iassign_submission->status == 1)
  3670. $icon_status = iassign_icons::insert('post');
  3671. elseif ($iassign_submission->status == 0)
  3672. $icon_status = iassign_icons::insert('not_post');
  3673. } // if ($iassign_array[$j]->show_answer==1)
  3674. else {
  3675. if ($iassign_submission->status == 0)
  3676. $icon_status = iassign_icons::insert('not_post');
  3677. else
  3678. $icon_status = iassign_icons::insert('post');
  3679. }
  3680. } // if ($iassign_array[$j]->type_iassign == 3)
  3681. } // if ($iassign_submission)
  3682. elseif ($iassign_array[$j]->type_iassign == 3) {
  3683. $icon_status = iassign_icons::insert('not_post');
  3684. } // if ($iassign_array[$j]->type_iassign == 3)
  3685. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3686. } // if ($iassign_array[$j]->visible == 1)
  3687. } // for ($j = 0; $j < $i; $j++)
  3688. } else if (isguestuser()) {
  3689. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3690. print '<table width=100% ><tr>' . "\n";
  3691. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3692. print '</tr></table>' . "\n";
  3693. for ($j = 0; $j < $i; $j ++) {
  3694. $icon_status = "";
  3695. $icon_comment = "";
  3696. if ($iassign_array[$j]->visible == 1) {
  3697. $iassign_current = $iassign_array[$j]->id;
  3698. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3699. print '<p>' . $links . '</p>' . "\n";
  3700. } // if ($iassign_array[$j]->visible == 1)
  3701. }
  3702. }
  3703. print $OUTPUT->box_end();
  3704. } // function show_iassign($title, $iassign_array, $i)
  3705. /// Show message of return
  3706. function return_home_course ($message) {
  3707. //D global $DB, $OUTPUT;
  3708. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3709. //D echo $OUTPUT->box_start();
  3710. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3711. //D echo '<tr><td align="left"><strong>' . "\n";
  3712. //D print_string($message, 'iassign');
  3713. //D echo '</strong></td>' . "\n";
  3714. //D echo '<td width=20% align="right">' . "\n";
  3715. //D echo $link_return;
  3716. //D echo '</td></tr></table>' . "\n";
  3717. //D echo $OUTPUT->box_end();
  3718. //D // echo $OUTPUT->footer();
  3719. redirect(new moodle_url($this->return . '&notice=' . $message));
  3720. exit;
  3721. }
  3722. /// Search comment of activity
  3723. function search_comment_submission ($iassign_submissionid) {
  3724. global $USER, $DB, $OUTPUT, $COURSE;
  3725. // $context = context_course::instance($COURSE->id);
  3726. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3727. $colorEdit2 = "#d2e5fc";
  3728. $has_capability = 0;
  3729. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3730. $text = "";
  3731. if ($comments) {
  3732. $even = 1;
  3733. foreach ($comments as $tmp) {
  3734. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3735. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3736. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3737. // $text .= $tmp->comment . "</td></tr>";
  3738. //} else {
  3739. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3740. $avatar = new user_picture($user_data);
  3741. $avatar->courseid = $COURSE->id;
  3742. $avatar->link = true;
  3743. $user_picture = $OUTPUT->render($avatar);
  3744. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3745. if ($even) {
  3746. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3747. $even = 0;
  3748. } else {
  3749. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3750. $even = 1;
  3751. }
  3752. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3753. } // foreach ($comments as $tmp)
  3754. }
  3755. return $text;
  3756. }
  3757. /// Update comment of activity
  3758. function update_comment ($iassign_submissionid) {
  3759. global $USER, $DB, $OUTPUT;
  3760. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3761. $receiver = 1; // student message to teacher
  3762. else
  3763. $receiver = 2; // teacher message to student
  3764. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3765. if ($verify_message) {
  3766. foreach ($verify_message as $message) {
  3767. if ($message->receiver == $receiver) {
  3768. $newentry = new stdClass();
  3769. $newentry->id = $message->id;
  3770. $newentry->return_status = 1;
  3771. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3772. print_error('error_update', 'iassign');
  3773. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3774. } // if ($message->receiver == $receiver)
  3775. // Trigger module viewed event.
  3776. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3777. 'objectid' => $this->iassign->id,
  3778. 'context' => $this->context
  3779. ));
  3780. $event->add_record_snapshot('course', $this->course);
  3781. $event->trigger();
  3782. } // foreach ($verify_message as $message)
  3783. }
  3784. }
  3785. /// Record comment of activity
  3786. function write_comment_submission () {
  3787. global $USER, $CFG, $DB;
  3788. $id = $this->cm->id;
  3789. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3790. $row = optional_param('row', 0, PARAM_INT);
  3791. $column = optional_param('column', 0, PARAM_INT);
  3792. $sum_comment = 0;
  3793. $return = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $this->iassign_submission_current . "&userid_iassign=" . $this->userid_iassign . "&iassign_current=" . $this->activity->get_activity()->id . "&row=" . ($row) . "&column=" . ($column);
  3794. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3795. $str1 = trim($submission_comment);
  3796. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3797. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3798. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3799. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3800. $receiver = 1; // student message to teacher
  3801. $this->action = 'view';
  3802. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3803. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3804. } else {
  3805. $receiver = 2; // teacher message to student
  3806. $this->action = 'viewsubmission';
  3807. //D $tousers = array(); //MOOC 2016
  3808. //MOOC 2016 //T $tousers[] = $DB->get_record("user", array("id" => $iassign_submission->userid)); //TODO Para registrar mensagem na area do Moodle - tem que ativar abaixo
  3809. }
  3810. //MOOC 2016: foi p/ 15 linhas acima:
  3811. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3812. // verificar se existe uma submissão para o exercício e aluno informados
  3813. if (!$iassign_submission) {
  3814. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3815. }
  3816. if (!$iassign_submission) {
  3817. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3818. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3819. $this->iassign_submission_current = $id_submission;
  3820. } else {
  3821. $id_submission = $iassign_submission->id;
  3822. } // if (!$iassign_submission)
  3823. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3824. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3825. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3826. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3827. $comments = $DB->get_record_sql(
  3828. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3829. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3830. if ($comments)
  3831. foreach ($comments as $tmp)
  3832. $sum_comment = $tmp;
  3833. if ($sum_comment == 0) {
  3834. $newentry = new stdClass();
  3835. $newentry->iassign_submissionid = $id_submission;
  3836. $newentry->comment_authorid = $USER->id;
  3837. $newentry->timecreated = time();
  3838. $newentry->comment = $submission_comment;
  3839. $newentry->receiver = $receiver;
  3840. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3841. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3842. //T $eventdata = new stdClass();
  3843. //T $eventdata->component = 'mod_iassign'; //your component name
  3844. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3845. //T $eventdata->userfrom = $USER;
  3846. //T $eventdata->userto = $touser;
  3847. //T $eventdata->subject = "Teste de Subject";
  3848. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3849. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3850. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3851. //T $eventdata->smallmessage = "Teste de Mensagem";
  3852. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3853. //T // alteracao tulio faria
  3854. //T //message_send($eventdata);
  3855. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3856. // Trigger module viewed event.
  3857. $event = \mod_iassign\event\submission_comment_created::create(array(
  3858. 'objectid' => $this->iassign->id,
  3859. 'context' => $this->context
  3860. ));
  3861. $event->add_record_snapshot('course', $this->course);
  3862. $event->trigger();
  3863. }
  3864. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3865. // if ($this->action=='viewsubmission') {
  3866. // echo $OUTPUT->header();
  3867. // $this->return_last('confirm_add_comment', $link_return);
  3868. // die;
  3869. // }
  3870. return true;
  3871. } // function write_comment_submission()
  3872. /// Writes a new submission
  3873. // The first student answer is under 'function get_answer()'
  3874. function new_submission ($iassignid, $id_user, $receiver) {
  3875. global $USER, $DB, $OUTPUT;
  3876. $newentry = new stdClass();
  3877. $newentry->iassign_statementid = $iassignid;
  3878. $newentry->userid = $id_user;
  3879. $newentry->timecreated = time();
  3880. $newentry->timemodified = time();
  3881. $newentry->answer = 0; // student only submit message
  3882. if ($receiver == 2) // teacher message to student (write id teacher)
  3883. $newentry->teacher = $USER->id;
  3884. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3885. return_home_course('error_insert_submissions');
  3886. else {
  3887. // Trigger module view event
  3888. $event = \mod_iassign\event\submission_created::create(array(
  3889. 'objectid' => $this->iassign->id,
  3890. 'context' => $this->context
  3891. ));
  3892. $event->add_record_snapshot('course', $this->course);
  3893. $event->trigger();
  3894. }
  3895. return $newentry->id;
  3896. }
  3897. /// Return to a specific address of page
  3898. function return_last ($message, $link_return) {
  3899. global $DB, $OUTPUT;
  3900. print $OUTPUT->box_start();
  3901. print '<table width=100% border=0 valign="top">' . "\n";
  3902. print '<tr><td align="left"><strong>' . "\n";
  3903. print_string($message, 'iassign');
  3904. print '</strong></td>' . "\n";
  3905. print '<td width=20% align="right">' . "\n";
  3906. print $link_return;
  3907. print '</td></tr></table>' . "\n";
  3908. print $OUTPUT->box_end();
  3909. print $OUTPUT->footer();
  3910. die();
  3911. } // function return_last($message, $link_return)
  3912. } // class iassign
  3913. /// Class for manage activities
  3914. class activity {
  3915. var $activity;
  3916. /// Constructor of class.
  3917. // @param int $id Id of activity
  3918. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3919. //D public function activity($id) { self::__construct($id); }
  3920. function __construct ($id) {
  3921. global $DB;
  3922. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3923. if (empty($this->activity))
  3924. $this->activity = null;
  3925. }
  3926. /// Get an activity
  3927. // @return NULL
  3928. function get_activity () {
  3929. if ($this->activity != null)
  3930. return $this->activity;
  3931. else
  3932. return null;
  3933. }
  3934. /// Delete interactive activities
  3935. function delete ($return) {
  3936. global $USER, $CFG, $DB, $OUTPUT;
  3937. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3938. $output = $OUTPUT->header();
  3939. $output .= $OUTPUT->box_start();
  3940. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3941. if ($iassign_submission_currents) {
  3942. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3943. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3944. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3945. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3946. $output .= $OUTPUT->box_end();
  3947. $output .= $OUTPUT->footer();
  3948. print $output;
  3949. die();
  3950. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3951. } // if ($iassign_submission_currents)
  3952. else
  3953. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3954. $output .= '<table width=50% border=0>';
  3955. $output .= '<tr valign="top"><td>';
  3956. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3957. $output .= '</td><td>';
  3958. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3959. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3960. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3961. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3962. $output .= "</form>\n";
  3963. $output .= '</td><td>';
  3964. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3965. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3966. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3967. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3968. $output .= "</form>\n";
  3969. $output .= '</td></tr></table>' . "\n";
  3970. $output .= $OUTPUT->box_end();
  3971. $output .= $OUTPUT->footer();
  3972. print $output;
  3973. } // function delete($return)
  3974. /// Function for confirm the delete of activity
  3975. // @param String $return Url of return
  3976. // @param Object $iassign Object content an activity
  3977. function deleteyes ($return, $iassign) {
  3978. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3979. $msg = '';
  3980. if (!empty($this->activity->id)) {
  3981. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3982. if ($iassign_submission_currents) {
  3983. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3984. foreach ($iassign_submission_currents as $iassign_submission)
  3985. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3986. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3987. } // if ($iassign_submission_currents)
  3988. }
  3989. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3990. // Remove all files associated to this activity:
  3991. $fs = get_file_storage();
  3992. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3993. $this->delete_calendar($this->activity->id);
  3994. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3995. iassign::update_grade_iassign($this->activity->iassignid);
  3996. if ($delete_iassign_current) {
  3997. $iassign->return_home_course('confirm_delete_iassign');
  3998. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3999. } else {
  4000. $iassign->return_home_course('error_confirm_delete_iassign');
  4001. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4002. }
  4003. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4004. }
  4005. }
  4006. /// Changes position of activities (between those inside a group of interactive activities)
  4007. // @param $move_action = must be "up" or "down"
  4008. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4009. function move_iassign ($move_action, $target, $return) {
  4010. global $DB, $OUTPUT;
  4011. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4012. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4013. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4014. if ($move_action=="firstdown") {
  4015. $final_position_source = 2;
  4016. $final_position_target = 1;
  4017. }
  4018. else
  4019. if ($move_action=="down") {
  4020. $final_position_target = $this->activity->position;
  4021. $final_position_source = $final_position_target + 1;
  4022. }
  4023. else
  4024. if ($move_action=="up") {
  4025. $final_position_target = $this->activity->position;
  4026. $final_position_source = $final_position_target - 1;
  4027. }
  4028. else { // error:
  4029. print_error('error_update_move_iassign', 'iassign');
  4030. exit;
  4031. }
  4032. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4033. $newentry->id = $this->activity->id; // ID of the "source activity"
  4034. $newentry->position = $final_position_source;
  4035. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4036. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4037. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4038. print_error('error_update_move_iassign', 'iassign');
  4039. }
  4040. else { // first update performed successfully
  4041. $newentry->id = $iassign_target->id;
  4042. $newentry->position = $final_position_target;
  4043. if (!$DB->update_record('iassign_statement', $newentry))
  4044. print_error('error_update_move_iassign', 'iassign');
  4045. }
  4046. redirect($return);
  4047. }
  4048. /// Enable or disable the display of interactive activities
  4049. function visible_iassign ($return) {
  4050. global $DB;
  4051. $newentry = new stdClass();
  4052. $newentry->id = $this->activity->id;
  4053. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4054. if (!$DB->update_record('iassign_statement', $newentry))
  4055. print_error('error_update_visible_iassign', 'iassign');
  4056. redirect($return);
  4057. }
  4058. /// Add news interactive activities (register in table 'iassign_statement')
  4059. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4060. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4061. function new_iassign ($param) {
  4062. global $DB;
  4063. $newentry = new stdClass();
  4064. $newentry->iassignid = $param->iassignid;
  4065. $newentry->name = $param->name;
  4066. $newentry->type_iassign = $param->type_iassign;
  4067. $newentry->store_all_submissions = $param->store_all_submissions;
  4068. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4069. $proposition = $param->proposition;
  4070. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4071. else $proposition_text = $proposition;
  4072. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4073. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4074. //TODO Then get it directly from the form data $_POST!
  4075. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4076. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4077. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4078. $newentry->author_name = $param->author_name;
  4079. $newentry->author_modified_name = $param->author_modified_name;
  4080. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4081. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4082. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4083. $newentry->grade = $param->grade;
  4084. $newentry->timemodified = time();
  4085. $newentry->timecreated = time();
  4086. if ($param->type_iassign == 1) {
  4087. $newentry->timedue = 0;
  4088. $newentry->timeavailable = 0;
  4089. } // if ($param->type_iassign == 1)
  4090. else {
  4091. $newentry->timedue = $param->timedue;
  4092. $newentry->timeavailable = $param->timeavailable;
  4093. }
  4094. $newentry->preventlate = $param->preventlate;
  4095. $newentry->test = $param->test;
  4096. $newentry->special_param1 = $param->special_param1;
  4097. $newentry->visible = $param->visible;
  4098. $newentry->position = $param->position;
  4099. $newentry->max_experiment = $param->max_experiment;
  4100. $newentry->dependency = $param->dependency;
  4101. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4102. $newentry->show_answer = $param->show_answer;
  4103. $id = $DB->insert_record("iassign_statement", $newentry);
  4104. if ($id) {
  4105. $component = 'mod_iassign';
  4106. $filearea = 'exercise';
  4107. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4108. $file = $fs->get_file_by_id($param->file);
  4109. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4110. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4111. //$itemid = $id;
  4112. // File already inserted in other context!
  4113. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4114. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4115. $updateentry = new stdClass();
  4116. $updateentry->id = $id;
  4117. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4118. $updateentry->file = $newfile->get_itemid();
  4119. if (!$DB->update_record("iassign_statement", $updateentry))
  4120. print_error('error_add', 'iassign');
  4121. if ($param->type_iassign == 3)
  4122. iassign::update_grade_iassign($param->iassignid);
  4123. //TODO iLM_HTML5 :: //MOOC2014
  4124. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4125. //D if ($iassign_ilm_configs) {
  4126. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4127. //D if ($iassign_ilm_config->param_type != 'static') {
  4128. //D $newentry = new stdClass();
  4129. //D $newentry->iassign_statementid = $id;
  4130. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4131. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4132. //D $newentry->param_value =(is_array($param->{'param_'.$iassign_ilm_config->id}) ? implode(",", $param->{'param_'.$iassign_ilm_config->id}) : $param->{'param_'.$iassign_ilm_config->id});
  4133. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4134. //D print_error('error_add_param', 'iassign');
  4135. //D }
  4136. //D }
  4137. //D }
  4138. // log event --------------------------------------------------------------------------------------
  4139. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4140. // log event --------------------------------------------------------------------------------------
  4141. return $id;
  4142. }
  4143. else
  4144. print_error('error_add', 'iassign');
  4145. } // function new_iassign($param)
  4146. /// Add the calendar entries for this iassign
  4147. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4148. // @return bool
  4149. static function add_calendar ($iassignid) {
  4150. global $DB, $CFG;
  4151. require_once($CFG->dirroot . '/calendar/lib.php');
  4152. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4153. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4154. $event = new stdClass();
  4155. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4156. $event->description = $iassign_statement_activity_item->name;
  4157. $event->courseid = $iassign->course;
  4158. $event->groupid = 0;
  4159. $event->userid = 0;
  4160. $event->modulename = 'iassign';
  4161. $event->instance = $iassign->id;
  4162. $event->eventtype = 'due';
  4163. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4164. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4165. calendar_event::create($event);
  4166. }
  4167. /// Update the calendar entries for this iassign
  4168. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4169. // @return bool
  4170. function update_calendar ($iassignid, $olddescription) {
  4171. global $DB, $CFG;
  4172. require_once($CFG->dirroot . '/calendar/lib.php');
  4173. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4174. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4175. $event = new stdClass();
  4176. $event->id = 0;
  4177. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4178. if ($events) {
  4179. foreach ($events as $value) {
  4180. if ($value->description == $olddescription) {
  4181. $event->id = $value->id;
  4182. }
  4183. }
  4184. }
  4185. if ($event->id != 0) {
  4186. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4187. $event->description = $iassign_statement_activity_item->name;
  4188. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4189. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4190. $calendarevent = calendar_event::load($event->id);
  4191. $calendarevent->update($event);
  4192. } else
  4193. $this->add_calendar($iassignid);
  4194. }
  4195. /// Update the calendar entries for this iassign
  4196. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4197. // @return bool
  4198. function delete_calendar ($iassignid) {
  4199. global $DB, $CFG;
  4200. require_once($CFG->dirroot . '/calendar/lib.php');
  4201. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4202. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4203. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4204. if ($events) {
  4205. foreach ($events as $value) {
  4206. if ($value->description == $iassign_statement_activity_item->name) {
  4207. $DB->delete_records('event', array('id' => $value->id));
  4208. }
  4209. }
  4210. }
  4211. }
  4212. /// Update interactive activities
  4213. function update_iassign ($param) {
  4214. global $DB;
  4215. $component = 'mod_iassign';
  4216. $filearea = 'exercise';
  4217. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4218. $file = $fs->get_file_by_id($param->file);
  4219. $fileold = $fs->get_file_by_id($param->fileold);
  4220. if ($param->file != $param->fileold) {
  4221. if ($fileold) {
  4222. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4223. foreach ($fileoldarea as $value) {
  4224. $value->delete();
  4225. }
  4226. }
  4227. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4228. $itemid = $file->get_itemid() + $param->iassign_id;
  4229. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4230. $param->file = $newfile->get_itemid();
  4231. } else
  4232. $param->file = $file->get_itemid();
  4233. } else {
  4234. $param->file = $file->get_itemid();
  4235. }
  4236. $newentry = new stdClass();
  4237. $newentry->id = $param->iassign_id;
  4238. $newentry->name = $param->name;
  4239. $newentry->type_iassign = $param->type_iassign;
  4240. $newentry->store_all_submissions = $param->store_all_submissions;
  4241. //2019 $newentry->proposition = $param->proposition;
  4242. $proposition = $param->proposition;
  4243. if (is_array($proposition))
  4244. $proposition_text = $proposition['text'];
  4245. else
  4246. $proposition_text = $proposition;
  4247. $newentry->proposition = $proposition_text;
  4248. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4249. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4250. $newentry->grade = $param->grade;
  4251. $newentry->author_modified_name = $param->author_modified_name;
  4252. $newentry->timemodified = time();
  4253. if ($param->type_iassign == 1) {
  4254. $newentry->timedue = 0;
  4255. $newentry->timeavailable = 0;
  4256. } // if ($param->type_iassign == 1)
  4257. else {
  4258. $newentry->timedue = $param->timedue;
  4259. $newentry->timeavailable = $param->timeavailable;
  4260. }
  4261. $newentry->preventlate = $param->preventlate;
  4262. $newentry->test = $param->test;
  4263. $newentry->special_param1 = $param->special_param1;
  4264. $newentry->visible = $param->visible;
  4265. $newentry->max_experiment = $param->max_experiment;
  4266. $newentry->dependency = $param->dependency;
  4267. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4268. $newentry->show_answer = $param->show_answer;
  4269. if (!$DB->update_record("iassign_statement", $newentry))
  4270. print_error('error_update', 'iassign');
  4271. if ($param->type_iassign == 3) {
  4272. iassign::update_grade_iassign($param->iassignid);
  4273. }
  4274. //$id = $newentry->id; // MOOC 2016 --- inicio
  4275. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4276. //if ($iassign_activity_item_configs) {
  4277. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4278. // $newentry = new stdClass();
  4279. // $newentry->id = $iassign_activity_item_config->id;
  4280. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4281. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4282. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4283. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4284. // print_error('error_edit_param', 'iassign');
  4285. // }
  4286. // } // MOOC 2016 --- final
  4287. // log event --------------------------------------------------------------------------------------
  4288. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4289. // log event --------------------------------------------------------------------------------------
  4290. return $newentry->id;
  4291. // if ($param->type_iassign==3)
  4292. // $this->update_grade_iassign($param->iassignid);
  4293. } // function update_iassign($param)
  4294. /// Show information of activity
  4295. function show_info_iassign () {
  4296. global $DB, $OUTPUT;
  4297. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4298. if ($this->activity->type_iassign == 3) {
  4299. if ($this->activity->dependency == 0) {
  4300. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4301. } else {
  4302. $dependencys = explode(';', $this->activity->dependency);
  4303. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4304. foreach ($dependencys as $dependency) {
  4305. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4306. if ($dependencyiassign)
  4307. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4308. } // foreach ($dependencys as $dependency)
  4309. } // if ($iassign_statement_activity_item->dependency == 0)
  4310. if ($this->activity->max_experiment == 0)
  4311. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4312. else
  4313. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4314. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4315. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4316. print $OUTPUT->box($output);
  4317. } // function show_info_iassign()
  4318. /// Shows date of opening and closing activities
  4319. function view_dates () {
  4320. global $USER, $CFG, $DB, $OUTPUT;
  4321. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4322. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4323. $status_iassign = "";
  4324. $status_iassign1 = "";
  4325. $status_iassign2 = "";
  4326. if ($this->activity->type_iassign == 1) // activity of type example
  4327. $type_iassign = get_string('example_iassign', 'iassign');
  4328. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4329. $type_iassign = get_string('test_iassign', 'iassign');
  4330. if ($this->activity->timeavailable > time()) {
  4331. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4332. } elseif ($this->activity->timedue < time()) {
  4333. $status_iassign = get_string('last_timedue', 'iassign');
  4334. }
  4335. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4336. $type_iassign = get_string('exercise_iassign', 'iassign');
  4337. if ($this->activity->timeavailable > time()) {
  4338. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4339. } elseif ($this->activity->timedue < time()) { // after delivery
  4340. $status_iassign = get_string('last_timedue', 'iassign');
  4341. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4342. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4343. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4344. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4345. if ($this->activity->test == 1) // allowed to test after of deadline
  4346. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4347. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4348. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4349. } // elseif ($iassign_statement_activity_item->test == 0)
  4350. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4351. } // elseif ($iassign_statement_activity_item->timedue < time())
  4352. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4353. $output = '<table width=100% >' . "\n";
  4354. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4355. $output .= '<tr>' . "\n";
  4356. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4357. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4358. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4359. // leo $output .= '<td width=80%>' . $type_iassign;
  4360. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4361. // $output .= '</td>' . "\n";
  4362. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4363. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4364. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=report&iassignid=" . $this->activity->iassign_ilmid . "'>" . iassign_icons::insert('view_report') . '&nbsp;' . get_string('report', 'iassign') . "</a>";
  4365. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4366. } else {
  4367. $link_next = "";
  4368. $link_previous = "";
  4369. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4370. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4371. // previous_activity
  4372. if ($iassign_previous) {
  4373. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4374. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4375. } // next_activity
  4376. if ($iassign_next) {
  4377. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4378. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4379. }
  4380. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4381. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4382. $output .= '</tr></table>' . "\n";
  4383. $output .= '<table width=100% >' . "\n";
  4384. if ($this->activity->type_iassign > 1) {
  4385. if ($this->activity->timeavailable)
  4386. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4387. if ($this->activity->timedue)
  4388. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4389. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4390. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4391. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4392. $output .= '</table>' . "\n";
  4393. print $OUTPUT->box($output);
  4394. } // function view_dates()
  4395. } // class activity
  4396. /// Class to manage Interactive Learning Module (iLM)
  4397. class ilm {
  4398. var $ilm;
  4399. /// Constructor of class
  4400. // @param int $id Id of iLM
  4401. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4402. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4403. function __construct ($id) {
  4404. global $DB;
  4405. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4406. if (empty($this->ilm))
  4407. $this->ilm = null;
  4408. }
  4409. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4410. // @calledby view_iassign_current()
  4411. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4412. global $USER, $CFG, $DB;
  4413. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4414. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4415. $typec = strtolower($iassign_ilm->type);
  4416. require_once 'ilm_handlers/' . $typec . '.php';
  4417. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4418. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4419. return $retorno;
  4420. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4421. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4422. // @calledby view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) : $id_iLM_security=$this->write_iLM_security($iassign_statement_activity_item->id,$content_or_id_from_ilm_security);
  4423. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4424. // @param Object $file File in use in activity
  4425. // @return int Return the id of log
  4426. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4427. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4428. $newentry = new stdClass();
  4429. $newentry->iassign_statementid = $iassign_activity_itemid;
  4430. $newentry->userid = $USER->id;
  4431. $newentry->file = $content_or_id_from_ilm_security;
  4432. $newentry->timecreated = time();
  4433. $newentry->view = 1;
  4434. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4435. if (!$id_iLM_security) {
  4436. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4437. } // from (!$DB->insert_record("iassign_security", $newentry))
  4438. return $id_iLM_security;
  4439. }
  4440. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4441. // @calledby view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) : $this->remove_old_iLM_security_entries($USER->id, $iassign_statement_activity_item->id);
  4442. // @param int $userid
  4443. // @param int $iassign_activity_itemid Id of iassign statement
  4444. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4445. global $DB;
  4446. // This is an additional security: erase eventually old entries in 'iassign_security' table (do not remove '$iassign_activity_itemid' since it is going to be used "now")
  4447. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4448. }
  4449. } // class ilm
  4450. /// Class to manage settings of iLM.
  4451. class ilm_settings {
  4452. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4453. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4454. // @param int $ilm_id Id of iLM
  4455. // @param array $options An array with options for create dynamic tag html APPLET
  4456. // @return string Return with a tag html APPLET created
  4457. static function build_ilm_tags ($ilm_id, $options = array()) {
  4458. global $DB;
  4459. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4460. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4461. $typec = strtolower($iassign_ilm->type);
  4462. require_once 'ilm_handlers/' . $typec . '.php';
  4463. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4464. return $retorno;
  4465. } // static function build_ilm_tags($ilm_id, $options = array())
  4466. /// Function for get modified date of iLM file
  4467. // @param string $file_jar String with Ids of iLM files
  4468. // @return string Return with the filenames and modified date
  4469. static function applet_filetime ($file_jar) {
  4470. $filetime = "";
  4471. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4472. $files_jar = explode(",", $file_jar);
  4473. foreach ($files_jar as $one_file) {
  4474. $file = $fs->get_file_by_id($one_file);
  4475. if ($file)
  4476. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4477. }
  4478. return $filetime;
  4479. }
  4480. /// Function for verify an default applet
  4481. // @param String $file_jar String containing an list de ids of applet files
  4482. // @return boolean Return true or fale if applet is default
  4483. static function applet_default ($file_jar) {
  4484. $is_default = true;
  4485. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4486. $files_jar = explode(",", $file_jar);
  4487. foreach ($files_jar as $one_file) {
  4488. $file = $fs->get_file_by_id($one_file);
  4489. if ($file)
  4490. $is_default &= ($file->get_itemid() == 0);
  4491. }
  4492. return $is_default;
  4493. }
  4494. /// Function for get form variables for add, edit, or copy iLM
  4495. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4496. // @see settings_form.php
  4497. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4498. // @param int $ilm_id Id of iLM
  4499. // @param string $action String with the action
  4500. // @return object Return an object with forms variables
  4501. static function add_edit_copy_ilm ($ilm_id, $action) {
  4502. global $USER, $DB, $CFG;
  4503. require_once('settings_form.php'); // put the form
  4504. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4505. $param = new stdClass();
  4506. $param->action = $action;
  4507. $param->ilm_id = $ilm_id;
  4508. $CFG->action_ilm = $action;
  4509. $CFG->ilm_id = $ilm_id;
  4510. if ($action == 'add') {
  4511. $param->title = get_string('add_ilm', 'iassign');
  4512. $param->name = "";
  4513. $param->version = "";
  4514. $param->url = "";
  4515. $param->description = "";
  4516. $param->extension = "";
  4517. $param->author = $USER->id;
  4518. $param->file_jar = "";
  4519. $param->file_jar_static = "";
  4520. $param->file_class = "";
  4521. $param->width = 800;
  4522. $param->height = 600;
  4523. $param->enable = 0; // 0 - hide / 1 - show
  4524. $param->timecreated = time();
  4525. $param->timemodified = time();
  4526. $param->evaluate = 0;
  4527. $param->parent = 0;
  4528. }
  4529. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4530. if ($iassign_ilm) {
  4531. $description = json_decode($iassign_ilm->description);
  4532. $param->title = get_string('edit_ilm', 'iassign');
  4533. $param->id = $iassign_ilm->id;
  4534. $param->name_ilm = $iassign_ilm->name;
  4535. $param->name = $iassign_ilm->name;
  4536. $param->version = $iassign_ilm->version;
  4537. $param->ilm_type = $iassign_ilm->type;
  4538. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4539. $param->url = $iassign_ilm->url;
  4540. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4541. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4542. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4543. if (!isset($description->{current_language()})) {
  4544. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4545. else
  4546. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4547. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4548. }
  4549. else
  4550. $param->description = $description->{current_language()};
  4551. $param->description_lang = $iassign_ilm->description;
  4552. $param->extension = $iassign_ilm->extension;
  4553. $param->author = $iassign_ilm->author;
  4554. $param->file_jar = $iassign_ilm->file_jar;
  4555. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4556. $param->file_class = $iassign_ilm->file_class;
  4557. $param->width = $iassign_ilm->width;
  4558. $param->height = $iassign_ilm->height;
  4559. $param->enable = $iassign_ilm->enable;
  4560. $param->timecreated = $iassign_ilm->timecreated;
  4561. $param->timemodified = time();
  4562. $param->evaluate = $iassign_ilm->evaluate;
  4563. $param->parent = $iassign_ilm->parent;
  4564. }
  4565. }
  4566. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4567. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4568. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4569. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4570. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4571. // echo "Sem dados<br/>"; exit;
  4572. return;
  4573. }
  4574. $description = json_decode($iassign_ilm->description);
  4575. if ($iassign_ilm) {
  4576. if ($iassign_ilm->parent == 0)
  4577. $iassign_ilm->parent = $ilm_id;
  4578. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4579. $param->title = get_string('new_version_ilm', 'iassign');
  4580. $param->name_ilm = $iassign_ilm->name;
  4581. $param->name = $iassign_ilm->name;
  4582. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4583. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4584. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4585. $param->ilm_type = $iassign_ilm->type;
  4586. $param->url = $iassign_ilm->url;
  4587. $param->description = $description->{current_language()};
  4588. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4589. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4590. $param->extension = $iassign_ilm->extension;
  4591. $param->author = $USER->id;
  4592. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4593. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4594. $param->file_jar_static = '';
  4595. $param->file_class = $iassign_ilm->file_class;
  4596. $param->width = $iassign_ilm->width;
  4597. $param->height = $iassign_ilm->height;
  4598. $param->enable = 0;
  4599. $param->timecreated = time();
  4600. $param->timemodified = time();
  4601. $param->evaluate = $iassign_ilm->evaluate;
  4602. $param->parent = $iassign_ilm->parent;
  4603. }
  4604. }
  4605. elseif ($action == 'copy') {
  4606. $description = json_decode($iassign_ilm->description);
  4607. if ($iassign_ilm) {
  4608. if ($iassign_ilm->parent == 0)
  4609. $iassign_ilm->parent = $ilm_id;
  4610. $param->title = get_string('copy_ilm', 'iassign');
  4611. $param->id = $iassign_ilm->id;
  4612. $param->name_ilm = $iassign_ilm->name;
  4613. $param->name = $iassign_ilm->name;
  4614. $param->version = "";
  4615. $param->ilm_type = $iassign_ilm->type;
  4616. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4617. $param->url = $iassign_ilm->url;
  4618. $param->description = $description->{current_language()};
  4619. $param->description_lang = $iassign_ilm->description;
  4620. $param->extension = $iassign_ilm->extension;
  4621. $param->author = $USER->id;
  4622. $param->file_jar = '';
  4623. $param->file_jar_static = '';
  4624. $param->file_class = $iassign_ilm->file_class;
  4625. $param->width = $iassign_ilm->width;
  4626. $param->height = $iassign_ilm->height;
  4627. $param->enable = 0;
  4628. $param->timecreated = time();
  4629. $param->timemodified = time();
  4630. $param->evaluate = $iassign_ilm->evaluate;
  4631. $param->parent = $iassign_ilm->parent;
  4632. }
  4633. }
  4634. return $param;
  4635. } // static function add_edit_copy_ilm($ilm_id, $action)
  4636. /// Function for save iLM file in moodledata
  4637. // @param int $itemid Itemid of file save in draft (upload file)
  4638. // @param int $ilm_id Id of iLM
  4639. // @return string Return an string with ids of iLM files
  4640. static function new_file_ilm ($itemid, $iassign_ilm) {
  4641. global $CFG, $USER, $DB;
  4642. $return = null;
  4643. $file_jar = array();
  4644. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4645. $contextuser = context_user::instance($USER->id);
  4646. $contextsystem = context_system::instance();
  4647. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4648. if ($files_ilm) {
  4649. foreach ($files_ilm as $value) {
  4650. // CHECK IF file is HTML type
  4651. if ($iassign_ilm->type == 1) {
  4652. // Check if the file extension is ZIP
  4653. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4654. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4655. if ((strtolower($ext) == 'zip')) {
  4656. // Coping...:
  4657. $destination = 'ilm_debug/' . $value->get_filename();
  4658. $value->copy_content_to($destination);
  4659. // Extracting content...:
  4660. $zip = new ZipArchive();
  4661. $extracted = './ilm';
  4662. $dir = "";
  4663. if ($zip->open($destination) === TRUE) {
  4664. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4665. if (is_dir($dir)) {
  4666. $i = 1;
  4667. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4668. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4669. $i ++;
  4670. }
  4671. $name = $previous . "_" . $i;
  4672. $dir = './ilm/' . $name . "/";
  4673. $j = 0;
  4674. while ($item_name = $zip->getNameIndex($j)) {
  4675. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4676. $j++;
  4677. }
  4678. $zip->close();
  4679. }
  4680. $zip->open($destination);
  4681. $zip->extractTo($extracted);
  4682. $zip->close();
  4683. // After the extraction, remove it from DEBUG
  4684. unlink($destination);
  4685. } else { // Error trying to open destination...
  4686. // After the extraction error, also remove it from DEBUG
  4687. unlink($destination);
  4688. print_error('error_add_ilm_zip', 'iassign');
  4689. }
  4690. return $dir;
  4691. }
  4692. } // if ($iassign_ilm->type == 1)
  4693. if ($value->get_filename() != '.') {
  4694. $file_ilm = array(
  4695. 'userid' => $USER->id,
  4696. 'contextid' => $contextsystem->id,
  4697. 'component' => 'mod_iassign',
  4698. 'filearea' => 'ilm',
  4699. 'itemid' => rand(1, 999999999),
  4700. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4701. 'filename' => $value->get_filename());
  4702. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4703. array_push($file_jar, $file_ilm->get_id());
  4704. }
  4705. }
  4706. if (!empty($file_jar)) {
  4707. $return = implode(",", $file_jar);
  4708. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4709. foreach ($old_file_jar as $value) {
  4710. $file = $fs->get_file_by_id($value);
  4711. if ($file)
  4712. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4713. }
  4714. }
  4715. }
  4716. else // if ($files_ilm)
  4717. $return = $iassign_ilm->file_jar;
  4718. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4719. return $return;
  4720. } // static function new_file_ilm($itemid, $iassign_ilm)
  4721. /// Function for save in database an new iLM
  4722. // @param object $param An object with iLM params
  4723. static function new_ilm ($itemid) {
  4724. global $CFG, $USER, $OUTPUT;
  4725. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4726. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4727. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4728. }
  4729. $pathtemp = $CFG->dataroot . '/temp/';
  4730. $contextuser = context_user::instance($USER->id);
  4731. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4732. $zip = new zip_packer();
  4733. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4734. foreach ($files as $file) {
  4735. if (!$file->is_directory())
  4736. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4737. }
  4738. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4739. // Verifica se o pacote possui o XML
  4740. if (!$application_xml) {
  4741. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4742. return;
  4743. } else {
  4744. $missing = "";
  4745. if (!isset($application_xml->name)) {
  4746. $missing .= "name";
  4747. }
  4748. if (!isset($application_xml->version)) {
  4749. $missing .= ", version";
  4750. }
  4751. if (!isset($application_xml->type)) {
  4752. $missing .= ", type";
  4753. }
  4754. if (!isset($application_xml->extension)) {
  4755. $missing .= ", extension";
  4756. }
  4757. if (!isset($application_xml->file_jar)) {
  4758. $missing .= ", file_jar";
  4759. }
  4760. if (!isset($application_xml->file_class)) {
  4761. $missing .= ", file_class";
  4762. }
  4763. if (!isset($application_xml->width)) {
  4764. $missing .= ", width";
  4765. }
  4766. if (!isset($application_xml->height)) {
  4767. $missing .= ", height";
  4768. }
  4769. if (!isset($application_xml->evaluate)) {
  4770. $missing .= ", evaluate";
  4771. }
  4772. if (strlen($missing) > 2) {
  4773. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4774. return;
  4775. }
  4776. }
  4777. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4778. $typec = strtolower($application_xml->type);
  4779. require_once 'ilm_handlers/' . $typec . '.php';
  4780. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4781. return $retorno;
  4782. } // static function new_ilm($itemid)
  4783. /// Function for save in database an iLM edit
  4784. // @param object $param An object with iLM params
  4785. static function edit_ilm ($param, $itemid) {
  4786. // Descobrir o tipo de iLM:
  4787. global $DB, $USER, $CFG;
  4788. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4789. $pathtemp = $CFG->dataroot . '/temp/';
  4790. $contextuser = context_user::instance($USER->id);
  4791. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4792. $zip = new zip_packer();
  4793. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4794. $files_extract = null;
  4795. foreach ($files as $file) {
  4796. if (!$file->is_directory())
  4797. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4798. }
  4799. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4800. $typec = strtolower($iassign_t->type);
  4801. require_once 'ilm_handlers/' . $typec . '.php';
  4802. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4803. }
  4804. /// Function for register the new iLM (in database and in the directory)
  4805. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4806. // @param object $param An object with iLM params
  4807. static function copy_new_version_ilm ($param) {
  4808. global $DB, $CFG, $USER;
  4809. $itemid = $param->file;
  4810. $pathtemp = $CFG->dataroot . '/temp/';
  4811. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4812. //D echo "pathtemp=$pathtemp<br/>";
  4813. $contextuser = context_user::instance($USER->id);
  4814. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4815. $zip = new zip_packer();
  4816. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4817. $files_extract = null;
  4818. foreach ($files as $file) {
  4819. if (!$file->is_directory())
  4820. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4821. }
  4822. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4823. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4824. $typec = strtolower($iassign_t->type);
  4825. require_once 'ilm_handlers/' . $typec . '.php';
  4826. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4827. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4828. } // static function copy_new_version_ilm($param)
  4829. //VER::
  4830. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4831. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4832. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4833. /// Function for change visibility of iLM
  4834. // @param int $ilm_id Id of iLM
  4835. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4836. static function visible_ilm ($ilm_id, $status) {
  4837. global $DB;
  4838. if ($status == 0)
  4839. $visible = 1;
  4840. else
  4841. $visible = 0;
  4842. $newentry = new stdClass();
  4843. $newentry->id = $ilm_id;
  4844. $newentry->enable = $visible;
  4845. if (!$DB->update_record("iassign_ilm", $newentry))
  4846. error(get_string('error_edit_ilm', 'iassign'));
  4847. }
  4848. /// Function for confirm change default iLM
  4849. // @param int $ilm_id Id of iLM
  4850. // @param int $ilm_parent Id of parent iLM
  4851. // @return string Return with an string for create default page confirmation
  4852. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4853. global $OUTPUT, $DB;
  4854. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4855. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4856. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4857. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4858. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4859. return $return;
  4860. }
  4861. /// Function for change the default iLM
  4862. // @see settings_ilm.php
  4863. // @param int $ilm_id Id of iLM
  4864. // @return int Return Id of default iLM
  4865. static function default_ilm ($ilm_id) {
  4866. global $DB;
  4867. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4868. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4869. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4870. $iassign_ilm_default->id = $iassign_ilm->id;
  4871. $iassign_ilm_default->parent = 0;
  4872. $iassign_ilm->parent = $iassign_ilm_default->id;
  4873. $iassign_ilm->id = 0;
  4874. $iassign_ilm_default->enable = 1;
  4875. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4876. print_error('error_edit_ilm', 'iassign');
  4877. }
  4878. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4879. if (!$inserted) {
  4880. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4881. print_error($msg_error);
  4882. //xx print_error('error_add_ilm', 'iassign');
  4883. }
  4884. return $iassign_ilm_default->id;
  4885. } // static function default_ilm ($ilm_id)
  4886. /// Function for confirm delete iLM
  4887. // @param int $ilm_id Id of iLM
  4888. // @param int $ilm_parent Id of parent iLM
  4889. // @return string Return with an string for create delete page confirmation
  4890. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4891. global $OUTPUT, $DB;
  4892. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4893. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4894. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4895. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4896. }
  4897. /// Function for delete directory where the iLM is allocated.
  4898. // @param string $dirPath
  4899. // @throws InvalidArgumentException
  4900. public static function delete_dir ($dirPath) {
  4901. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4902. $dirPath .= '/';
  4903. }
  4904. $files = glob($dirPath . '*', GLOB_MARK);
  4905. foreach ($files as $file) {
  4906. if (is_dir($file)) {
  4907. ilm_settings::delete_dir($file);
  4908. } else {
  4909. unlink($file);
  4910. }
  4911. }
  4912. rmdir($dirPath);
  4913. }
  4914. /// Function for delete iLM
  4915. // @param int $ilm_id Id of iLM
  4916. // @return int Return Id of parent iLM
  4917. static function delete_ilm ($ilm_id) {
  4918. global $DB;
  4919. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4920. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4921. $typec = strtolower($iassign_ilm->type);
  4922. require_once 'ilm_handlers/' . $typec . '.php';
  4923. $retorno = $typec::delete_ilm($ilm_id);
  4924. return $retorno;
  4925. }
  4926. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4927. // @param int $ilm_id Id of iLM
  4928. static function export_ilm ($ilm_id) {
  4929. global $DB;
  4930. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4931. if (!$iassign_ilm) return; // security debug...
  4932. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4933. $typec = strtolower($iassign_ilm->type);
  4934. if (!$typec) $typec = "html5"; // security debug...
  4935. require_once 'ilm_handlers/' . $typec . '.php';
  4936. $typec::export_ilm($ilm_id);
  4937. } // static function export_ilm($ilm_id)
  4938. //TODO iLM_HTML5 :: //MOOC 2016
  4939. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4940. // @param int $ilm_id Id of iLM
  4941. static function export_update_ilm ($ilm_id) {
  4942. global $DB, $CFG;
  4943. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4944. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4945. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4946. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4947. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4948. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4949. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4950. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4951. $upgrade_descriptor .= '</upgrade>' . "\n";
  4952. file_put_contents($xml_filename, $upgrade_descriptor);
  4953. header("Pragma: public");
  4954. header("Expires: 0");
  4955. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4956. header("Cache-Control: private", false);
  4957. header('Content-Type: application/xml; charset=utf-8');
  4958. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4959. header("Content-Length: " . @filesize($xml_filename));
  4960. set_time_limit(0);
  4961. @readfile("$xml_filename") || die("File not found.");
  4962. unlink($xml_filename);
  4963. exit;
  4964. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4965. /// Function for save iLM from XML descriptor
  4966. // @param array $application_xml Data of XML descriptor
  4967. // @param array $files_extract Filenames of extract files
  4968. // @return array Return an array content id of JAR files
  4969. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4970. global $CFG, $USER;
  4971. // Tratamento diferenciado se for do tipo HTML5:
  4972. $source = "";
  4973. $diretorio = "";
  4974. if (strtolower($application_xml->type) == 'html5') {
  4975. $i = 0;
  4976. foreach ($files_extract as $key => $value) {
  4977. $file = $CFG->dataroot . '/temp/' . $key;
  4978. // Verifica se já existe a pasta no diretório dos iLM:
  4979. if ($i == 0) {
  4980. $source = $file;
  4981. if (file_exists("ilm/" . basename($file))) {
  4982. $j = 1;
  4983. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4984. $j ++;
  4985. }
  4986. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4987. // mkdir($diretorio, 0777, true);
  4988. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4989. }
  4990. else {
  4991. $diretorio = 'ilm/' . basename($file);
  4992. // mkdir($diretorio, 0777, true);
  4993. mkdir($diretorio, 0755, true);
  4994. }
  4995. break;
  4996. }
  4997. $i ++;
  4998. }
  4999. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5000. if ($item->isDir()) {
  5001. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5002. }
  5003. else {
  5004. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5005. }
  5006. }
  5007. ilm_settings::delete_dir($source);
  5008. return "./" . $diretorio;
  5009. }
  5010. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5011. $file_jar = array();
  5012. $files_ilm = explode(",", $application_xml->file_jar);
  5013. $contextsystem = context_system::instance();
  5014. foreach ($files_ilm as $value) {
  5015. $file_ilm = array(
  5016. 'userid' => $USER->id,
  5017. 'contextid' => $contextsystem->id,
  5018. 'component' => 'mod_iassign',
  5019. 'filearea' => 'ilm',
  5020. 'itemid' => rand(1, 999999999),
  5021. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5022. 'filename' => $value);
  5023. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5024. array_push($file_jar, $file_ilm->get_id());
  5025. }
  5026. foreach ($files_extract as $key => $value) {
  5027. $file = $CFG->dataroot . '/temp/' . $key;
  5028. if (file_exists($file))
  5029. unlink($file);
  5030. }
  5031. return $file_jar;
  5032. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5033. /// Function for import the iLM from an package
  5034. // @param int $itemid Itemid of zip file
  5035. static function import_ilm ($itemid) {
  5036. global $CFG, $USER, $OUTPUT;
  5037. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5038. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5039. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5040. }
  5041. $pathtemp = $CFG->dataroot . '/temp/';
  5042. $contextuser = context_user::instance($USER->id);
  5043. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5044. $zip = new zip_packer();
  5045. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5046. foreach ($files as $file) {
  5047. if (!$file->is_directory())
  5048. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5049. }
  5050. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5051. // Verifica se o pacote possui o XML
  5052. if (!$application_xml) {
  5053. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5054. return;
  5055. } else {
  5056. $missing = "";
  5057. if (!isset($application_xml->name)) {
  5058. $missing .= "name";
  5059. }
  5060. if (!isset($application_xml->version)) {
  5061. $missing .= ", version";
  5062. }
  5063. if (!isset($application_xml->type)) {
  5064. $missing .= ", type";
  5065. }
  5066. if (!isset($application_xml->extension)) {
  5067. $missing .= ", extension";
  5068. }
  5069. if (!isset($application_xml->file_jar)) {
  5070. $missing .= ", file_jar";
  5071. }
  5072. if (!isset($application_xml->file_class)) {
  5073. $missing .= ", file_class";
  5074. }
  5075. if (!isset($application_xml->width)) {
  5076. $missing .= ", width";
  5077. }
  5078. if (!isset($application_xml->height)) {
  5079. $missing .= ", height";
  5080. }
  5081. if (!isset($application_xml->evaluate)) {
  5082. $missing .= ", evaluate";
  5083. }
  5084. if (strlen($missing) > 2) {
  5085. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5086. return;
  5087. }
  5088. }
  5089. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5090. $typec = strtolower($application_xml->type);
  5091. require_once 'ilm_handlers/' . $typec . '.php';
  5092. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5093. } // static function import_ilm($itemid)
  5094. /// Function for list iLM defaults
  5095. // @return string Return an string with a table of iLM
  5096. static function list_ilm () {
  5097. global $DB, $OUTPUT;
  5098. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5099. $str = '';
  5100. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5101. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5102. if ($iassign_ilm) {
  5103. foreach ($iassign_ilm as $ilm) {
  5104. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5105. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5106. $str .= '<tr><td>';
  5107. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5108. $str .= '<tr>';
  5109. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5110. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5111. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5112. $str .= '</tr>';
  5113. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5114. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5115. $str .= '</table>';
  5116. $str .= '</td></tr>';
  5117. }
  5118. }
  5119. $str .= '</table>';
  5120. return $str;
  5121. }
  5122. /// Function for download and install an upgrade of an iLM
  5123. // @param int $ilm_id Id of iLM
  5124. static function upgrade_ilm ($ilm_id) {
  5125. global $DB, $CFG, $USER;
  5126. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5127. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5128. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5129. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5130. if (!$result)
  5131. print_error('error_upgrade_ilm', 'iassign');
  5132. else {
  5133. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5134. $extension = explode(".", $zip_filename);
  5135. if ($extension[count($extension) - 1] != 'ipz') {
  5136. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5137. die;
  5138. }
  5139. $zip = new zip_packer();
  5140. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5141. $contextuser = context_user::instance($USER->id);
  5142. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5143. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5144. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5145. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5146. if (file_exists($zip_filename))
  5147. unlink($zip_filename);
  5148. if (empty($file_jar)) {
  5149. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5150. print_error($msg_error);
  5151. //xx print_error('error_add_ilm', 'iassign');
  5152. }
  5153. else {
  5154. $newentry = new stdClass();
  5155. $newentry->name = (String) $application_xml->name;
  5156. $newentry->version = (String) $application_xml->version;
  5157. $newentry->url = (String) $application_xml->url;
  5158. $newentry->description = $description_str;
  5159. $newentry->extension = strtolower((String) $application_xml->extension);
  5160. $newentry->file_jar = implode(",", $file_jar);
  5161. $newentry->file_class = (String) $application_xml->file_class;
  5162. $newentry->width = (String) $application_xml->width;
  5163. $newentry->height = (String) $application_xml->height;
  5164. $newentry->enable = 0;
  5165. $newentry->timemodified = time();
  5166. $newentry->author = $USER->id;
  5167. $newentry->timecreated = time();
  5168. $newentry->evaluate = (String) $application_xml->evaluate;
  5169. $newentry->parent = $ilm_id;
  5170. }
  5171. }
  5172. return $iassign_ilm->id;
  5173. } // static function upgrade_ilm($ilm_id)
  5174. //MOOC2014 -- inicio
  5175. //TODO: REVIEW
  5176. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5177. // static function move_iassign($ilm_id)
  5178. //MOOC2014 -- final
  5179. /// Function for list iLM versions with all informations
  5180. // @return string Return an string with a table of iLM
  5181. static function view_ilm ($ilmid, $from) {
  5182. global $DB;
  5183. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5184. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5185. $typec = strtolower($iassign_ilm->type);
  5186. require_once 'ilm_handlers/' . $typec . '.php';
  5187. $retorno = $typec::view_ilm($ilmid, $from);
  5188. return $retorno;
  5189. }
  5190. /// Function for get form variables for add, edit, or copy iLM params
  5191. // @param int $ilm_param_id Id of iLM param
  5192. // @param string $action String with the action
  5193. // @return object Return an object with forms variables
  5194. static function add_edit_copy_param ($ilm_param_id, $action) {
  5195. global $DB;
  5196. require_once('params_form.php');
  5197. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5198. $param = new stdClass();
  5199. $param->action = $action;
  5200. $param->ilm_param_id = $ilm_param_id;
  5201. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5202. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5203. $type = $iassign_ilm_config->param_type;
  5204. if ($action == 'add') {
  5205. $param->title = get_string('add_ilm', 'iassign');
  5206. $param->iassign_ilmid = $ilm_param_id;
  5207. $param->param_name = "";
  5208. $param->param_value = "";
  5209. $param->description = "";
  5210. $param->visible = 1;
  5211. }
  5212. elseif ($action == 'edit') {
  5213. if ($iassign_ilm_config) {
  5214. $param->title = get_string('edit_ilm', 'iassign');
  5215. $param->id = $iassign_ilm_config->id;
  5216. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5217. $param->param_type = $type; //MOOC2014
  5218. $param->param_name = $iassign_ilm_config->param_name;
  5219. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5220. $param->param_value = $iassign_ilm_config->param_value;
  5221. else //MOOC2014
  5222. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5223. $param->param_value = $iassign_ilm_config->param_value;
  5224. $param->description = $iassign_ilm_config->description;
  5225. $param->visible = $iassign_ilm_config->visible;
  5226. }
  5227. }
  5228. elseif ($action == 'copy') {
  5229. if ($iassign_ilm_config) {
  5230. $param->title = get_string('copy_ilm', 'iassign');
  5231. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5232. $param->param_type = $type; //MOOC2014
  5233. $param->param_name = $iassign_ilm_config->param_name;
  5234. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5235. $param->param_value = $iassign_ilm_config->param_value;
  5236. else //MOOC2014
  5237. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5238. $param->description = $iassign_ilm_config->description;
  5239. $param->visible = $iassign_ilm_config->visible;
  5240. }
  5241. }
  5242. return $param;
  5243. } // static function add_edit_copy_param($ilm_param_id, $action)
  5244. /// Function for change visibility of iLM param
  5245. // @param int $ilm_param_id Id of iLM param
  5246. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5247. static function visible_param ($ilm_param_id, $status) {
  5248. global $DB, $CFG;
  5249. if ($status == 0)
  5250. $visible = 1;
  5251. else
  5252. $visible = 0;
  5253. $newentry = new stdClass();
  5254. $newentry->id = $ilm_param_id;
  5255. $newentry->visible = $visible;
  5256. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5257. error(get_string('error_edit_param', 'iassign'));
  5258. }
  5259. /// Function for save in database an new iLM param
  5260. // @param object $param An object with iLM params
  5261. static function add_param ($param) {
  5262. global $DB;
  5263. $newentry = new stdClass();
  5264. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5265. //MOOC2014 $newentry->param_name = $param->param_name;
  5266. $newentry->param_type = $param->param_type; //MOOC2014
  5267. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5268. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5269. $newentry->param_value = $param->param_value;
  5270. else //MOOC2014
  5271. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5272. $newentry->description = $param->description;
  5273. $newentry->visible = $param->visible;
  5274. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5275. if (!$newentry->id) {
  5276. print_error('error_add_param', 'iassign');
  5277. }
  5278. }
  5279. /// Function for save in database a iLM param edit
  5280. // @param object $param An object with iLM params
  5281. static function edit_param ($param) {
  5282. global $DB;
  5283. $updentry = new stdClass();
  5284. $updentry->id = $param->id;
  5285. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5286. $updentry->param_type = $param->param_type; //MOOC2014
  5287. // $updentry->param_name = $param->param_name;
  5288. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5289. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5290. $updentry->param_value = $param->param_value;
  5291. else //MOOC2014
  5292. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5293. $updentry->description = $param->description;
  5294. $updentry->visible = $param->visible;
  5295. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5296. error(get_string('error_edit_param', 'iassign'));
  5297. }
  5298. }
  5299. /// Function for save in database a iLM param copy
  5300. // @param object $param An object with iLM params
  5301. static function copy_param ($param) {
  5302. global $DB;
  5303. $newentry = new stdClass();
  5304. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5305. //$newentry->param_name = $param->param_name;
  5306. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5307. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5308. $newentry->param_value = $param->param_value;
  5309. else //MOOC2014
  5310. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5311. $newentry->description = $param->description;
  5312. $newentry->visible = $param->visible;
  5313. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5314. if (!$newentry->id) {
  5315. print_error('error_add_param', 'iassign');
  5316. }
  5317. }
  5318. /// Function for delete iLM param of database
  5319. // @param int $param_id Id of iLM param
  5320. static function delete_param ($param_id) {
  5321. global $DB;
  5322. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5323. print_error('error_delete_param', 'iassign');
  5324. }
  5325. }
  5326. } // class ilm_settings
  5327. /// Class for manage iLM files (editor).
  5328. class ilm_manager {
  5329. var $id; // course id
  5330. var $url;
  5331. var $from;
  5332. /// Constructor for the base ilm_manager class
  5333. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5334. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5335. function __construct ($id, $url, $from) {
  5336. $this->id = $id; // course id
  5337. $this->url = $url;
  5338. $this->from = $from;
  5339. }
  5340. /// Function to get iAssign content file in Moodle data (exercise)
  5341. // @calledby x function preview_ilm($iassign_ilm) :
  5342. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5343. function get_file_ilm () {
  5344. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5345. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5346. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5347. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5348. $md_file = $fs->get_file_by_id($fileid);
  5349. $ilm_content_file = $md_file->get_content();
  5350. return $ilm_content_file;
  5351. }
  5352. /// Function for creating a new file from the iLM online editor
  5353. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5354. function ilm_editor_new () {
  5355. global $CFG, $DB, $OUTPUT, $PAGE;
  5356. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5357. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5358. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5359. $context = context_course::instance($this->id);
  5360. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5361. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5362. if (!$iassign) {
  5363. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5364. die();
  5365. }
  5366. $temp = explode(",", $iassign->extension);
  5367. $extension = $temp[0]; // default extension for this iLM
  5368. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5369. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5370. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5371. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5372. if ($stringArchiveContent != NULL) {
  5373. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5374. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5375. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5376. $filename = optional_param('filename', NULL, PARAM_RAW);
  5377. //Leo $filename = iassign_utils::format_filename($filename); //
  5378. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5379. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5380. //2019/02 $arrayfilename = explode(".", $filename);
  5381. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5382. //2019/02 $count_dots = count($arrayfilename);
  5383. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5384. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5385. //2019/02 if ($last_name != $extension)
  5386. //2019/02 $filename = $filename . '.' . $extension;
  5387. //2019/02 }
  5388. //2019/02 else { // no extension...
  5389. //2019/02 $filename = $filename . '.' . $extension;
  5390. //2019/02 }
  5391. // Store the name of recent created file
  5392. $_SESSION['file_name'] = $filename;
  5393. //$this->write_file_iassign($string, $filename);
  5394. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5395. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5396. die();
  5397. }
  5398. else { // if ($stringArchiveContent != NULL)
  5399. // iLM On-line editor
  5400. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5401. $str_get_iLM = "window.frames.iLM";
  5402. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5403. }
  5404. else { // otherwise it is JAR named 'iLM'
  5405. $str_get_iLM = "document.iLM";
  5406. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5407. }
  5408. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5409. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5410. $files_array = '';
  5411. foreach ($files as $value) {
  5412. if ($value->get_filename() != ".")
  5413. $files_array .= "'" . $value->get_filename() . "',";
  5414. }
  5415. $files_array .= "''";
  5416. $file = null;
  5417. $ia_content = "";
  5418. $filename = "";
  5419. $error_files_exists = get_string('error_file_exists', 'iassign');
  5420. $output = "<script type='text/javascript'>
  5421. //<![CDATA[
  5422. //D alert('locallib.php: ilm_editor_new');
  5423. function submit_iLM_Answer () {
  5424. var docFormOnLineEditor = document.formEnvio;
  5425. var resposta_exerc = new Array(3);
  5426. var valor_resposta = new Array(3);
  5427. var sessao = new Array(3);
  5428. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5429. resposta_exerc[0] = doc_iLM.getAnswer();
  5430. valor_resposta[0] = doc_iLM.getEvaluation();
  5431. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5432. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5433. var files = new Array(" . $files_array . ");
  5434. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5435. if (docFormOnLineEditor.filename.value=='') {
  5436. // ERROR: the file name is empty
  5437. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5438. return false;
  5439. }
  5440. // }
  5441. for (i=0; i<files.length; i++) {
  5442. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5443. alert('" . $error_files_exists . "');
  5444. return false;
  5445. }
  5446. }
  5447. docFormOnLineEditor.submit();
  5448. return true;
  5449. }
  5450. //]]>
  5451. </script>\n";
  5452. $output .= "
  5453. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5454. $output .= $OUTPUT->box_start();
  5455. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5456. $output .= "
  5457. <table width='100%' cellpadding='20'>
  5458. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5459. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5460. </tr>
  5461. </table>\n";
  5462. $output .= $OUTPUT->box_end();
  5463. $output .= "<center>\n";
  5464. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5465. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5466. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5467. $output .= $output_ilm;
  5468. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5469. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5470. </center>
  5471. </form>\n";
  5472. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5473. $PAGE->navbar->add($title);
  5474. $PAGE->set_title($title);
  5475. $PAGE->set_heading($title); // insert title above the navigation bar
  5476. print $OUTPUT->header();
  5477. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5478. print $output;
  5479. print $OUTPUT->footer();
  5480. }
  5481. die();
  5482. } // function ilm_editor_new()
  5483. /// Function for editing an file in online editor
  5484. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5485. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5486. global $CFG, $DB, $OUTPUT, $PAGE;
  5487. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5488. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5489. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5490. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5491. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5492. // If iLM is not registered, error!
  5493. if (!$iassign) {
  5494. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5495. die;
  5496. }
  5497. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5498. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5499. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5500. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5501. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5502. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5503. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5504. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5505. if ($stringArchiveContent != NULL) {
  5506. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5507. die();
  5508. } else { // if ($stringArchiveContent != NULL)
  5509. $end_file = '';
  5510. if ($content_file) {
  5511. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5512. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5513. }
  5514. $temp = explode(",", $iassign->extension);
  5515. $extension = $temp[0]; // default extension for this iLM
  5516. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5517. $str_get_iLM = "window.frames.iLM";
  5518. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5519. } else { // otherwise it is JAR named 'iLM'
  5520. $str_get_iLM = "document.iLM";
  5521. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5522. }
  5523. $output = "<script type='text/javascript'>
  5524. //<![CDATA[
  5525. function submit_iLM_Answer () {
  5526. var docFormEditor = document.formEnvio;
  5527. var activityAnswer; // to get activity answer (text)
  5528. var activityValue; // to get activity answer value (float)
  5529. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5530. //activityAnswer = doc_iLM.getAnswer();
  5531. //activityValue = doc_iLM.getEvaluation();
  5532. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5533. activityValue = " . $str_get_iLM . ".getEvaluation();
  5534. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5535. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5536. docFormEditor.submit();
  5537. return true;
  5538. }
  5539. //]]>
  5540. </script>\n";
  5541. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5542. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5543. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5544. // return true;
  5545. // }
  5546. $output .= "
  5547. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5548. $output .= $OUTPUT->box_start();
  5549. $output .= "
  5550. <table width='100%' cellpadding='20'>
  5551. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5552. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5553. <input type='hidden' name='filename' value='$filename'/></td>
  5554. <td>
  5555. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5556. </tr>
  5557. </table>\n";
  5558. $output .= $OUTPUT->box_end();
  5559. $output .= " <center>\n";
  5560. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5561. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5562. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5563. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5564. </center>
  5565. </form>\n";
  5566. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5567. $PAGE->navbar->add($title);
  5568. $PAGE->set_title($title);
  5569. $PAGE->set_heading($title); // insert title above the navigation bar
  5570. print $OUTPUT->header();
  5571. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5572. print $output;
  5573. print $OUTPUT->footer();
  5574. } // else if ($stringArchiveContent != NULL)
  5575. die();
  5576. } // function ilm_editor_update()
  5577. /// Function for write iAssign file in Moodle data (exercise)
  5578. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5579. // @param string $stringArchiveContent Content of iassign file
  5580. // @param string $filename Filename of iassign file
  5581. function write_file_iassign ($stringArchiveContent, $filename) {
  5582. global $USER;
  5583. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5584. $context = context_course::instance($this->id);
  5585. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5586. $dirid = $this->get_dir_ilm('dirid');
  5587. $dir = $fs->get_file_by_id($dirid);
  5588. $fileinfo = array('contextid' => $context->id, // ID of course
  5589. 'component' => 'mod_iassign', // usually = table name
  5590. 'filearea' => 'activity', // usually = table name
  5591. 'itemid' => 0, // usually = ID of row in table
  5592. 'filepath' => '/', // any path beginning and ending whith '/'
  5593. 'userid' => $USER->id,
  5594. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5595. 'filename' => $filename); // any filename
  5596. // Create file containing text. '$stringArchiveContent'
  5597. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5598. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5599. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5600. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5601. // 'Activité interactive enregistrée avec succès sous le nom:';
  5602. // 'Atividade interativa gravada com sucesso sob o nome:'
  5603. $output = "
  5604. <script type='text/javascript'>
  5605. //<![CDATA[
  5606. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5607. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5608. //]]>
  5609. </script>";
  5610. print $output;
  5611. die();
  5612. }
  5613. /// Function for write iAssign file in Moodle data (exercise)
  5614. // @param string $stringArchiveContent Content of iassign file
  5615. // @param string $filename Filename of iassign file
  5616. // @param int $itemid Itemid of iassign file
  5617. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5618. global $OUTPUT, $USER;
  5619. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5620. $context = context_course::instance($this->id);
  5621. $dirid = $this->get_dir_ilm('dirid');
  5622. if ($stringArchiveContent != (-1)) {
  5623. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5624. $file = $fs->get_file_by_id($fileid);
  5625. if (!$file) {
  5626. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5627. die;
  5628. }
  5629. $fileinfo = array('contextid' => $context->id, // ID of context
  5630. 'component' => 'mod_iassign', // usually = table name
  5631. 'filearea' => 'activity', // usually = table name
  5632. 'itemid' => 0, // usually = ID of row in table
  5633. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5634. 'userid' => $USER->id,
  5635. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5636. 'license' => 'allrightsreserved', // allrightsreserved
  5637. 'timecreated' => $file->get_timecreated(),
  5638. 'filename' => $file->get_filename()); // any filename
  5639. $file->delete();
  5640. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5641. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5642. }
  5643. $output = "<script type='text/javascript'>
  5644. //<![CDATA[
  5645. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5646. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5647. //]]>
  5648. </script>";
  5649. print $output;
  5650. die();
  5651. }
  5652. /// Function for create an tag for iAssign filter
  5653. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5654. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5655. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5656. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5657. // @param int $fileid Id of file
  5658. // @return string Return an string with an tag of iassign filter
  5659. function tag_ilm ($fileid) {
  5660. global $DB;
  5661. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5662. $width = '600';
  5663. $height = '400';
  5664. $file = $fs->get_file_by_id($fileid);
  5665. $filetype = explode(".", $file->get_filename());
  5666. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5667. foreach ($iassign_ilm as $value) {
  5668. $extensions = explode(",", $value->extension);
  5669. if (in_array($filetype[1], $extensions)) {
  5670. $width = $value->width;
  5671. $height = $value->height;
  5672. }
  5673. }
  5674. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5675. }
  5676. /// Function for delete iAssign file in Moodle data (exercise)
  5677. function delete_file_ilm () {
  5678. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5679. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5680. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5681. $file = $fs->get_file_by_id($fileid);
  5682. if ($file)
  5683. $file->delete();
  5684. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5685. die();
  5686. }
  5687. /// Function for delete selected iAssign file in Moodle data (exercise)
  5688. function delete_selected_ilm () {
  5689. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5690. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5691. $context = context_course::instance($this->id);
  5692. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5693. $dirid = $this->get_dir_ilm('dirid');
  5694. foreach ($files_id as $file_id) {
  5695. $file = $fs->get_file_by_id($file_id);
  5696. if ($file) {
  5697. if (!$file->is_directory())
  5698. $file->delete();
  5699. else {
  5700. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5701. foreach ($files_delete as $value)
  5702. $value->delete();
  5703. $file->delete();
  5704. }
  5705. }
  5706. }
  5707. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5708. die();
  5709. }
  5710. /// Function for duplicate iAssign file from "online" edition
  5711. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5712. function duplicate_file_ilm () {
  5713. global $USER, $COURSE;
  5714. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5715. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5716. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5717. $filename = optional_param('filename', NULL, PARAM_RAW);
  5718. $file = $fs->get_file_by_id($fileid);
  5719. $context = context_course::instance($this->id);
  5720. $fileinfo = array(
  5721. 'contextid' => $context->id, // ID of context
  5722. 'component' => 'mod_iassign', // usually = table name
  5723. 'filearea' => 'activity', // usually = table name
  5724. 'itemid' => 0, // usually = ID of row in table
  5725. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5726. 'userid' => $USER->id,
  5727. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5728. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5729. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5730. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5731. die();
  5732. }
  5733. /// Function for rename iAssign file
  5734. function rename_file_ilm () {
  5735. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5736. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5737. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5738. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5739. $file = $fs->get_file_by_id($fileid);
  5740. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5741. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5742. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5743. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5744. die();
  5745. }
  5746. /// Function for get iassign file for iassign form
  5747. function add_ilm () {
  5748. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5749. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5750. $output = "
  5751. <script type='text/javascript'>
  5752. //<![CDATA[
  5753. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5754. iassign_file_link.innerHTML = '$filename';
  5755. window.opener.document.forms['mform1'].file.value='$fileid';
  5756. window.opener.document.forms['mform1'].filename.value='$filename';
  5757. window.close();
  5758. //]]>
  5759. </script>";
  5760. print $output;
  5761. die();
  5762. }
  5763. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5764. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5765. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5766. function preview_ilm ($courseid, $iassign_ilm) {
  5767. global $OUTPUT, $CFG, $USER;
  5768. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5769. $title = get_string('modulename', 'iassign'); // iAssign
  5770. print $OUTPUT->header();
  5771. print $OUTPUT->box_start();
  5772. $javascript = "
  5773. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5774. <script type='text/javascript'>
  5775. //<![CDATA[
  5776. function submit_close () {
  5777. window.opener.location.reload();
  5778. window.close();
  5779. }
  5780. //]]>
  5781. </script>\n";
  5782. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5783. // to the complete "applet" tag
  5784. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5785. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5786. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5787. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5788. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5789. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5790. if ($ilm_name != "ivprog") {
  5791. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5792. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5793. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5794. } else {
  5795. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5796. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5797. $timecreated = time();
  5798. $token = md5($timecreated);
  5799. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5800. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5801. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5802. $tag_filter_filtered = ilm_settings::build_ilm_tags($iassign_ilm->id, array("type" => "view", "notSEND" => "true", "Proposition" => $url_file)); // buil iLM tag (JAR or HTML5)
  5803. }
  5804. $html = "
  5805. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5806. <table border='1'>
  5807. <tr><td>
  5808. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5809. <!-- iLM calls : end -->
  5810. </td></tr>
  5811. </table>
  5812. <table>
  5813. <tr>
  5814. <td align='center'>
  5815. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5816. </td></tr>
  5817. </table>
  5818. </form>\n";
  5819. print $javascript . $html;
  5820. print $OUTPUT->box_end();
  5821. //NAO echo format_string($html); // Moodle 3.X
  5822. die();
  5823. } // function preview_ilm($courseid, $iassign_ilm)
  5824. //r_ function preview_ilm ($iassign_ilm)
  5825. //r_ /// Function for preview iassign file from iassign filter.
  5826. //r_ function preview_ilm() {
  5827. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5828. //r_ $tag_filter = $this->tag_ilm($fileid);
  5829. //r_ $javascript = "<script type='text/javascript'>
  5830. //r_ //<![CDATA[
  5831. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5832. //r_ //]]>
  5833. //r_ </script>";
  5834. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5835. //r_ <table border='1'><tr><td>$tag_filter</td></tr></table><table><tr><td align='center'><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();'/></td></tr>
  5836. //r_ </table></form></body></html>";
  5837. //r_ echo $javascript . format_text($html);
  5838. //r_ die;
  5839. //r_ }
  5840. /// Function for export an package (zip) of iassign files
  5841. function export_files_ilm () {
  5842. global $CFG;
  5843. $context = context_course::instance($this->id);
  5844. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5845. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5846. $zip = new zip_archive();
  5847. $zip->open($zip_filename);
  5848. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5849. foreach ($files_id as $file_id) {
  5850. $file = $fs->get_file_by_id($file_id);
  5851. if (!$file->is_directory())
  5852. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5853. else {
  5854. $zip->add_directory($file->get_filepath());
  5855. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5856. foreach ($files_zip as $value) {
  5857. if (!$value->is_directory())
  5858. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5859. else
  5860. $zip->add_directory($value->get_filepath());
  5861. }
  5862. }
  5863. }
  5864. $zip->close();
  5865. header("Pragma: public");
  5866. header("Expires: 0");
  5867. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5868. header("Cache-Control: private", false);
  5869. header("Content-Type: application/zip");
  5870. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5871. header("Content-Transfer-Encoding: binary");
  5872. header("Content-Length: " . @filesize($zip_filename));
  5873. set_time_limit(0);
  5874. @readfile("$zip_filename") || die("File not found.");
  5875. unlink($zip_filename);
  5876. exit;
  5877. }
  5878. /// Function of execute a command in button editor tinymce
  5879. // @param int $fileid Id of file
  5880. function tinymce_ilm ($fileid) {
  5881. $tag_filter = $this->tag_ilm($fileid);
  5882. $output = "<script type='text/javascript'>
  5883. //<![CDATA[
  5884. var tag_filter = '$tag_filter';
  5885. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5886. // all right, insert it
  5887. } else {
  5888. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5889. }
  5890. // window.close();
  5891. //]]>
  5892. </script>\n";
  5893. print $output;
  5894. die();
  5895. }
  5896. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5897. /// Function to add content to the Editor Window
  5898. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5899. // @param int $fileid Id of file
  5900. function editor_ilm ($fileid, $editor) {
  5901. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5902. $output1 = "<script type='text/javascript'>
  5903. //<![CDATA[
  5904. var tag_filter = '$tag_filter';\n";
  5905. if ($editor == 'atto') {
  5906. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5907. } elseif ($editor == 'tinyMCE') {
  5908. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5909. } else
  5910. $output2 = "";
  5911. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5912. window.close();
  5913. //]]>
  5914. </script>\n";
  5915. //D var_dump($output);
  5916. print $output1 . $output2 . $output3;
  5917. die();
  5918. }
  5919. /// Function to add content to the Atto Editor Window
  5920. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5921. // @param int $fileid Id of file
  5922. function atto_ilm ($fileid) {
  5923. global $CFG, $DB;
  5924. $tag_filter = $this->tag_ilm($fileid);
  5925. $output = "<script type='text/javascript'>
  5926. //<![CDATA[
  5927. var tag_filter = '$tag_filter';
  5928. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5929. // all right, insert iLM tag to this editor
  5930. } else {
  5931. // error trying to insert
  5932. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5933. }
  5934. //window.close();
  5935. //]]>
  5936. </script>\n";
  5937. print $output;
  5938. die();
  5939. }
  5940. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5941. // @param string $key Key for return information
  5942. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5943. function get_dir_ilm ($key) {
  5944. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5945. $context = context_course::instance($this->id);
  5946. $dirid = optional_param('dirid', 0, PARAM_INT);
  5947. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5948. if ($dirid == 0) {
  5949. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5950. $dirid = $dir->get_id();
  5951. }
  5952. else {
  5953. $dir = $fs->get_file_by_id($dirid);
  5954. $dir_base = $dir->get_filepath();
  5955. }
  5956. $dir_parent = $dir->get_parent_directory();
  5957. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5958. return $data[$key];
  5959. }
  5960. /// Function for create an new dir
  5961. function new_dir_ilm () {
  5962. global $USER;
  5963. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5964. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5965. $dir_base = $this->get_dir_ilm('dir_base');
  5966. $context = context_course::instance($this->id);
  5967. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5968. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5969. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5970. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5971. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5972. }
  5973. /// Function for delete an dir
  5974. function delete_dir_ilm () { //
  5975. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5976. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5977. $context = context_course::instance($this->id);
  5978. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5979. $dir_parent = $this->get_dir_ilm('dir_parent');
  5980. if ($dir) {
  5981. if ($dir->is_directory()) {
  5982. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5983. foreach ($files_delete as $value)
  5984. $value->delete();
  5985. $dir->delete();
  5986. }
  5987. }
  5988. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5989. die();
  5990. }
  5991. /// Function for rename an dir
  5992. function rename_dir_ilm () {
  5993. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5994. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5995. $context = context_course::instance($this->id);
  5996. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5997. $dir_parent = $this->get_dir_ilm('dir_parent');
  5998. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5999. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6000. if ($dir->is_directory()) {
  6001. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6002. foreach ($files_rename_path as $value)
  6003. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6004. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6005. }
  6006. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6007. die();
  6008. }
  6009. /// Function for move an dir and your content for other dir
  6010. function selected_move_ilm () {
  6011. global $PAGE, $OUTPUT, $CFG;
  6012. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6013. $context = context_course::instance($this->id);
  6014. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6015. $dirid = $this->get_dir_ilm('dirid');
  6016. $dir_base = $this->get_dir_ilm('dir_base');
  6017. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6018. $code_javascript_ilm = "
  6019. <script type='text/javascript'>
  6020. //<![CDATA[
  6021. function getRadiobutton () {
  6022. var radioButtons = document.getElementsByTagName('input');
  6023. var param = '';
  6024. for (var counter=0; counter < radioButtons.length; counter++) {
  6025. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6026. param = radioButtons[counter].value;
  6027. }
  6028. return param;
  6029. }
  6030. function move_selected_ilm () {
  6031. var msgAnswer;
  6032. if (getRadiobutton() != '') {
  6033. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6034. if (msgAnswer)
  6035. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6036. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6037. }
  6038. else
  6039. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6040. }
  6041. function cancel_selected_ilm () {
  6042. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6043. }
  6044. //]]>
  6045. </script>\n";
  6046. $title = get_string('move_files', 'iassign');
  6047. $PAGE->set_title($title);
  6048. $PAGE->set_pagelayout('base');
  6049. print $OUTPUT->header();
  6050. print $OUTPUT->heading($title);
  6051. $dir_paths = array();
  6052. print $OUTPUT->box_start();
  6053. print "<center>";
  6054. foreach ($files_id as $file_id) {
  6055. $file = $fs->get_file_by_id($file_id);
  6056. if ($file) {
  6057. if (!$file->is_directory())
  6058. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6059. else {
  6060. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6061. array_push($dir_paths, $file->get_filepath());
  6062. }
  6063. }
  6064. }
  6065. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6066. if ($dir_base != '/') {
  6067. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6068. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6069. }
  6070. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6071. foreach ($files_tree as $file) {
  6072. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6073. $is_parent = false;
  6074. foreach ($dir_paths as $dir) {
  6075. $path = explode("/", $dir);
  6076. array_pop($path);
  6077. $path[count($path) - 1] = '';
  6078. $path = implode("/", $path);
  6079. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6080. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6081. }
  6082. if ($is_parent == false) {
  6083. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6084. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6085. }
  6086. }
  6087. }
  6088. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6089. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6090. print "</center>";
  6091. print $OUTPUT->box_end();
  6092. print $OUTPUT->footer();
  6093. print $code_javascript_ilm;
  6094. die;
  6095. }
  6096. /// Function for move files for an dir
  6097. function move_files_ilm () {
  6098. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6099. $context = context_course::instance($this->id);
  6100. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6101. $dirid = $this->get_dir_ilm('dirid');
  6102. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6103. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6104. foreach ($files_id as $file_id) {
  6105. $file = $fs->get_file_by_id($file_id);
  6106. if ($file) {
  6107. if ($file->is_directory()) {
  6108. $pathname = explode("/", $file->get_filepath());
  6109. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6110. foreach ($files_move_path as $value) {
  6111. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6112. $value->rename($path_move, $value->get_filename());
  6113. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6114. }
  6115. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6116. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6117. $file->rename($path_move, $file->get_filename());
  6118. } else {
  6119. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6120. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6121. }
  6122. }
  6123. }
  6124. //die;
  6125. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6126. die();
  6127. } // function move_files_ilm()
  6128. /// Function for recover files in use on all activities of a course
  6129. function recover_files_ilm () {
  6130. global $DB, $USER;
  6131. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6132. $courseid = optional_param('id', NULL, PARAM_INT);
  6133. $dirid = $this->get_dir_ilm('dirid');
  6134. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6135. $contextfile = context_course::instance($this->id);
  6136. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6137. foreach ($iassigns as $iassign) {
  6138. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6139. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6140. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6141. $context = context_module::instance($cm->id);
  6142. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  6143. if ($files) {
  6144. foreach ($files as $value) {
  6145. $extension = explode(".", $value->get_filename());
  6146. if (!$value->is_directory()) {
  6147. $fileinfo = array('contextid' => $contextfile->id,
  6148. 'component' => 'mod_iassign',
  6149. 'filearea' => 'activity',
  6150. 'itemid' => 0,
  6151. 'filepath' => $this->get_dir_ilm('dir_base'),
  6152. 'userid' => $USER->id,
  6153. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6154. 'license' => 'allrightsreserved',
  6155. 'timecreated' => time(),
  6156. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6157. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6158. }
  6159. }
  6160. } // if ($files)
  6161. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6162. } // foreach ($iassigns as $iassign)
  6163. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6164. die();
  6165. } // function recover_files_ilm()
  6166. /// Auxiliary function the get all files in a given context
  6167. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6168. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6169. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6170. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6171. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6172. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6173. // (NAO s_iassign_statement.file = s_files.id)
  6174. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6175. $dir_base = $this->get_dir_ilm('dir_base');
  6176. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6177. $countf = 0;
  6178. $array_files_id = array(); // all files from this context
  6179. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6180. //$filename = $item_fc->get_filename();
  6181. //$filepath = $item_fc->get_filepath();
  6182. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6183. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6184. // $array_files_aux[] = $item_fc;
  6185. $itemid = $item_fc->get_id();
  6186. if (!in_array($itemid, $array_files_id)) {
  6187. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6188. if ($fileuserid == $userid)
  6189. $filesfrommine[] = $item_fc;
  6190. else
  6191. $filesfromothers[] = $item_fc;
  6192. $array_files_id[] = $itemid;
  6193. $countf++;
  6194. }
  6195. }
  6196. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6197. return $countf;
  6198. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6199. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6200. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6201. function get_all_ilm_files_by_fileid ($fileid) {
  6202. global $DB, $USER;
  6203. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6204. //TODO Criar coluna 'authorid'
  6205. $str_query = "SELECT * FROM {iassign_statement} " .
  6206. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6207. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6208. return $array_iassign_ilm;
  6209. }
  6210. //NN
  6211. //NN
  6212. // Build string with JavaScript code with function to edit/remove/double iLM files
  6213. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6214. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6215. global $CFG;
  6216. $error_files_exists = get_string('error_file_exists', 'iassign');
  6217. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6218. $code_javascript_ilm = "
  6219. <script type='text/javascript'>
  6220. //<![CDATA[
  6221. function preview_ilm (fileid, ilmid) { //JavaScript function
  6222. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6223. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6224. }
  6225. function update_ilm (ilmid, fileid) { //JavaScript function
  6226. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6227. }
  6228. function delete_ilm (ilmid, fileid) { //JavaScript function
  6229. var msgAnswer;
  6230. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6231. if (msgAnswer) {
  6232. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6233. }
  6234. }
  6235. function delete_selected_ilm () { //JavaScript function
  6236. var msgAnswer;
  6237. var param = getCheckbox();
  6238. if (param.join() != '') {
  6239. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6240. if (msgAnswer)
  6241. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6242. }
  6243. else
  6244. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6245. }
  6246. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6247. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6248. }
  6249. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6250. var filenamecopy;
  6251. var i;
  6252. var files = new Array(" . $files_array . ");
  6253. do {
  6254. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6255. } while (filenamecopy == '');
  6256. if (filenamecopy == null)
  6257. return false;\n
  6258. else {
  6259. for (i=0;i<files.length;i++) {
  6260. if (files[i]==filenamecopy) {
  6261. alert('" . $error_files_exists . "');
  6262. return false;\n
  6263. }
  6264. }\n" .
  6265. // @see: function 'duplicate_file_ilm()' above
  6266. "
  6267. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6268. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6269. } // else
  6270. }
  6271. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6272. var filenamecopy;
  6273. var i;
  6274. var files = new Array($files_array);
  6275. do {
  6276. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6277. } while (filenamecopy == '');
  6278. if (filenamecopy == null)
  6279. return false;
  6280. else {
  6281. for (i=0;i<files.length;i++) {
  6282. if (files[i]==filenamecopy) {
  6283. alert('" . $error_files_exists . "');
  6284. return false;
  6285. }
  6286. }
  6287. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid+'&filename='+filenamecopy;
  6288. }
  6289. }
  6290. function export_files_ilm () { //JavaScript function
  6291. var param = getCheckbox();
  6292. if (param.join() != '')
  6293. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6294. else
  6295. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6296. }
  6297. function select_all_ilm () { //JavaScript function
  6298. var checkBoxes = document.getElementsByTagName('input');
  6299. var selectAll = document.getElementById('select_all');
  6300. for (var counter=0; counter < checkBoxes.length; counter++) {
  6301. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6302. checkBoxes[counter].checked = selectAll.checked;
  6303. }
  6304. }
  6305. function getCheckbox () { //JavaScript function
  6306. var checkBoxes = document.getElementsByTagName('input');
  6307. var param = new Array();
  6308. for (var counter=0; counter < checkBoxes.length; counter++) {
  6309. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6310. param.push(checkBoxes[counter].value);
  6311. }
  6312. return param;
  6313. }
  6314. function new_dir_ilm () { //JavaScript function
  6315. var dirname = '';
  6316. var i;
  6317. var dirs = new Array(" . $dirs_array . ");
  6318. do {
  6319. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6320. } while (dirname == '');
  6321. if (dirname == null)
  6322. return false;\n
  6323. else {
  6324. for (i=0;i<dirs.length;i++) {
  6325. if (dirs[i]==dirname) {
  6326. alert('" . $error_dir_exists . "');
  6327. return false;\n
  6328. }
  6329. }
  6330. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6331. }
  6332. }
  6333. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6334. var msgAnswer;
  6335. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6336. if (msgAnswer) {
  6337. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6338. }
  6339. }
  6340. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6341. var dirnamecopy;
  6342. var i;
  6343. var dirs = new Array($dirs_array);
  6344. do {
  6345. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6346. } while (dirnamecopy == '');
  6347. if (dirnamecopy == null)
  6348. return false;\n
  6349. else {
  6350. for (i=0;i<dirs.length;i++) {
  6351. if (dirs[i]==dirnamecopy) {
  6352. alert('" . $error_dir_exists . "');
  6353. return false;\n
  6354. }
  6355. }
  6356. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6357. }
  6358. }
  6359. function move_selected_ilm (ilmid) { //JavaScript function
  6360. var param = getCheckbox();
  6361. if (param.join() != '')
  6362. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_move&ilmid='+ilmid+'&dirid=" . $dirid . "&files_id='+param.join();
  6363. else
  6364. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6365. }
  6366. function recover_files_ilm () { //JavaScript function
  6367. var msgAnswer;
  6368. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6369. if (msgAnswer) {
  6370. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6371. }
  6372. }
  6373. window.onload = function() { //JavaScript function
  6374. var xPosition = 0;
  6375. var yPosition = 0;
  6376. element=document.getElementById('new_file');
  6377. while(element) {
  6378. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6379. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6380. element = element.offsetParent;
  6381. }
  6382. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6383. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6384. location.hash = '#new_file';
  6385. };
  6386. //]]>
  6387. </script>\n"; // end of $code_javascript_ilm
  6388. return $code_javascript_ilm;
  6389. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6390. /// List iassign files from course directory
  6391. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6392. function view_files_ilm ($iassign_ilm_class, $extension) {
  6393. global $CFG, $DB, $USER, $OUTPUT;
  6394. $fs = get_file_storage();
  6395. $context = context_course::instance($this->id);
  6396. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6397. $dirid = $this->get_dir_ilm('dirid');
  6398. $dir_base = $this->get_dir_ilm('dir_base');
  6399. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6400. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6401. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6402. $files_array = '';
  6403. foreach ($files_course as $value) {
  6404. if (!$value->is_directory())
  6405. $files_array .= "'" . $value->get_filename() . "',";
  6406. }
  6407. $files_array .= "''";
  6408. $error_files_exists = get_string('error_file_exists', 'iassign');
  6409. $dirs_array = '';
  6410. foreach ($files_course as $value) {
  6411. if ($value->is_directory()) {
  6412. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6413. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6414. }
  6415. }
  6416. $dirs_array .= "''";
  6417. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6418. // TODO Rever o preview pois só deixar ver uma vez.
  6419. $code_javascript_ilm = "
  6420. <script type='text/javascript'>
  6421. //<![CDATA[
  6422. function preview_ilm (fileid, ilmid) {
  6423. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6424. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6425. }
  6426. function update_ilm (ilmid, fileid) {
  6427. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6428. }
  6429. function delete_ilm (ilmid, fileid) {
  6430. var msgAnswer;
  6431. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6432. if (msgAnswer) {
  6433. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6434. }
  6435. }
  6436. function delete_selected_ilm () {
  6437. var msgAnswer;
  6438. var param = getCheckbox();
  6439. if (param.join() != '') {
  6440. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6441. if (msgAnswer)
  6442. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6443. }
  6444. else
  6445. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6446. }
  6447. function add_ilm_iassign (ilmid, filename, fileid) {
  6448. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6449. }
  6450. function duplicate_ilm (ilmid, filename, fileid) {
  6451. var filenamecopy;
  6452. var i;
  6453. var files = new Array($files_array);
  6454. do {
  6455. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6456. } while (filenamecopy == '');
  6457. if (filenamecopy == null)
  6458. return false;\n
  6459. else {
  6460. for (i=0;i<files.length;i++) {
  6461. if (files[i]==filenamecopy) {
  6462. alert('$error_files_exists');
  6463. return false;\n
  6464. }
  6465. }\n" .
  6466. // @see: function 'duplicate_file_ilm()' above
  6467. "
  6468. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6469. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6470. } // else
  6471. }
  6472. function rename_ilm (ilmid, filename, fileid) {
  6473. var filenamecopy;
  6474. var i;
  6475. var files = new Array($files_array);
  6476. do {
  6477. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6478. } while (filenamecopy == '');
  6479. if (filenamecopy == null)
  6480. return false;
  6481. else {
  6482. for (i=0;i<files.length;i++) {
  6483. if (files[i]==filenamecopy) {
  6484. alert('$error_files_exists');
  6485. return false;
  6486. }
  6487. }
  6488. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid+'&filename='+filenamecopy;
  6489. }
  6490. }
  6491. function export_files_ilm () {
  6492. var param = getCheckbox();
  6493. if (param.join() != '')
  6494. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6495. else
  6496. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6497. }
  6498. function select_all_ilm () {
  6499. var checkBoxes = document.getElementsByTagName('input');
  6500. var selectAll = document.getElementById('select_all');
  6501. for (var counter=0; counter < checkBoxes.length; counter++) {
  6502. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6503. checkBoxes[counter].checked = selectAll.checked;
  6504. }
  6505. }
  6506. function getCheckbox () {
  6507. var checkBoxes = document.getElementsByTagName('input');
  6508. var param = new Array();
  6509. for (var counter=0; counter < checkBoxes.length; counter++) {
  6510. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6511. param.push(checkBoxes[counter].value);
  6512. }
  6513. return param;
  6514. }
  6515. function new_dir_ilm () {
  6516. var dirname = '';
  6517. var i;
  6518. var dirs = new Array($dirs_array);
  6519. do {
  6520. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6521. } while (dirname == '');
  6522. if (dirname == null)
  6523. return false;\n
  6524. else {
  6525. for (i=0;i<dirs.length;i++) {
  6526. if (dirs[i]==dirname) {
  6527. alert('$error_dir_exists');
  6528. return false;\n
  6529. }
  6530. }
  6531. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6532. }
  6533. }
  6534. function delete_dir_ilm (ilmid, dirid) {
  6535. var msgAnswer;
  6536. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6537. if (msgAnswer) {
  6538. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6539. }
  6540. }
  6541. function rename_dir_ilm (ilmid, dirname, dirid) {
  6542. var dirnamecopy;
  6543. var i;
  6544. var dirs = new Array($dirs_array);
  6545. do {
  6546. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6547. } while (dirnamecopy == '');
  6548. if (dirnamecopy == null)
  6549. return false;\n
  6550. else {
  6551. for (i=0;i<dirs.length;i++) {
  6552. if (dirs[i]==dirnamecopy) {
  6553. alert('$error_dir_exists');
  6554. return false;\n
  6555. }
  6556. }
  6557. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6558. }
  6559. }
  6560. function move_selected_ilm (ilmid) {
  6561. var param = getCheckbox();
  6562. if (param.join() != '')
  6563. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_move&ilmid='+ilmid+'&dirid=" . $dirid . "&files_id='+param.join();
  6564. else
  6565. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6566. }
  6567. function recover_files_ilm () {
  6568. var msgAnswer;
  6569. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6570. if (msgAnswer) {
  6571. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6572. }
  6573. }
  6574. window.onload = function() {
  6575. var xPosition = 0;
  6576. var yPosition = 0;
  6577. element=document.getElementById('new_file');
  6578. while(element) {
  6579. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6580. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6581. element = element.offsetParent;
  6582. }
  6583. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6584. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6585. location.hash = '#new_file';
  6586. };
  6587. //]]>
  6588. </script>\n";
  6589. $output = "";
  6590. $select_all = "";
  6591. $count_files = 0;
  6592. $extensions_allow = array();
  6593. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6594. foreach ($iassign_ilm as $item_iassign_ilm)
  6595. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6596. foreach ($files_course as $value) {
  6597. $filename = $value->get_filename();
  6598. $filepath = $value->get_filepath();
  6599. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6600. $pathname = $pathname[count($pathname) - 1];
  6601. $fileid = $value->get_id();
  6602. $tmp = explode(".", $filename);
  6603. if (count($tmp)>1) // avoid error if the file has no extension
  6604. $filetype = $tmp[1];
  6605. else // probably error...
  6606. $filetype = '';
  6607. $author = $value->get_author();
  6608. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6609. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6610. $extensions = explode(",", $extension);
  6611. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6612. $count_files ++;
  6613. // buscar fileid nas tabelas do iassign
  6614. $list_filein_use = "";
  6615. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6616. if ($iassign_statement_activity_list) {
  6617. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6618. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6619. }
  6620. }
  6621. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6622. if (!$iassign_ilm) {
  6623. $iassign_ilm = new stdClass();
  6624. $iassign_ilm->id = $ilmid;
  6625. }
  6626. // Do not use $var inside "..." - problem with some "unusual" operational system
  6627. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6628. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6629. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6630. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6631. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6632. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6633. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6634. $check_select = "";
  6635. $link_rename = "";
  6636. $link_delete = "";
  6637. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6638. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6639. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6640. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6641. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6642. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6643. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6644. if ($value->get_userid() == $USER->id) {
  6645. if ($iassign_statement_activity_list) {
  6646. $check_select = "";
  6647. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6648. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6649. $link_rename = "";
  6650. } else {
  6651. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6652. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6653. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6654. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6655. }
  6656. }
  6657. if (!in_array($filetype, $extensions_allow)) {
  6658. $link_edit = "";
  6659. $link_add_ilm_iassign = "";
  6660. $link_add_ilm_tinymce = "";
  6661. $link_add_ilm_atto = "";
  6662. $link_filter = "";
  6663. }
  6664. if ($value->is_directory()) {
  6665. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6666. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6667. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6668. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6669. <td><center>$author</center></td>
  6670. <td><center>$timecreated</center></td>
  6671. <td><center>$timemodified</center></td></tr>\n";
  6672. }
  6673. else if ($this->from == 'iassign') {
  6674. $new_id = "";
  6675. $new_class = "";
  6676. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6677. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6678. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6679. }
  6680. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6681. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6682. <td><center>$author</center></td>
  6683. <td><center>$timecreated</center></td>
  6684. <td><center>$timemodified</center></td></tr>\n";
  6685. }
  6686. else if ($this->from == 'block') {
  6687. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6688. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6689. <td><center>$author</center></td>
  6690. <td><center>$timecreated</center></td>
  6691. <td><center>$timemodified</center></td></tr>\n";
  6692. }
  6693. else if ($this->from == 'tinymce') {
  6694. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6695. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6696. <td><center>$author</center></td>
  6697. <td><center>$timecreated</center></td>
  6698. <td><center>$timemodified</center></td></tr>\n";
  6699. }
  6700. else if ($this->from == 'atto') {
  6701. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6702. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6703. <td><center>$author</center></td>
  6704. <td><center>$timecreated</center></td>
  6705. <td><center>$timemodified</center></td></tr>\n";
  6706. }
  6707. }
  6708. }
  6709. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6710. $dir_base = "";
  6711. $header = "";
  6712. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6713. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6714. foreach ($basename as $value) {
  6715. $dir_base .= $value . "/";
  6716. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6717. if ($dir_id) {
  6718. if ($value == "") {
  6719. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6720. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6721. } else {
  6722. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6723. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6724. }
  6725. }
  6726. } // foreach ($basename as $value)
  6727. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6728. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6729. $html .= "
  6730. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6731. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6732. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6733. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6734. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6735. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6736. </table>\n";
  6737. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6738. $html .= "<table width='100%'><tr>\n";
  6739. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6740. if ($count_files != 0) {
  6741. $html .= "&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;<input type='button' value='" . get_string('file_ilm_move', 'iassign') . "' onClick='move_selected_ilm(\"$iassign_ilm->id\");'/>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;\n";
  6742. $html .= "<input type='button' value='" . get_string('file_ilm_delete', 'iassign') . "' onClick='delete_selected_ilm(\"$iassign_ilm->id\");'>&nbsp;&nbsp;&nbsp;|&nbsp;&nbsp;&nbsp;\n";
  6743. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6744. }
  6745. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6746. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6747. $html .= "</form>\n";
  6748. print $code_javascript_ilm;
  6749. print $html;
  6750. } // function view_files_ilm($extension)
  6751. } // class ilm_manager
  6752. /// Class to insert of icons
  6753. class iassign_icons {
  6754. static function insert ($icon) {
  6755. global $CFG;
  6756. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6757. return $string;
  6758. }
  6759. }
  6760. /// Class with util functions for plugin manage
  6761. class iassign_utils {
  6762. /// Function to return the filename extension
  6763. // @param string The $filename as an string
  6764. // @return string Return an string (last group after '.')
  6765. static function filename_extension ($filename) {
  6766. if ($filename == null || $filename == '') {
  6767. return null;
  6768. }
  6769. $itens = explode('.', $filename);
  6770. $num = count($itens);
  6771. if ($num < 2) {
  6772. return null;
  6773. }
  6774. return $itens[$num - 1];
  6775. }
  6776. /// Use the PHP class/package ZipArchive to create a Zip file
  6777. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6778. // Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /var/www/html/.../lib/filestorage/zip_archive.php on line 224
  6779. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6780. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6781. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6782. $zip = new zip_archive(); //2
  6783. $res = $zip->open($full_path_zip_filename);
  6784. $total_vet = count($vet_student_filename);
  6785. for ($ii=0; $ii<$total_vet; $ii++) {
  6786. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6787. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6788. }
  6789. $ret = $zip->close();
  6790. iassign_utils::download_file($full_path_zip_filename);
  6791. $filenameZip = $zip->filename;
  6792. return array($ret, $zip);
  6793. }
  6794. static function download_file ($zip_filename) {
  6795. header("Pragma: public");
  6796. header("Expires: 0");
  6797. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6798. header("Cache-Control: private", false);
  6799. header("Content-Type: application/zip");
  6800. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6801. header("Content-Transfer-Encoding: binary");
  6802. header("Content-Length: " . @filesize($zip_filename));
  6803. set_time_limit(0);
  6804. @readfile("$zip_filename") || die("File not found.");
  6805. unlink($zip_filename);
  6806. }
  6807. /// Function for format filename remove special caracters
  6808. // @param string $text String for clean
  6809. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6810. // @return string Return an string in clean format
  6811. static function format_filename ($text) {
  6812. if ($text != '.') {
  6813. //D $text = htmlspecialchars(urldecode($text));
  6814. //D echo "locallib.php: format_filename: $text<br/>";
  6815. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6816. $text = json_decode($text)->{current_language()};
  6817. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6818. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6819. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6820. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6821. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6822. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6823. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6824. // E.g. text = "exerc_midpoint.course.geo"
  6825. // 0123456789012345678901234
  6826. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6827. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6828. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6829. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6830. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6831. //$ext = strrpos($text, ".");
  6832. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6833. //$text = str_replace($array1, $array2, $text);
  6834. }
  6835. return $text;
  6836. }
  6837. /// Function to filter characters to the file name to iLM content
  6838. // @param string $text String for clean
  6839. // @param string $ext String ot the extension of the iLM
  6840. // @return string Return an string in clean format
  6841. static function filter_filename_extension ($filename, $ext) {
  6842. if ($filename != '.') {
  6843. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6844. $arrTo = array("_","","","","","","","","","","","","");
  6845. $filename = str_replace($arrFrom, $arrTo, $filename);
  6846. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6847. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6848. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6849. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6850. $index_lastposition = strlen($filenameF);
  6851. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6852. $text = str_replace(".", "_", $text); // erase all other "."
  6853. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6854. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6855. }
  6856. else
  6857. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6858. return $filenameF;
  6859. }
  6860. /// Function for format pathname remove special caracters
  6861. // @param string $text String for clean
  6862. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6863. // @return string Return an string in clean format
  6864. static function format_pathname ($text, $is_lowercase = true) {
  6865. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6866. $array2 = array("a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C", "-", "_", "", "", "");
  6867. $text = str_replace($array1, $array2, $text);
  6868. if ($is_lowercase)
  6869. $text = strtolower($text);
  6870. return $text;
  6871. }
  6872. /// Function for format file name from iLM original name
  6873. // @param string $text String to build the file neam
  6874. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6875. // @return string Return an string in clean format
  6876. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6877. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6878. $array2 = array("a", "a", "a", "a", "a", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u", "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C", "-", "_", "", "", "");
  6879. $index_firstposition_blank = strpos($ilm_name, " ");
  6880. if ($index_firstposition_blank) { // truncate the name!
  6881. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6882. }
  6883. $index_firstposition_dots = strpos($ilm_name, ":");
  6884. if ($index_firstposition_dots) { // truncate the name!
  6885. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6886. }
  6887. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6888. if ($is_lowercase)
  6889. $namefiltered = strtolower($namefiltered);
  6890. return $namefiltered;
  6891. }
  6892. /// Function for insert version in the filename
  6893. // @param string $filename Name of file
  6894. // @return string Return the filename with version
  6895. static function version_filename ($filename) {
  6896. $array_filename = explode('.', $filename);
  6897. if (count($array_filename) > 1)
  6898. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6899. else
  6900. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6901. return $filename;
  6902. }
  6903. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6904. static function remove_code_message ($string) {
  6905. $array = explode("&lt;ia_uc&gt;", $string);
  6906. return $array[0];
  6907. }
  6908. }
  6909. // class iassign_utils
  6910. /// Class with language functions for plugin manage
  6911. class iassign_language {
  6912. /// Function for return text in language or get default language (en)
  6913. // @param string $lang Code of language
  6914. // @param string $description JSON text content all languages
  6915. // @return string Return an string in the language selected
  6916. static function get_description_lang ($lang, $descriptions) {
  6917. $description_lang = "";
  6918. $description = json_decode($descriptions);
  6919. if ($description == null) {
  6920. $description_lang = $descriptions;
  6921. }
  6922. else {
  6923. if (isset($description->{$lang}))
  6924. $description_lang = $description->{$lang};
  6925. else
  6926. if (isset($description->en)) //MOOC2014
  6927. $description_lang = $description->en;
  6928. else //MOOC2014
  6929. $description_lang = "en"; //MOOC2014
  6930. }
  6931. return $description_lang;
  6932. }
  6933. /// Function for return all language supported by iLM
  6934. // @param string $descriptions JSON text content all languages
  6935. // @return string Return as string with all languages
  6936. static function get_all_lang ($descriptions) {
  6937. $langs = "";
  6938. $description = json_decode($descriptions);
  6939. if ($description) {
  6940. foreach ($description as $key => $value) {
  6941. $langs .= $key . " ; ";
  6942. }
  6943. $langs = substr($langs, 0, strlen($langs) - 3);
  6944. }
  6945. return $langs;
  6946. }
  6947. /// Function for convert json in xml //MOOC2014
  6948. // @param string $json JSON text
  6949. // @return string Return as string with xml tags
  6950. static function json_to_xml ($json) {
  6951. $xml = "";
  6952. $json = json_decode($json);
  6953. foreach ($json as $key => $value) {
  6954. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6955. }
  6956. return $xml;
  6957. }
  6958. }
  6959. // class iassign_language
  6960. /// Class with log functions for plugin manage.
  6961. class iassign_log {
  6962. /// Function for insert log event
  6963. // @param string $action Code action of event
  6964. // @param string $information Text for describe action of event
  6965. // @param int $cmid Id of context module
  6966. // @param int $ilmid Id of iLM
  6967. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6968. global $COURSE, $CFG, $USER, $DB;
  6969. $newentry = new stdClass();
  6970. $newentry->time = time();
  6971. $newentry->userid = $USER->id;
  6972. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6973. $newentry->course = $COURSE->id;
  6974. $newentry->cmid = $cmid;
  6975. $newentry->ilmid = $ilmid;
  6976. $newentry->action = $action;
  6977. $newentry->info = $information;
  6978. $newentry->language = current_language();
  6979. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6980. if (ini_get("browscap") && function_exists('get_browse')) {
  6981. $browser = get_browse(null, true);
  6982. $newentry->javascript = $browser['javascript'];
  6983. $newentry->java = $browser['javaapplets'];
  6984. }
  6985. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6986. print_error('error_add_log', 'iassign');
  6987. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6988. } // class iassign_log