1
0

locallib.php 361 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764
  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. 'get_student_submission' => '$this->get_student_submission();',
  278. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  279. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  280. );
  281. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  282. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  283. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  284. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  285. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  286. }
  287. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  288. eval($action_iassign_limit[$this->action]);
  289. }
  290. else { // Student reaches this point
  291. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  292. // Arrive here with: "get_answer"; "view"
  293. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  294. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  295. }
  296. } // function action()
  297. /// This method prints the student submission to a specific exercise
  298. function get_student_submission () {
  299. global $DB;
  300. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  301. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  302. if (!$student || !$exercise) exit;
  303. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  304. if ($iassign_submission)
  305. print($iassign_submission->answer);
  306. die();
  307. }
  308. /// This method prints the teacher exercise
  309. function get_teacher_exercise () {
  310. global $DB, $COURSE;
  311. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  312. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  314. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  315. foreach ($files as $file) {
  316. if ($file->get_filename() != ".") {
  317. print($file->get_content());
  318. }
  319. }
  320. die();
  321. }
  322. /// This method receives the data from auto_eval event
  323. /// @see auto_evaluate()
  324. function post_auto_eval_result () {
  325. global $COURSE, $CFG, $USER, $DB;
  326. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  327. exit;
  328. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  329. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  330. $student = optional_param('student', -1, PARAM_INT);
  331. $grade = optional_param('grade', 0, PARAM_FLOAT);
  332. // 1: Recuperar a nota atual:
  333. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  334. // 2: Atualizar a tabela:
  335. $update_entry = new stdClass();
  336. $update_entry->id = $actual->id;
  337. $update_entry->previous_grade = $actual->grade;
  338. $update_entry->grade = $grade;
  339. // Update the iassign_submission
  340. $DB->update_record("iassign_submission", $update_entry);
  341. }
  342. /// This method runs activities auto evaluation in teacher area
  343. function auto_evaluate () {
  344. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  345. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  346. exit;
  347. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  348. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  349. // Get list of exercises in the instance:
  350. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  351. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  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 " .
  359. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  360. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  361. print $OUTPUT->header();
  362. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  363. print '<ul style="list-style-type: none; margin: 1em;">';
  364. foreach ($exercises_list as $exercise) {
  365. $matches = [];
  366. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  367. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  368. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  369. if ($matches[0][0]) {
  370. 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>';
  371. } else {
  372. 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>';
  373. }
  374. } else {
  375. if ($matches[0][0]) {
  376. 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>';
  377. } else {
  378. 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>';
  379. }
  380. }
  381. }
  382. print '</ul>
  383. <center>
  384. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  385. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  386. <div id="evaluate_message" style="color: red"></div>
  387. <div id="evaluate_alerts"></div>
  388. <div>
  389. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  390. <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>
  391. </div>
  392. </center>'; // close "
  393. print ' </div>' + "\n";
  394. print ' <script>';
  395. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  396. print ' var submissions = [';
  397. // Get list of student id have submit for each exercise:
  398. foreach ($exercises_list as $exercise) {
  399. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  400. print '
  401. {
  402. "exerciseid": "' . $exercise->id . '",
  403. "grade": ' . $exercise->grade . ',
  404. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  405. "submited": ['; // "
  406. $params = array('iassign_statementid' => $exercise->id);
  407. $submited = $DB->get_records_sql( // Get userid and his grade
  408. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  409. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  410. foreach ($submited as $ss) {
  411. print($ss->userid . ',');
  412. }
  413. print '],';
  414. print '"allgrades": [';
  415. foreach ($submited as $ss) {
  416. print( $ss->grade . ',');
  417. }
  418. print ']
  419. },'; // close "
  420. } // foreach ($exercises_list as $exercise)
  421. print " ];\n";
  422. print '
  423. var total_submissions = 0;
  424. var selected_exercises;
  425. var count_steps;
  426. var value_by_step;
  427. var stoped = false;
  428. var time_interval = 5000;
  429. var var_interval;
  430. function add_hover_th (id_th, id_li) {
  431. $("#" + id_th).hover(function() {
  432. $("#" + id_li).css("background-color", "#d9d8d8");
  433. $(this).css("background-color", "#d9d8d8");
  434. }, function() {
  435. $("#" + id_li).css("background-color", "");
  436. $(this).css("background-color", "");
  437. });
  438. }
  439. function start_evaluation () {
  440. stoped = false;
  441. $("#progress_bar").css("display", "none");
  442. $("#evaluate_message").text("");
  443. $("#evaluate_alerts").text("");
  444. $(".added-col").remove();
  445. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  446. selected_exercises = [];
  447. var c = 0;
  448. for (var i = 0; i < exercises.length; i++) {
  449. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  450. selected_exercises[c++] = exercises[i];
  451. }
  452. }
  453. if (selected_exercises.length == 0) {
  454. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  455. return;
  456. } else {
  457. $("input:checkbox").attr("disabled", true);
  458. for (var i = 0; i < selected_exercises.length; i++) {
  459. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  460. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  461. $("#table-results tbody tr").each(function(e) {
  462. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  463. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  464. });
  465. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  466. }
  467. $("#button_start").prop("disabled", true);
  468. $("#button_stop").prop("disabled", false);
  469. $("#progress_bar").css("display", "block");
  470. }
  471. total_submissions = selected_exercises.length * students.length;
  472. count_steps = 0;
  473. value_by_step = 100/total_submissions;
  474. actual_exercise = 0;
  475. actual_student = 0;
  476. actual_submission = 0;
  477. get_original_propositions();
  478. var_interval = setInterval(verifyBreak, time_interval);
  479. } // function start_evaluation()
  480. var actual_exercise;
  481. var actual_student;
  482. var actual_submission;
  483. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  484. function run_individual_evaluation () {
  485. if (stoped) return;
  486. // Verify if student really sent his answer
  487. var found = false;
  488. for (var j = 0; j < submissions.length; j++) {
  489. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  490. for (var k = 0; k < submissions[j].submited.length; k++) {
  491. if (students[actual_student] == submissions[j].submited[k]) {
  492. found = true;
  493. break;
  494. }
  495. }
  496. break;
  497. }
  498. }
  499. if (found == false) {
  500. postResultAutoEval();
  501. } else {
  502. // If it was sent, search it...
  503. var final_url = "";
  504. 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];
  505. for (var j = 0; j < submissions.length; j++) {
  506. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  507. final_url = submissions[j].ilm;
  508. break;
  509. }
  510. }
  511. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  512. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  513. window.frames["ifrm"].location=final_url;
  514. }
  515. } // function run_individual_evaluation()
  516. var break_student = -1;
  517. var break_exercise = -1;
  518. function verifyBreak () {
  519. if (actual_student == break_student && actual_exercise == break_exercise) {
  520. postResultAutoEval(-6);
  521. break_student = -1;
  522. break_exercise = -1;
  523. return;
  524. } else {
  525. break_student = actual_student;
  526. break_exercise = actual_exercise;
  527. }
  528. }
  529. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  530. function getStudentAnswerURL () {
  531. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  532. }
  533. // This function is called by the iLM!!!
  534. function getAutoEvalOriginalData () {
  535. return original_propositions[actual_exercise];
  536. }
  537. function updateProgressBar () {
  538. if (stoped) return;
  539. var temp = (count_steps * value_by_step)|0;
  540. count_steps ++;
  541. temp = temp > 100 ? 100 : temp;
  542. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  543. if (temp >= 100) {
  544. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  545. $("#button_start").prop("disabled", false);
  546. $("#button_stop").prop("disabled", true);
  547. $("input:checkbox").attr("disabled", false);
  548. clearInterval(var_interval);
  549. }
  550. }
  551. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  552. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  553. function postResultAutoEval (grade = null) {
  554. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  555. if (grade == null) {
  556. $("#"+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>\');
  557. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  558. } else {
  559. // Verify if the re-evaluation grade is the of that one registered:
  560. var actual_value = 0;
  561. var actual_student_grade = 0;
  562. for (var k = 0; k < submissions.length; k++) {
  563. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  564. actual_value = submissions[k].grade;
  565. for (var h = 0; h < submissions[k].submited.length; h++) {
  566. if (submissions[k].submited[h] == students[actual_student]) {
  567. actual_student_grade = submissions[k].allgrades[h];
  568. break;
  569. }
  570. }
  571. break;
  572. }
  573. }
  574. // @FeedbackConvention
  575. if (grade < 0) {
  576. switch (grade) {
  577. case -1:
  578. // Test-cases are empty:
  579. $("#"+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>\');
  580. var mm = actual_exercise;
  581. $("#"+id_t).find(".details-button").click(function(e) {
  582. $(".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>\');
  583. });
  584. break;
  585. case -2:
  586. // Test-cases were manually altered by the student (fraud!):
  587. $("#"+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>\');
  588. var mm = actual_exercise;
  589. $("#"+id_t).find(".details-button").click(function(e) {
  590. $(".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>");
  591. });
  592. $.ajax({
  593. dataType: "html",
  594. 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",
  595. success: function(d) {}
  596. });
  597. break;
  598. case -5:
  599. // Execution failed:
  600. $("#"+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>\');
  601. var mm = actual_exercise;
  602. $("#"+id_t).find(".details-button").click(function(e) {
  603. $(".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>\');
  604. });
  605. break;
  606. case -6: // iLM not answering was detected in "verifyBreak()"
  607. // The iLM are not answering:
  608. $("#"+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>\');
  609. $("#"+id_t).find(".details-button").click(function(e) {
  610. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  611. });
  612. break;
  613. }
  614. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  615. } else {
  616. console.log((grade), (actual_student_grade));
  617. if ((grade) == (actual_student_grade)) {
  618. $("#"+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>\');
  619. } else { // Notas diferem:
  620. $("#"+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>\');
  621. var mm = actual_exercise;
  622. $("#"+id_t).find(".details-button").click(function(e) {
  623. $(".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>\');
  624. });
  625. // Send to the endpoint the post_auto_eval_result to verify:
  626. $.ajax({
  627. dataType: "html",
  628. 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),
  629. success: function(d) {}
  630. });
  631. }
  632. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  633. }
  634. }
  635. updateProgressBar();
  636. // Does it must continue in the same exercise or stop?
  637. if (actual_student < students.length) {
  638. actual_student ++;
  639. run_individual_evaluation();
  640. } else {
  641. actual_student = 0;
  642. // Does it go to next exercise or is it finished?
  643. if (actual_exercise < selected_exercises.length) {
  644. actual_exercise++;
  645. run_individual_evaluation();
  646. } else {
  647. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  648. }
  649. }
  650. }
  651. var original_propositions;
  652. function get_original_propositions () {
  653. original_propositions = [];
  654. var count = 0;
  655. for (var i = 0; i < exercises.length; i++) {
  656. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  657. $.ajax({
  658. dataType: "html",
  659. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  660. success: function(d) { // variable "d" has the iLM content
  661. original_propositions[count] = d; // exercise original content
  662. count ++;
  663. if (count == selected_exercises.length) {
  664. run_individual_evaluation();
  665. }
  666. }
  667. });
  668. }
  669. }
  670. }
  671. function stop_evaluation () {
  672. stoped = true;
  673. $("#button_start").prop("disabled", false);
  674. $("#button_stop").prop("disabled", true);
  675. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  676. $("input:checkbox").attr("disabled", false);
  677. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  678. clearInterval(var_interval);
  679. }
  680. var exercises = [ '; // '
  681. foreach ($exercises_list as $exercise) {
  682. print $exercise->id . ',';
  683. }
  684. print ' ];';
  685. print ' var students = [ ';
  686. foreach ($students_list as $student) {
  687. print $student->userid . ',';
  688. }
  689. print '];';
  690. print ' var ilms = [';
  691. foreach ($exercises_list as $exercise) {
  692. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  693. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  694. }
  695. print ']';
  696. print '</script>';
  697. print '
  698. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  699. <div class="modal-dialog modal-dialog-centered" role="document">
  700. <div class="modal-content">
  701. <div class="modal-header">
  702. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  703. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  704. <span aria-hidden="true">&times;</span>
  705. </button>
  706. </div>
  707. <div class="modal-body">
  708. ...
  709. </div>
  710. <div class="modal-footer">
  711. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  712. </div>
  713. </div>
  714. </div>
  715. </div>'; //
  716. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  717. print '<table id="table-results" class="table table-hover m-t-1">
  718. <thead>
  719. <tr id="cols-exercises">
  720. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  721. </tr>
  722. </thead>
  723. <tbody>'; // "
  724. foreach ($students_list as $student) {
  725. $user = $DB->get_record('user', array('id' => $student->userid));
  726. $avatar = new user_picture($user);
  727. $avatar->courseid = $COURSE->id;
  728. $avatar->link = true;
  729. print
  730. '<tr data-student="'.$student->userid.'">
  731. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  732. </tr>'; // "
  733. }
  734. print '</tbody>
  735. </table>'; // "
  736. print $OUTPUT->footer();
  737. } // function auto_evaluate()
  738. /// This method moves an iAssign activity
  739. function move_activity () {
  740. global $USER, $CFG, $DB, $COURSE;
  741. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  742. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  743. $update_entry_new_iassign = new stdClass();
  744. $update_entry_new_iassign->id = $iassign_id;
  745. $update_entry_new_iassign->iassignid = $iassign_destiny;
  746. // Update the iassign_statement
  747. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  748. // Update file context
  749. $c_i = context_module::instance($this->cm->id);
  750. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  751. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  752. $path_module = context_course::instance($COURSE->id);
  753. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  754. if ($context_file) {
  755. $id_context = $context_file->id;
  756. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  757. $fs = get_file_storage(); // Get reference to all files in Moodle data
  758. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  759. foreach ($files as $value) {
  760. if ($value->get_filename() != ".") {
  761. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  762. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  763. $updateentry = new stdClass();
  764. $updateentry->id = $iassign_id;
  765. $updateentry->file = $newfile->get_itemid();
  766. $DB->update_record("iassign_statement", $updateentry);
  767. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  768. break;
  769. }
  770. }
  771. }
  772. $this->return_home_course('moved_activity');
  773. exit;
  774. }
  775. /// This method duplicates an iAssign activity
  776. function duplicate_activity () {
  777. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  778. $id = $this->cm->id;
  779. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  780. $context = context_module::instance($this->cm->id);
  781. $contextuser = context_user::instance($USER->id);
  782. // Get the the iAssign acitivity to be duplicated
  783. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  784. // Remove the current id of activity
  785. $iassign_statement->id=0;
  786. // Get the information about current author, and add this information in author_modified field
  787. $author = $DB->get_record("user", array('id' => $USER->id));
  788. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  789. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  790. // Store the activity in the table
  791. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  792. // Duplicate activity file
  793. $fs = get_file_storage(); // Get reference to all files in Moodle data
  794. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  795. foreach ($files as $value) {
  796. if ($value->get_filename() != ".") {
  797. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  798. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  799. $updateentry = new stdClass();
  800. $updateentry->id = $id_;
  801. $updateentry->file = $newfile->get_itemid();
  802. // Update the duplicated iLM iAssign with new file id
  803. $DB->update_record("iassign_statement", $updateentry);
  804. }
  805. }
  806. }
  807. // log event --------------------------------------------------------------------------------------
  808. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  809. $this->return_home_course('duplicated_activity');
  810. exit;
  811. }
  812. // / This method gets the content from comment and register it
  813. function add_comment () {
  814. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  815. $comment = false;
  816. if ($submission_comment)
  817. $comment = $this->write_comment_submission();
  818. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  819. echo $this->search_comment_submission($id_submission);
  820. }
  821. /// This method gets the content from the iLM and register it
  822. // It could be the "exercise template" (teacher) or an answer (student)
  823. function get_answer () {
  824. global $USER, $CFG, $DB, $OUTPUT;
  825. $id = $this->cm->id;
  826. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  827. $comment = false;
  828. if ($submission_comment)
  829. $comment = $this->write_comment_submission();
  830. // receives data of iLM using the current activity
  831. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  832. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  833. // receives data of submission of current activity
  834. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  835. // receives post and get
  836. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  837. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  838. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  839. $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)
  840. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  841. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  842. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  843. $msg = '';
  844. if ($this->activity->get_activity()->store_all_submissions == 1) {
  845. $newentry = new stdClass();
  846. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  847. $newentry->userid = $this->userid_iassign;
  848. $newentry->timecreated = time();
  849. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  850. $newentry->answer = $iLM_PARAM_ArchiveContent;
  851. $DB->insert_record("iassign_allsubmissions", $newentry);
  852. }
  853. // Feedback
  854. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  855. $str_action = "view"; // repeat
  856. if (strtolower($iassign_ilm->name) == "igeom") {
  857. }
  858. $title = get_string('evaluate_iassign', 'iassign');
  859. print $OUTPUT->header();
  860. print $OUTPUT->box_start();
  861. // Action = { view ; repeat ; viewsubmission }
  862. // * '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")
  863. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  864. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  865. $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;
  866. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  867. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  868. print '<table width=100% >';
  869. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  870. //TODO alterar aqui???
  871. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  872. // empty_answer_post = No solution was posted.
  873. if ($comment)
  874. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  875. else
  876. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  877. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  878. } else {
  879. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  880. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  881. // Correct answer!!
  882. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  883. $this->write_solution = 1; //
  884. $status = 3;
  885. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  886. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  887. // log record
  888. $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;
  889. // Trigger module viewed event.
  890. $event = \mod_iassign\event\submission_created::create(array(
  891. 'objectid' => $this->iassign->id,
  892. 'context' => $this->context,
  893. 'other' => $info
  894. ));
  895. $event->add_record_snapshot('course', $this->course);
  896. $event->trigger();
  897. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  898. // Wrong answer...: get_answer_incorrect
  899. $status = 2;
  900. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  901. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  902. // log record
  903. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  904. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  905. // Trigger module viewed event.
  906. $event = \mod_iassign\event\submission_created::create(array(
  907. 'objectid' => $this->iassign->id,
  908. 'context' => $this->context,
  909. 'other' => $info
  910. ));
  911. $event->add_record_snapshot('course', $this->course);
  912. $event->trigger();
  913. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  914. // Presents to the learner the result of the automatic evaluate?
  915. if ($this->activity->get_activity()->show_answer == 0) { // no...
  916. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  917. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  918. print '<tr>';
  919. // log record
  920. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  921. // Trigger module viewed event.
  922. $event = \mod_iassign\event\submission_created::create(array(
  923. 'objectid' => $this->iassign->id,
  924. 'context' => $this->context,
  925. 'other' => $info
  926. ));
  927. $event->add_record_snapshot('course', $this->course);
  928. $event->trigger();
  929. } else { // yes!!!
  930. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  931. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  932. print '<tr>';
  933. print $msg;
  934. }
  935. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  936. $status = 1;
  937. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  938. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  939. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  940. print '<tr>';
  941. // log record
  942. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  943. $event = \mod_iassign\event\submission_created::create(array(
  944. 'objectid' => $this->iassign->id,
  945. 'context' => $this->context,
  946. 'other' => $info
  947. ));
  948. $event->add_record_snapshot('course', $this->course);
  949. $event->trigger();
  950. } // if ($iassign_ilm->evaluate == 1)
  951. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  952. print '</tr></table>';
  953. print $OUTPUT->box_end();
  954. // add or update evaluate
  955. if ($this->write_solution == 1) {
  956. $timenow = time();
  957. // new record
  958. if (!$iassign_submission) {
  959. $newentry = new stdClass();
  960. $newentry->userid = $this->userid_iassign;
  961. // $newentry->userid = $USER->id;
  962. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  963. $newentry->timecreated = $timenow;
  964. $newentry->timemodified = $timenow;
  965. $newentry->answer = $iLM_PARAM_ArchiveContent;
  966. $newentry->grade = round($grade_student, 2);
  967. $newentry->status = $status;
  968. $newentry->experiment = 1;
  969. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  970. print_error('error_insert', 'iassign');
  971. } else {
  972. // Trigger module viewed event.
  973. $event = \mod_iassign\event\submission_created::create(array(
  974. 'objectid' => $this->iassign->id,
  975. 'context' => $this->context
  976. ));
  977. $event->add_record_snapshot('course', $this->course);
  978. $event->trigger();
  979. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  980. }
  981. } elseif ($iassign_submission->status != 3) {
  982. $newentry = new stdClass();
  983. $newentry->id = $iassign_submission->id;
  984. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  985. $newentry->userid = $iassign_submission->userid;
  986. $newentry->timecreated = $iassign_submission->timecreated;
  987. $newentry->timemodified = $timenow;
  988. $newentry->answer = $iLM_PARAM_ArchiveContent;
  989. $newentry->grade = round($grade_student, 2);
  990. $newentry->status = $status;
  991. $newentry->experiment = $iassign_submission->experiment + 1;
  992. if (!$DB->update_record("iassign_submission", $newentry)) {
  993. print_error('error_update', 'iassign');
  994. //D depurar...
  995. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  996. //D $fp = fopen("teste1.txt","w");
  997. //D fwrite($fp,$stringAux);
  998. } else {
  999. // Trigger module viewed event.
  1000. $event = \mod_iassign\event\submission_updated::create(array(
  1001. 'objectid' => $this->iassign->id,
  1002. 'context' => $this->context
  1003. ));
  1004. $event->add_record_snapshot('course', $this->course);
  1005. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1006. }
  1007. } else {
  1008. if ($return_get_answer == 1) {
  1009. $newentry = new stdClass();
  1010. $newentry->id = $iassign_submission->id;
  1011. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1012. $newentry->userid = $iassign_submission->userid;
  1013. $newentry->timecreated = $iassign_submission->timecreated;
  1014. $newentry->timemodified = $timenow;
  1015. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1016. $newentry->grade = round($grade_student, 2);
  1017. $newentry->status = $status;
  1018. $newentry->experiment = $iassign_submission->experiment + 1;
  1019. if (!$DB->update_record("iassign_submission", $newentry))
  1020. print_error('error_update', 'iassign');
  1021. else {
  1022. $event = \mod_iassign\event\submission_updated::create(array(
  1023. 'objectid' => $this->iassign->id,
  1024. 'context' => $this->context
  1025. ));
  1026. $event->add_record_snapshot('course', $this->course);
  1027. $event->trigger();
  1028. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1029. print $OUTPUT->box_start();
  1030. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1031. print $OUTPUT->box_end();
  1032. }
  1033. } elseif ($return_get_answer == 2) {
  1034. print $OUTPUT->box_start();
  1035. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1036. print $OUTPUT->box_end();
  1037. } else {
  1038. print $OUTPUT->box_start();
  1039. print "
  1040. <script type='text/javascript'>
  1041. //<![CDATA[
  1042. function overwrite () {
  1043. document.formEnvio.return_get_answer.value = 1;
  1044. document.formEnvio.submit();
  1045. }
  1046. function nooverwrite () {
  1047. document.formEnvio.return_get_answer.value = 2;
  1048. document.formEnvio.submit();
  1049. }
  1050. //]]>
  1051. </script>";
  1052. $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;
  1053. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1054. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1055. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1056. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1057. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1058. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1059. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1060. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1061. <input type='hidden' name='return_get_answer'/> ";
  1062. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1063. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1064. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1065. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1066. print " </form>";
  1067. print $OUTPUT->box_end();
  1068. }
  1069. }
  1070. } // if ($this->write_solution == 1)
  1071. print $OUTPUT->footer();
  1072. die();
  1073. } // function get_answer()
  1074. /// Export in file the answer of student.
  1075. function export_file_answer () {
  1076. global $DB;
  1077. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1078. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1079. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1080. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1081. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1082. $extensions = explode(",", $iassign_ilm->extension);
  1083. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1084. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1085. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1086. header("Pragma: public");
  1087. header("Expires: 0");
  1088. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1089. header("Cache-Control: private", false);
  1090. header("Content-Type: document/unknown");
  1091. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1092. set_time_limit(0);
  1093. print($iassign_submission->answer);
  1094. exit;
  1095. } // function export_file_answer()
  1096. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1097. // @calledby $this->export_package_answer()
  1098. //TODO Precisa terminar! //TODO_HTML
  1099. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1100. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1101. <head>
  1102. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1103. $str_html .= " </head>
  1104. <body>\n";
  1105. $tam = sizeof($array_iassign_name);
  1106. for ($ii=0; $ii<$tam; $ii++) {
  1107. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1108. }
  1109. $str_html .= "
  1110. </body>\n</html>";
  1111. return $str_html;
  1112. }
  1113. /// Export an package (zip) with all answer of students
  1114. // @calledby $this->action()
  1115. function export_package_answer () {
  1116. global $DB, $CFG, $OUTPUT;
  1117. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1118. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1119. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1120. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1121. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1122. $userid = optional_param('userid', NULL, PARAM_INT);
  1123. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1124. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1125. //TODO_HTML echo "username=$username<br/>"; exit;
  1126. $current_date = date('Y_m_d_H');
  1127. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1128. // If temporary directory under Moodle data does not exists => create it
  1129. if (!is_dir($diretorio)) {
  1130. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1131. // created directory with permissions to be seen by everyone
  1132. }
  1133. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1134. if (!is_writable($diretorio)) { // send a highlighted message!
  1135. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1136. exit; // just in case
  1137. }
  1138. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1139. $zip = new zip_archive(); // create ZIP
  1140. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1141. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1142. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1143. $vet_student_filename = array();
  1144. $vet_student_content = array();
  1145. foreach ($iassign_statements as $iassign_statement) {
  1146. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1147. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1148. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1149. $extensions = explode(",", $iassign_ilm->extension);
  1150. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1151. if ($iassign_submission) {
  1152. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1153. $student_content = $iassign_submission->answer;
  1154. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1155. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1156. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1157. if ($resp) {
  1158. $vet_student_filename[] = $student_filename;
  1159. $vet_student_content[] = $student_content;
  1160. }
  1161. else { // send a highlighted message!
  1162. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1163. exit; // just in case
  1164. }
  1165. }
  1166. }
  1167. $zip->close(); // close the ZIP file
  1168. if (count($vet_student_filename)>0) {
  1169. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1170. $result_tf = $vet_result[0];
  1171. $filenameZip = $vet_result[1]->filename;
  1172. }
  1173. iassign_utils::download_file($zip_filename); // download the ZIP file
  1174. exit;
  1175. } // function export_package_answer()
  1176. /// Editing status of interactive activities
  1177. function edit_status () {
  1178. global $USER, $DB, $OUTPUT;
  1179. $newentry = new stdClass();
  1180. $newentry->id = $this->iassign_submission_current;
  1181. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1182. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1183. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1184. $newentry->status = $iassign_submission->status;
  1185. $newentry->teacher = $USER->id;
  1186. if (!$DB->update_record('iassign_submission', $newentry))
  1187. print_error('error_update', 'iassign');
  1188. else {
  1189. // Trigger module viewed event.
  1190. $event = \mod_iassign\event\submission_updated::create(array(
  1191. 'objectid' => $this->iassign->id,
  1192. 'context' => $this->context
  1193. ));
  1194. $event->add_record_snapshot('course', $this->course);
  1195. $event->trigger();
  1196. $this->action = 'viewsubmission';
  1197. $this->view_iassign_current();
  1198. } // if (!$DB->update_record('iassign_submission', $newentry))
  1199. } // function edit_status()
  1200. /// Editing grade of interactive activities
  1201. function edit_grade () {
  1202. global $USER, $DB, $OUTPUT;
  1203. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1204. if ($newgrade && $newgrade >= 0) {
  1205. $newentry = new stdClass();
  1206. $newentry->id = $this->iassign_submission_current;
  1207. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1208. $newentry->teacher = $USER->id;
  1209. if (!$DB->update_record('iassign_submission', $newentry))
  1210. print_error('error_update', 'iassign');
  1211. else {
  1212. // Trigger module viewed event.
  1213. $event = \mod_iassign\event\submission_updated::create(array(
  1214. 'objectid' => $this->iassign->id,
  1215. 'context' => $this->context
  1216. ));
  1217. $event->add_record_snapshot('course', $this->course);
  1218. $event->trigger();
  1219. }
  1220. } // if ($newgrade >= 0)
  1221. $this->action = 'viewsubmission';
  1222. $this->view_iassign_current();
  1223. }
  1224. /// Add or Edit interactive activities
  1225. // @calledby $this->action()
  1226. function add_edit_iassign () {
  1227. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1228. require_once('iassign_form.php');
  1229. $id = $this->cm->id;
  1230. $iassignid = $this->iassign->id;
  1231. $param = new stdClass();
  1232. $param->action = $this->action; // oculto
  1233. $param->id = $id; // oculto
  1234. $COURSE->cm = $id;
  1235. $COURSE->iassignid = $iassignid;
  1236. $COURSE->iassign_file_id = NULL;
  1237. $context = context_module::instance($this->cm->id);
  1238. $contextuser = context_user::instance($USER->id);
  1239. $component = 'mod_iassign';
  1240. $filearea = 'exercise';
  1241. if (!empty($this->iassign_current))
  1242. $COURSE->iassign_id = $this->iassign_current;
  1243. else
  1244. $COURSE->iassign_id = 0;
  1245. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1246. if ($this->action == 'add') {
  1247. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1248. $params = array('iassignid' => $iassignid);
  1249. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1250. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1251. $total_of_activities = count($iassign_statement);
  1252. $param->iassignid = $iassignid;
  1253. $param->name = "";
  1254. $param->oldname = "";
  1255. $param->type_iassign = 3;
  1256. $param->proposition = "";
  1257. $author = $DB->get_record("user", array("id" => $USER->id));
  1258. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1259. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1260. $param->author = $param->author_name;
  1261. $param->author_modified = $param->author_modified_name;
  1262. $COURSE->iassign_list = array();
  1263. $param->iassign_list = array();
  1264. if ($iassign_statement) {
  1265. foreach ($iassign_statement as $iassign) {
  1266. $iassignid = $iassign->id;
  1267. $param->iassign_list[$iassignid] = 0;
  1268. $COURSE->iassign_list[$iassignid] = new stdClass();
  1269. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1270. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1271. $COURSE->iassign_list[$iassignid]->enable = 1;
  1272. } // foreach ($iassign_statement as $iassign)
  1273. }
  1274. $param->iassign_ilmid = 0;
  1275. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1276. $param->file = 0;
  1277. $param->fileold = 0;
  1278. $param->filename = "";
  1279. $param->grade = $iassign_data->grade;
  1280. $param->timemodified = time();
  1281. $param->timecreated = time();
  1282. $param->timeavailable = $iassign_data->timeavailable;
  1283. $param->timedue = $iassign_data->timedue;
  1284. $param->preventlate = $iassign_data->preventlate;
  1285. $param->test = $iassign_data->test;
  1286. $param->special_param1 = 0;
  1287. $param->visible = 1;
  1288. $param->max_experiment = $iassign_data->max_experiment;
  1289. $param->dependency = 0;
  1290. $param->automatic_evaluate = 1;
  1291. $param->show_answer = 1;
  1292. } // if ($this->action == 'add')
  1293. elseif ($this->action == 'edit') {
  1294. $COURSE->iassign_list = array();
  1295. $this_activity = $this->activity->get_activity();
  1296. if ($this_activity != null) {
  1297. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1298. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1299. $param->iassign_id = $iassign_statement_current->id; // oculto
  1300. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1301. $param->name = $iassign_statement_current->name;
  1302. $param->oldname = $iassign_statement_current->name;
  1303. $param->type_iassign = $iassign_statement_current->type_iassign;
  1304. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1305. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1306. //2019 $param->proposition = $iassign_statement_current->proposition;
  1307. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1308. $param->author_name = $iassign_statement_current->author_name; // oculto
  1309. $param->author = $iassign_statement_current->author_name;
  1310. $author = $DB->get_record("user", array('id' => $USER->id));
  1311. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1312. $param->author_modified = $param->author_modified_name;
  1313. $dependency = explode(';', $iassign_statement_current->dependency);
  1314. $param->iassign_list = array();
  1315. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1316. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1317. $array_dependency = array();
  1318. $subdependency = "";
  1319. $sub_subdependency = "";
  1320. // dependent on this exercise
  1321. if ($iassign_statement_dependency) {
  1322. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1323. // to whom this exercise depends
  1324. foreach ($inter as $tmp)
  1325. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1326. $list_dependency = $subdependency . $sub_subdependency;
  1327. $array_dependency = explode(";", $list_dependency);
  1328. }
  1329. // Get all activity with the same iLM - iassignid
  1330. $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";
  1331. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1332. $total_of_activities = count($all_others_iassign_statement) + 1;
  1333. $inter = array();
  1334. if ($all_others_iassign_statement) {
  1335. foreach ($all_others_iassign_statement as $iassign)
  1336. if (in_array($iassign->id, $dependency))
  1337. $inter[] = $iassign->id;
  1338. }
  1339. if ($all_others_iassign_statement) {
  1340. foreach ($all_others_iassign_statement as $iassign) {
  1341. $iassignid = $iassign->id;
  1342. $COURSE->iassign_list[$iassignid] = new stdClass();
  1343. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1344. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1345. if (in_array($iassignid, $dependency))
  1346. $param->iassign_list[$iassignid] = 1;
  1347. else
  1348. $param->iassign_list[$iassignid] = 0;
  1349. if (in_array($iassignid, $array_dependency))
  1350. $COURSE->iassign_list[$iassignid]->enable = 0;
  1351. else
  1352. $COURSE->iassign_list[$iassignid]->enable = 1;
  1353. } // foreach ($all_others_iassign_statement as $iassign)
  1354. }
  1355. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1356. $param->fileold = 0;
  1357. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1358. $param->filename = '';
  1359. $param->grade = $iassign_statement_current->grade;
  1360. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1361. $param->timeavailable = $iassign_statement_current->timeavailable;
  1362. $param->timedue = $iassign_statement_current->timedue;
  1363. $param->preventlate = $iassign_statement_current->preventlate;
  1364. $param->test = $iassign_statement_current->test;
  1365. $param->special_param1 = $iassign_statement_current->special_param1;
  1366. $param->position = $iassign_statement_current->position; // oculto
  1367. $param->visible = $iassign_statement_current->visible;
  1368. $param->max_experiment = $iassign_statement_current->max_experiment;
  1369. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1370. $param->show_answer = $iassign_statement_current->show_answer;
  1371. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1372. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1373. if ($files) {
  1374. foreach ($files as $file) {
  1375. if ($file->get_filename() != '.') {
  1376. $param->filename = $file->get_filename();
  1377. $param->file = $file->get_id();
  1378. $param->fileold = $file->get_id();
  1379. $COURSE->iassign_file_id = $file->get_id();
  1380. }
  1381. }
  1382. }
  1383. //TODO //MOOC2014 -- inicio
  1384. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1385. //D if ($iassign_ilm_configs) {
  1386. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1387. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1388. //D } //MOOC2014 -- fim
  1389. } // if ($this_activity != null)
  1390. } // elseif ($this->action == 'edit')
  1391. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1392. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1393. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1394. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1395. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1396. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1397. $param->position = $total_of_activities;
  1398. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1399. $mform->set_data($param);
  1400. if ($mform->is_cancelled()) {
  1401. $this->return_home_course('iassign_cancel');
  1402. exit;
  1403. }
  1404. else { // if ($mform->is_cancelled())
  1405. $result = $mform->get_data();
  1406. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1407. if ($result) {
  1408. $result->context = $context;
  1409. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1410. $result->grade = 0;
  1411. if ($result->type_iassign == 1) {
  1412. $result->automatic_evaluate = 0;
  1413. $result->show_answer = 0;
  1414. }
  1415. elseif ($result->automatic_evaluate == 0)
  1416. $result->show_answer = 0;
  1417. // $_POST['iassign_list']
  1418. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1419. if ($result->iassign_list) {
  1420. foreach ($result->iassign_list as $key => $value)
  1421. $result->dependency .= $key . ';';
  1422. }
  1423. else
  1424. $result->dependency = 0;
  1425. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1426. //TODO Then get it directly from the form data $_POST!
  1427. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1428. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1429. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1430. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1431. if ($this->action == 'add') {
  1432. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1433. if ($iassign_statement_name) {
  1434. $this->return_home_course('error_iassign_name');
  1435. die();
  1436. }
  1437. // Really insert the new iActivity in table '*_iassign_statement'
  1438. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1439. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1440. // Trigger module viewed event.
  1441. $event = \mod_iassign\event\iassign_created::create(array(
  1442. 'objectid' => $iassignid,
  1443. 'context' => $context
  1444. ));
  1445. $event->add_record_snapshot('course', $this->course);
  1446. $event->trigger();
  1447. $this->return_home_course('iassign_add');
  1448. } // if ($this->action == 'add')
  1449. elseif ($this->action == 'edit') {
  1450. $iassignid = $this->activity->update_iassign($result);
  1451. $this->activity->update_calendar($iassignid, $result->oldname);
  1452. // Trigger module viewed event.
  1453. $event = \mod_iassign\event\iassign_updated::create(array(
  1454. 'objectid' => $iassignid,
  1455. 'context' => $context
  1456. ));
  1457. $event->add_record_snapshot('course', $this->course);
  1458. $event->trigger();
  1459. $this->return_home_course('iassign_update');
  1460. } // elseif ($this->action == 'edit')
  1461. die();
  1462. } // if ($result)
  1463. } // else if ($mform->is_cancelled())
  1464. print $OUTPUT->header();
  1465. $mform->display();
  1466. print $OUTPUT->footer();
  1467. die();
  1468. } // function add_edit_iassign()
  1469. /// Search for dependencies
  1470. function search_dependency ($search_iassing_id, $iassign_statement) {
  1471. global $DB, $OUTPUT;
  1472. $dependency = "";
  1473. if ($iassign_statement)
  1474. foreach ($iassign_statement as $iassign) {
  1475. $inter_dependency = explode(';', $iassign->dependency);
  1476. if (in_array($search_iassing_id, $inter_dependency)) {
  1477. $dependency .= $iassign->id . ";";
  1478. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1479. } // if (in_array($search_iassing_id, $inter_dependency))
  1480. } // foreach ($iassign_statement as $iassign)
  1481. return $dependency;
  1482. }
  1483. /// Search for "sub"dependency
  1484. function search_sub_dependency ($search_iassing_id) {
  1485. global $DB, $OUTPUT;
  1486. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1487. $dependency = "";
  1488. if ($iassign_statement) {
  1489. $inter_dependency = explode(';', $iassign_statement->dependency);
  1490. foreach ($inter_dependency as $tmp) {
  1491. if ($tmp != 0)
  1492. $dependency .= $tmp . ";";
  1493. $dependency .= $this->search_sub_dependency($tmp);
  1494. } // foreach ($inter_dependency as $tmp)
  1495. } // if ($iassign_statement)
  1496. return $dependency;
  1497. }
  1498. // Warning message
  1499. static function warning_message_iassign ($strcode) {
  1500. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1501. }
  1502. /// Update grade of iAssign
  1503. // Called always any iAssign activity is created
  1504. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1505. static function update_grade_iassign ($iassignid) {
  1506. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1507. require_once($CFG->libdir . '/gradelib.php');
  1508. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1509. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1510. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1511. // Each iAssign item is associated with one item on the "gradebook"
  1512. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1513. //$sum_grade = 0;
  1514. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1515. //foreach($grade as $tmp) {
  1516. // $sum_grade += $tmp->grade;
  1517. // }
  1518. //1 Solution 1
  1519. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1520. //1 $sum_grade = 0; //1
  1521. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1522. //2 Solution 2
  1523. $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
  1524. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1525. if (key($array_sum_grade))
  1526. $sum_grade = key($array_sum_grade); //2
  1527. else
  1528. $sum_grade = 0; //2
  1529. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1530. $grades = NULL;
  1531. $params = array('itemname' => $grade_iassign->name);
  1532. $params['iteminstance'] = $iassignid;
  1533. $params['gradetype'] = GRADE_TYPE_VALUE;
  1534. //2016 if ($sum_grade != 0) {
  1535. $params['grademax'] = $sum_grade;
  1536. $params['rawgrademax'] = $sum_grade;
  1537. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1538. $params['grademin'] = 0;
  1539. // @calls /lib/gradelib.php: call to grade_item->insert()
  1540. //TODO: is there any error here in Moodle version 3.0?
  1541. //TODO: Incorrect property 'grademax' found when inserting grade object
  1542. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1543. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1544. }
  1545. /// Update grade of student
  1546. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1547. global $CFG, $DB, $OUTPUT;
  1548. require_once($CFG->libdir . '/gradelib.php');
  1549. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1550. // Review all the student submission for this iAssign activity
  1551. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1552. $total_grade = 0;
  1553. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1554. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1555. if ($iassign_submission)
  1556. $total_grade += $iassign_submission->grade;
  1557. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1558. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1559. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1560. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1561. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1562. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1563. $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
  1564. if (key($array_sum_grade))
  1565. $sum_grade = key($array_sum_grade); //2
  1566. else
  1567. $sum_grade = 0; //2
  1568. $grades['userid'] = $userid;
  1569. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1570. $params = array('itemname' => $grade_iassign->name);
  1571. $params['iteminstance'] = $iassignid;
  1572. $params['gradetype'] = GRADE_TYPE_VALUE;
  1573. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1574. $params['grademax'] = $sum_grade;
  1575. $params['rawgrademax'] = $sum_grade;
  1576. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1577. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1578. }
  1579. /// Display caption of icons
  1580. function view_legend_icons () {
  1581. global $USER, $CFG, $DB, $OUTPUT;
  1582. $id = $this->cm->id;
  1583. if ($this->action == 'print')
  1584. print '<table border=1 width=100%><tr>';
  1585. else
  1586. print '<table width=100%><tr>';
  1587. print '<td >';
  1588. if ($this->action != 'print')
  1589. print $OUTPUT->help_icon('legend', 'iassign');
  1590. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1591. // $imagetext = '');
  1592. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1593. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1594. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1595. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1596. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1597. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1598. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1599. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1600. print '</td>' . "\n";
  1601. if ($this->action != 'print') {
  1602. $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>";
  1603. $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>";
  1604. $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>";
  1605. $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>";
  1606. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1607. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1608. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1609. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1610. } // if ($this->action != 'print')
  1611. print '</tr></table>' . "\n";
  1612. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1613. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1614. $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>";
  1615. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1616. print '</tr></table>' . "\n";
  1617. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1618. else
  1619. print '</td></tr></table>' . "\n";
  1620. } // function view_legend_icons()
  1621. /// Display activity current
  1622. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1623. function view_iassign_current () {
  1624. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1625. $id = $this->cm->id;
  1626. $iassignid = $this->iassign->id;
  1627. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1628. $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
  1629. // 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 ...
  1630. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1631. if (!$iassign_statement_activity_item) {
  1632. print $OUTPUT->header();
  1633. \core\notification::error(get_string('activity_not_found', 'iassign'));
  1634. print $OUTPUT->footer();
  1635. exit;
  1636. }
  1637. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1638. $ilm_name = '';
  1639. if ($ilm->ilm)
  1640. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1641. // 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
  1642. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1643. // log record
  1644. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1645. //Trigger module viewed event.
  1646. $event = \mod_iassign\event\submission_viewed::create(array(
  1647. 'objectid' => $iassign->id,
  1648. 'context' => $this->context,
  1649. 'other' => $info
  1650. ));
  1651. $event->add_record_snapshot('course', $this->course);
  1652. $event->trigger();
  1653. // Search of iLM data used in the current activity
  1654. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1655. // Add actual activity to navbar:
  1656. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1657. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1658. print $OUTPUT->header();
  1659. if ($this->action == 'viewsubmission') {
  1660. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1661. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1662. else
  1663. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1664. } else {
  1665. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1666. }
  1667. if ($iassign_submission)
  1668. $this->update_comment($iassign_submission->id);
  1669. $file = $iassign_statement_activity_item->file;
  1670. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1671. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1672. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1673. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1674. $this->bottonPost = 0; // hide submit button
  1675. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1676. $this->view_iassign = false; // disable visualization of activity
  1677. $repeat = "";
  1678. $last_iassign = "";
  1679. $student_answer = "";
  1680. $comment = "";
  1681. // *** Teacher access (view learner's submission)
  1682. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1683. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1684. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1685. // ---> access teacher for test
  1686. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1687. $this->bottonPost = 1;
  1688. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1689. $this->activity->view_dates();
  1690. $USER->iassignEdit = $this->bottonPost;
  1691. $this->activity->show_info_iassign();
  1692. if ($iassign_submission) {
  1693. //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;
  1694. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1695. } else {
  1696. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1697. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1698. }
  1699. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1700. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1701. // Prepare tags to present the iLM
  1702. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1703. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1704. // *** (end) Teacher access (view the activity)
  1705. // *** Teacher access (view learner's submission to the activity)
  1706. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1707. // It is teacher or 'nonediting teacher' that can evaluate
  1708. // ----> area teacher evaluate
  1709. $row = optional_param('row', 0, PARAM_INT);
  1710. $column = optional_param('column', 0, PARAM_INT);
  1711. $link_next = iassign_icons::insert('right_disable');
  1712. $link_previous = iassign_icons::insert('left_disable');
  1713. $link_up = iassign_icons::insert('up_disable');
  1714. $link_down = iassign_icons::insert('down_disable');
  1715. // next_activity
  1716. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1717. $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);
  1718. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1719. }
  1720. // previous_activity
  1721. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1722. $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);
  1723. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1724. }
  1725. // previous_student
  1726. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1727. $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);
  1728. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1729. }
  1730. // next_student
  1731. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1732. $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);
  1733. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1734. }
  1735. if ($iassign_submission) {
  1736. $student_answer = $iassign_submission->answer;
  1737. }
  1738. $last_iassign = get_string('last_iassign', 'iassign');
  1739. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1740. // Messages related to due date (and user role)
  1741. $this->activity->view_dates();
  1742. print $OUTPUT->box_start();
  1743. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1744. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1745. print $OUTPUT->user_picture($user_data);
  1746. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1747. print '</td>' . "\n";
  1748. print '<td width=20% align=right>' . "\n";
  1749. print '<table width=50 cellpadding="0">';
  1750. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1751. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1752. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1753. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1754. print '</table>' . "\n";
  1755. print '</td></tr></table>' . "\n";
  1756. print $OUTPUT->box_end();
  1757. print $OUTPUT->box_start();
  1758. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1759. print '<td width=60% valign="top">' . "\n";
  1760. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1761. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1762. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1763. $resp = get_string('yes');
  1764. else
  1765. $resp = get_string('no');
  1766. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1767. if ($iassign_statement_activity_item->show_answer == 1)
  1768. $resp = get_string('yes');
  1769. else
  1770. $resp = get_string('no');
  1771. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1772. print '</td>';
  1773. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1774. print '<td width=40% valign="top" align="left">';
  1775. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1776. // check status of solution sent by the student
  1777. if ($iassign_submission) {
  1778. switch ($iassign_submission->status) {
  1779. case 3 :
  1780. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1781. break;
  1782. case 2 :
  1783. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1784. break;
  1785. case 1 :
  1786. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1787. break;
  1788. default :
  1789. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1790. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1791. } // switch ($iassign_submission->status)
  1792. }
  1793. else { // if ($iassign_submission)
  1794. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1795. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1796. }
  1797. // update_status
  1798. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1799. $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);
  1800. print " <script type='text/javascript'>
  1801. //<![CDATA[
  1802. function overwriteStatus (newstatus) {
  1803. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1804. document.formEditStatus.return_status.value=newstatus;
  1805. document.formEditStatus.submit();
  1806. }
  1807. else
  1808. document.formEditStatus.return_status.value=-1;
  1809. }
  1810. //]]>
  1811. </script>";
  1812. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1813. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1814. 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";
  1815. print " <input type='hidden' name='return_status'>\n";
  1816. print "</form>\n";
  1817. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1818. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1819. $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);
  1820. print "
  1821. <script type='text/javascript'>
  1822. //<![CDATA[
  1823. function overwriteGrade (newgrade,maxgrade) {
  1824. if (newgrade<0 || newgrade>maxgrade) {
  1825. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1826. document.formEditGrade.return_grade.value=-1;
  1827. document.formEditGrade.submit();
  1828. }
  1829. else {
  1830. document.formEditGrade.return_grade.value=newgrade;
  1831. document.formEditGrade.submit();
  1832. }
  1833. }
  1834. //]]>
  1835. </script>";
  1836. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1837. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1838. print " <input type='text' name='grade' size='6'>";
  1839. print " <input type='hidden' name='return_grade'> ";
  1840. 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";
  1841. print "</form>";
  1842. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1843. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1844. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1845. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1846. if ($teacher)
  1847. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1848. } // if ($iassign_submission->experiment > 0)
  1849. print '</td>';
  1850. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1851. print '</tr></table>';
  1852. print $OUTPUT->box_end();
  1853. $USER->iassignEdit = $this->bottonPost;
  1854. if ($iassign_submission && $allow_resubmission) {
  1855. // Put the iLM to
  1856. print $OUTPUT->box_start();
  1857. print '<p><strong>' . $last_iassign . '</strong></p>';
  1858. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1859. $enderecoPOST = "";
  1860. // Prepare tags to present the iLM
  1861. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1862. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1863. print $OUTPUT->box_end();
  1864. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1865. // ATTENTION: exception used by iGeom (exercise with "script")
  1866. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1867. if (substr($ilm_name, 0, 5)=="igeom") {
  1868. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1869. $loadTeacherActivity = true;
  1870. }
  1871. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1872. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1873. // Prepare tags to present the iLM
  1874. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1875. }
  1876. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1877. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1878. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1879. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1880. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1881. // *** (end) Teacher access (view learner's submission to the activity)
  1882. // *** Student access (view the activity)
  1883. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1884. // It could be the learner (he could send or resend the activity)
  1885. // ---> access student
  1886. $time_now = time();
  1887. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1888. // activity of type example - not submit button for submission
  1889. $this->view_iassign = true;
  1890. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1891. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1892. // activity of type test - iLM automatic evaluator - submit button for submission
  1893. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1894. $this->bottonPost = 1;
  1895. $this->view_iassign = true;
  1896. } else
  1897. $this->view_iassign = false;
  1898. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1899. // activity of type exercise (learner can send his answer, if yet open...)
  1900. $this->view_iassign = true;
  1901. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1902. $this->view_iassign = false;
  1903. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1904. $this->bottonPost = 1; // allow the submit button
  1905. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1906. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1907. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1908. if (!$iassign_submission) {
  1909. $str_iassign_submission_id = '';
  1910. $str_iassign_submission_answer = '';
  1911. }
  1912. else {
  1913. $str_iassign_submission_id = $iassign_submission->id;
  1914. $str_iassign_submission_answer = $iassign_submission->answer;
  1915. }
  1916. if ($this->action != 'repeat') {
  1917. $repeat = "<a href='view.php?action=repeat&id="
  1918. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1919. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1920. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1921. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1922. }
  1923. $this->bottonPost = 1;
  1924. $this->write_solution = 1; // can register his submission
  1925. $student_answer = $str_iassign_submission_answer;
  1926. }
  1927. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1928. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1929. $last_iassign = get_string('last_iassign', 'iassign');
  1930. if ($iassign_submission) {
  1931. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1932. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1933. $student_answer = $iassign_submission->answer;
  1934. } else {
  1935. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1936. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1937. }
  1938. }
  1939. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1940. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1941. $this->bottonPost = 1;
  1942. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1943. } else {
  1944. $last_iassign = get_string('last_iassign', 'iassign');
  1945. if ($iassign_submission) {
  1946. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1947. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1948. $student_answer = $iassign_submission->answer;
  1949. } else {
  1950. // Symbol of "redo activity"
  1951. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1952. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1953. }
  1954. }
  1955. } // elseif ($iassign_statement_activity_item->test == 1)
  1956. elseif ($iassign_statement_activity_item->test == 0)
  1957. $this->view_iassign = false;
  1958. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1959. if ($iassign_submission)
  1960. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1961. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1962. else
  1963. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1964. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1965. $this->activity->view_dates();
  1966. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1967. print $OUTPUT->box_start();
  1968. print '<table width=100% border=0 valign="top">' . "\n";
  1969. print '<tr><td width=60% valign="top">' . "\n";
  1970. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1971. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1972. $flag_dependency = true;
  1973. if ($iassign_statement_activity_item->type_iassign == 3) {
  1974. if ($iassign_statement_activity_item->dependency == 0) {
  1975. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1976. } else {
  1977. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1978. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1979. foreach ($dependencys as $dependency) {
  1980. if ($dependency) {
  1981. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1982. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1983. if ($dependencysubmissions) {
  1984. if ($dependencysubmissions->status == 3)
  1985. $icon = iassign_icons::insert('correct');
  1986. elseif ($dependencysubmissions->status == 2) {
  1987. $icon = iassign_icons::insert('incorrect');
  1988. $flag_dependency = false;
  1989. } elseif ($dependencysubmissions->status == 1) {
  1990. $icon = iassign_icons::insert('post');
  1991. $flag_dependency = false;
  1992. } elseif ($dependencysubmissions->status == 0) {
  1993. $icon = iassign_icons::insert('not_post');
  1994. $flag_dependency = false;
  1995. }
  1996. } else {
  1997. $icon = iassign_icons::insert('not_post');
  1998. $flag_dependency = false;
  1999. } // if ($dependencysubmissions)
  2000. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2001. } // if ($dependency)
  2002. } // foreach ($dependencys as $dependency)
  2003. } // if ($iassign_statement_activity_item->dependency == 0)
  2004. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2005. if ($flag_dependency == false) {
  2006. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2007. $this->view_iassign = false;
  2008. print '</tr></table>' . "\n";
  2009. }
  2010. else {
  2011. $this->view_iassign = true;
  2012. print '</td>' . "\n";
  2013. } // if ($flag_dependency == false)
  2014. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2015. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2016. // receiver=1 - message to teacher
  2017. // receiver=2 - message to student
  2018. if ($iassign_submission) {
  2019. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2020. if ($verify_message)
  2021. $comment = iassign_icons::insert('comment_unread');
  2022. }
  2023. print '<td width=40% valign="top" align="left">';
  2024. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2025. if ($iassign_statement_activity_item->show_answer == 1) {
  2026. // check status of solution sent by the student
  2027. if ($iassign_submission) {
  2028. switch ($iassign_submission->status) {
  2029. case 3 :
  2030. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2031. break;
  2032. case 2 :
  2033. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2034. break;
  2035. case 1 :
  2036. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2037. break;
  2038. default :
  2039. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2040. $repeat = "";
  2041. $last_iassign = "";
  2042. } // switch ($iassign_submission->status)
  2043. } else {
  2044. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2045. $repeat = "";
  2046. $last_iassign = "";
  2047. }
  2048. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2049. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2050. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2051. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2052. if ($iassign_statement_activity_item->max_experiment == 0)
  2053. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2054. else {
  2055. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2056. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2057. $repeat = "";
  2058. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2059. $this->bottonPost = 0;
  2060. $this->write_solution = 0;
  2061. }
  2062. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2063. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2064. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2065. if ($teacher)
  2066. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2067. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2068. } // if ($iassign_statement_activity_item->show_answer==1)
  2069. else {
  2070. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2071. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2072. $repeat = "";
  2073. $last_iassign = "";
  2074. } elseif ($iassign_submission->status == 1) {
  2075. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2076. }
  2077. }
  2078. print '</td>';
  2079. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2080. print '</tr></table>' . "\n";
  2081. // Presents the iLM
  2082. print '<table width=100% border=0 valign="top">' . "\n";
  2083. print '<td width=80% align="left">';
  2084. 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\".
  2085. print '<td width=20% align="rigth">';
  2086. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2087. print $repeat; // symbol of "redo activity"
  2088. print '</td></tr></table>' . "\n";
  2089. //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)'
  2090. $output = '';
  2091. if (!$iassign_ilm) {
  2092. $iassign_ilm = new stdClass();
  2093. $iassign_ilm->file_jar = "";
  2094. }
  2095. $output .= $OUTPUT->box_start();
  2096. $USER->iassignEdit = $this->bottonPost;
  2097. // ---
  2098. // Presents the iLM
  2099. // Prepare tags to present the iLM
  2100. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2101. $student_answer = ""; //?
  2102. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2103. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2104. $student_answer = "";
  2105. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2106. } else {
  2107. // When student is redoing his activity
  2108. // ATTENTION: exception used by iGeom (exercise with "script")
  2109. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2110. if (substr($ilm_name, 0, 5)=="igeom") {
  2111. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2112. $loadTeacherActivity = true;
  2113. }
  2114. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2115. }
  2116. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2117. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2118. //1 $history_comment = '';
  2119. //1 if ($iassign_submission) {
  2120. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2121. //1 }
  2122. //1 if (!empty($history_comment)) {
  2123. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2124. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2125. //1 $output .= $history_comment;
  2126. //1 $output .= "</table>\n";
  2127. //1 }
  2128. //1 $output .= "</form></center>\n";
  2129. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2130. //1 }
  2131. $output .= $OUTPUT->box_end();
  2132. print $output;
  2133. } // if ($this->view_iassign)
  2134. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2135. } // if ($this->view_iassign)
  2136. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2137. else
  2138. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2139. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2140. print '<table width=100% border=0 valign="top">' . "\n";
  2141. print '<tr><td width=60% valign="top">' . "\n";
  2142. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2143. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2144. print '</tr></table>' . "\n";
  2145. $student_answer = "";
  2146. $enderecoPOST = "";
  2147. // Prepare tags to present the iLM
  2148. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2149. print $output;
  2150. }
  2151. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2152. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2153. 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
  2154. // Put a block with area to sent/answer comments
  2155. $output = '';
  2156. $history_comment = '';
  2157. $row = optional_param('row', 0, PARAM_INT);
  2158. $column = optional_param('column', 0, PARAM_INT);
  2159. if ($iassign_submission) {
  2160. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2161. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2162. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2163. }
  2164. else {
  2165. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2166. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2167. }
  2168. $output .= $OUTPUT->box_start();
  2169. //if (!empty($history_comment)) {
  2170. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2171. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2172. $output .= $history_comment;
  2173. $output .= "</table>";
  2174. print " <script type='text/javascript'>
  2175. //<![CDATA[
  2176. function submit_comment(url) {
  2177. var formData = new FormData();
  2178. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2179. var request = new XMLHttpRequest();
  2180. request.open('POST', url);
  2181. request.onload = function (e) {
  2182. if (request.readyState === 4) {
  2183. if (request.status === 200) {
  2184. alert(request.responseText);
  2185. }
  2186. }
  2187. };
  2188. request.send(formData);
  2189. }
  2190. //]]>
  2191. </script>";
  2192. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2193. $output .= "<br><p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2194. $output .= "<p><input onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2195. $output .= "</form></center>\n";
  2196. // }
  2197. $output .= $OUTPUT->box_end();
  2198. print $output;
  2199. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2200. // final block 'studant'
  2201. print $OUTPUT->footer();
  2202. die();
  2203. } // function view_iassign_current()
  2204. /// Export the data from performance report into CSV file format
  2205. function export_csv () {
  2206. global $USER, $CFG, $DB, $OUTPUT;
  2207. $str = "";
  2208. $fields = "student_id, student_name";
  2209. // Finding all iassign activities for the iassign:
  2210. $id = $this->cm->id;
  2211. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2212. $c = 1;
  2213. foreach ($iassign_list as $iassign) {
  2214. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2215. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2216. $c ++;
  2217. }
  2218. // Finding enrolled students:
  2219. $params = array('shortname' => 'student');
  2220. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2221. $context = context_course::instance($this->course->id);
  2222. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2223. $students = $DB->get_records_sql(
  2224. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2225. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2226. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2227. foreach ($students as $student) {
  2228. $str .= $student->userid . ',';
  2229. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2230. foreach ($iassign_list as $iassign) {
  2231. $str .= ',' . $iassign->id . ',';
  2232. $str .= '"' . $iassign->name . '",';
  2233. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2234. if ($student_submissions) {
  2235. $str .= $student_submissions->experiment . ',';
  2236. $str .= $student_submissions->grade . ',';
  2237. switch ($student_submissions->status) {
  2238. case 3:
  2239. $str .= '"correct",';
  2240. break;
  2241. case 2:
  2242. $str .= '"incorrect",';
  2243. break;
  2244. case 1:
  2245. $str .= '"post",';
  2246. break;
  2247. case 0:
  2248. $str .= '"not_post",';
  2249. break;
  2250. }
  2251. } else {
  2252. $str .= ',,"not_post",';
  2253. }
  2254. $str .= $iassign->iassign_ilmid . ',';
  2255. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2256. $str .= '"' . $ilm_activity->name . '"';
  2257. }
  2258. $str .= "\n";
  2259. }
  2260. $str = $fields . "\n" . $str;
  2261. header("Content-type: text/csv");
  2262. header("Content-disposition: attachment; filename=report.csv");
  2263. header("Pragma: no-cache");
  2264. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2265. header('Content-Length: ' . strlen($str));
  2266. header('Connection: close');
  2267. print $str;
  2268. flush();
  2269. } // function export_csv()
  2270. /// Display report of performance
  2271. function report () {
  2272. global $USER, $CFG, $DB, $OUTPUT;
  2273. $id = $this->cm->id;
  2274. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2275. if ($this->action != 'print') {
  2276. $title = get_string('report', 'iassign');
  2277. print $OUTPUT->header();
  2278. } // if ($this->action != 'print')
  2279. print $OUTPUT->box_start();
  2280. $this->view_legend_icons();
  2281. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2282. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2283. print $OUTPUT->box_end();
  2284. if ($this->action == 'print')
  2285. print '<table border=1 width="100%">' . "\n";
  2286. else
  2287. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2288. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2289. // $num = array();
  2290. $i = 1;
  2291. $num = array();
  2292. foreach ($iassign_list as $iassign) {
  2293. $test_exercise = "";
  2294. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2295. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2296. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2297. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2298. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2299. $num[$i] = new stdClass();
  2300. $num[$i]->name = $iassign->name;
  2301. $num[$i]->id = $i;
  2302. $num[$i]->iassignid = $iassign->id;
  2303. print ' <tr >' . "\n";
  2304. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2305. print "<td class=\"cell c0 actvity\">";
  2306. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2307. print ' </tr>' . "\n";
  2308. $i ++;
  2309. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2310. } // foreach ($iassign_list as $iassign)
  2311. print "</table>";
  2312. print "<p></p>";
  2313. if ($this->action == 'print')
  2314. print '<table border=1 width="100%">' . "\n";
  2315. else
  2316. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2317. $context = context_course::instance($this->course->id);
  2318. if ($i > 1) {
  2319. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2320. $params = array('shortname' => 'student');
  2321. $role = $DB->get_record_sql(
  2322. "SELECT s.id, s.shortname FROM {role} s " .
  2323. " WHERE s.shortname = :shortname", $params);
  2324. // $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");
  2325. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2326. $students = $DB->get_records_sql(
  2327. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2328. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2329. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2330. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2331. for ($j = 1; $j < $i; $j ++) {
  2332. $sum_iassign_correct[$j] = 0;
  2333. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2334. }
  2335. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2336. $sum_iassign = $j - 1;
  2337. print '</tr>' . "\n";
  2338. $total = 0;
  2339. $sum_student = 0;
  2340. $comment = iassign_icons::insert('comment_read');
  2341. $sum_comment = 0;
  2342. $sum_correct_iassign = array();
  2343. $sum_correct_student = array();
  2344. $USER->matrix_iassign = array();
  2345. if ($students) {
  2346. $w = 0;
  2347. foreach ($students as $tmp) {
  2348. $users_array[$w] = $tmp;
  2349. $w ++;
  2350. }
  2351. for ($x = 0; $x < $w; $x ++) {
  2352. print '<tr>' . "\n";
  2353. $sum_student ++;
  2354. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2355. print ' <td >' . $name . '</td>' . "\n";
  2356. $total_student = 0;
  2357. $tentativas = 0;
  2358. for ($j = 1; $j < $i; $j ++) {
  2359. $sum_comment = 0;
  2360. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2361. print ' <td valign="bottom" align="center">' . "\n";
  2362. if ($student_submissions) {
  2363. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2364. $tentativas = $student_submissions->experiment;
  2365. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2366. $params = array('iassign_submissionid' => $student_submissions->id);
  2367. $student_submissions_comment = $DB->get_record_sql(
  2368. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2369. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2370. if ($student_submissions_comment)
  2371. foreach ($student_submissions_comment as $tmp)
  2372. $sum_comment = $tmp;
  2373. // informations to previous activities
  2374. if ($j - 1 < 1 || $j == $i)
  2375. $iassign_previous = "-1";
  2376. else
  2377. $iassign_previous = $num[$j - 1]->iassignid;
  2378. if ($x - 1 < 0 || $x == $w)
  2379. $user_previous = "-1";
  2380. else
  2381. $user_previous = $users_array[$x - 1]->userid;
  2382. // next
  2383. if ($i - 1 > $j)
  2384. $iassign_next = $num[$j + 1]->iassignid;
  2385. else
  2386. $iassign_next = "-1";
  2387. if ($w - 1 > $x)
  2388. $user_next = $users_array[$x + 1]->userid;
  2389. else
  2390. $user_next = "-1";
  2391. $position = "&row= $x&column=$j";
  2392. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2393. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2394. $url .= $position;
  2395. // receiver=1 - message to teacher
  2396. // receiver=2 - message to student
  2397. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2398. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2399. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2400. $verify_message = $DB->get_record_sql(
  2401. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2402. "WHERE iassign_submissionid = :iassign_submissionid " .
  2403. " AND return_status= :return_status " .
  2404. " AND receiver= :receiver", $params);
  2405. if ($verify_message)
  2406. foreach ($verify_message as $tmp)
  2407. $sum_verify_message = $tmp;
  2408. if ($sum_verify_message > 0)
  2409. $comment = iassign_icons::insert('comment_unread');
  2410. else
  2411. $comment = iassign_icons::insert('comment_read');
  2412. if ($student_submissions->status == 3) {
  2413. $sum_iassign_correct[$j] ++;
  2414. $total_student ++;
  2415. $feedback = iassign_icons::insert('correct');
  2416. }
  2417. elseif ($student_submissions->status == 2) {
  2418. $feedback = iassign_icons::insert('incorrect');
  2419. }
  2420. elseif ($student_submissions->status == 1) {
  2421. $feedback = iassign_icons::insert('post');
  2422. }
  2423. elseif ($student_submissions->status == 0) {
  2424. $feedback = iassign_icons::insert('not_post');
  2425. }
  2426. if ($this->action != 'print') {
  2427. print '<table><tr>';
  2428. if ($tentativas > 0)
  2429. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2430. else
  2431. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2432. print '<td> &nbsp; </td>';
  2433. print '</tr>' . "\n";
  2434. if ($sum_comment > 0 && $sum_verify_message > 0)
  2435. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2436. else if ($sum_comment > 0)
  2437. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2438. print '</table>' . "\n";
  2439. }
  2440. if ($this->action == 'print')
  2441. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2442. } // if ($student_submissions)
  2443. else { // if ($student_submissions)
  2444. // informations to browse previous activities
  2445. if ($j - 1 < 1 || $j == $i)
  2446. $iassign_previous = "-1";
  2447. else
  2448. $iassign_previous = $num[$j - 1]->iassignid;
  2449. if ($x - 1 < 0 || $x == $w)
  2450. $user_previous = "-1";
  2451. else
  2452. $user_previous = $users_array[$x - 1]->userid;
  2453. // next
  2454. if ($i - 1 > $j)
  2455. $iassign_next = $num[$j + 1]->iassignid;
  2456. else
  2457. $iassign_next = "-1";
  2458. if ($w - 1 > $x)
  2459. $user_next = $users_array[$x + 1]->userid;
  2460. else
  2461. $user_next = "-1";
  2462. $position = "&row= $x&column=$j";
  2463. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2464. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2465. $url .= $position;
  2466. $feedback = iassign_icons::insert('not_post');
  2467. if ($this->action == 'print')
  2468. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2469. else {
  2470. print '<table><tr>';
  2471. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2472. print '<td> &nbsp; </td>';
  2473. print '</tr><tr>' . "\n";
  2474. print '<td> &nbsp;</td>';
  2475. if ($sum_comment > 0)
  2476. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2477. else
  2478. print '<td> &nbsp;</td>';
  2479. print '</tr></table>';
  2480. }
  2481. } // else if ($student_submissions)
  2482. $USER->matrix_iassign[$x][$j] = new stdClass();
  2483. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2484. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2485. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2486. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2487. if ($student_submissions)
  2488. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2489. else
  2490. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2491. print '</td>' . "\n";
  2492. } // for ($j=1; $j<$i; $j++)
  2493. $total = $total + $total_student;
  2494. $porcentagem = ($total_student / ($j - 1)) * 100;
  2495. if ($tentativas != 0 && $tentativas != null) {
  2496. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2497. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2498. }
  2499. else {
  2500. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2501. }
  2502. print '</tr>' . "\n";
  2503. $sum_correct_student[$sum_student] = new stdClass();
  2504. $sum_correct_student[$sum_student]->name = $name;
  2505. $sum_correct_student[$sum_student]->sum = $total_student;
  2506. } // for ($x = 0; $x < $w; $x ++)
  2507. for ($i = 1; $i < $j; $i ++) {
  2508. if (is_null($sum_iassign_correct[$i]))
  2509. $sum_iassign_correct[$i] = 0;
  2510. $sum_correct_iassign[$i] = new stdClass();
  2511. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2512. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2513. }
  2514. // print '</tr></table>' . "\n";
  2515. }
  2516. } // if ($i>1)
  2517. else {
  2518. print_string('no_activity', 'iassign');
  2519. }
  2520. print "</table>\n";
  2521. if ($this->action != 'print')
  2522. print $OUTPUT->footer();
  2523. die();
  2524. } // function report()
  2525. /// Display graphics of performance
  2526. function stats () {
  2527. global $USER, $CFG, $DB, $OUTPUT;
  2528. $id = $this->cm->id;
  2529. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2530. if ($this->action != 'printstats')
  2531. $title = get_string('graphic', 'iassign');
  2532. $num = array();
  2533. $sum_correct_iassign = array();
  2534. $sum_correct_student = array();
  2535. $sum_student = 0;
  2536. $i = 1;
  2537. foreach ($iassign_list as $iassign) {
  2538. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2539. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2540. $sum_iassign_correct[$i] = 0;
  2541. $num[$i] = new stdClass();
  2542. $num[$i]->name = $iassign->name;
  2543. $num[$i]->id = $i;
  2544. $num[$i]->iassignid = $iassign->id;
  2545. $i ++;
  2546. } // if ($iassign->type_iassign == 3)
  2547. } // foreach ($iassign_list as $iassign)
  2548. $sum_iassign = $i - 1;
  2549. $context = context_course::instance($this->course->id);
  2550. if ($i > 1) {
  2551. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2552. $params = array('shortname' => 'student');
  2553. $role = $DB->get_record_sql(
  2554. "SELECT s.id, s.shortname FROM {role} s " .
  2555. " WHERE s.shortname = :shortname", $params);
  2556. // $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");
  2557. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2558. $students = $DB->get_records_sql(
  2559. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2560. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2561. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2562. $total = 0;
  2563. $sum_student = 0;
  2564. $j = 0;
  2565. $sum_correct_iassign = array();
  2566. $sum_correct_student = array();
  2567. $sum_experiment = array();
  2568. if ($students) {
  2569. foreach ($students as $users) {
  2570. $sum_student ++;
  2571. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2572. // rows
  2573. $total_student = 0;
  2574. for ($j = 1; $j < $i; $j ++) {
  2575. $total_experiment = 0;
  2576. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2577. if ($student_submissions) {
  2578. if ($student_submissions->status == 3) {
  2579. $sum_iassign_correct[$j] ++;
  2580. $total_student ++;
  2581. } // if ($student_submissions->status == 3)
  2582. $total_experiment += $student_submissions->experiment;
  2583. }
  2584. $sum_experiment[$j] = $total_experiment;
  2585. } // for ($j=1; $j<$i; $j++)
  2586. $total = $total + $total_student;
  2587. $sum_correct_student[$sum_student] = new stdClass();
  2588. $sum_correct_student[$sum_student]->name = $name;
  2589. $sum_correct_student[$sum_student]->sum = $total_student;
  2590. } // foreach ($students as $users)
  2591. }
  2592. for ($i = 1; $i < $j; $i ++) {
  2593. if (is_null($sum_iassign_correct[$i]))
  2594. $sum_iassign_correct[$i] = 0;
  2595. $sum_correct_iassign[$i] = new stdClass();
  2596. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2597. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2598. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2599. } // for ($i = 1; $i < $j; $i++)
  2600. } // if ($i > 1)
  2601. if ($this->action != 'printstats') {
  2602. $title = get_string('graphic', 'iassign');
  2603. print $OUTPUT->header();
  2604. $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>";
  2605. $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>";
  2606. print '<table width=100%><tr>';
  2607. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2608. print '<td width=15% align="right">' . $link_report . '</td>';
  2609. print '</td></tr></table>' . "\n";
  2610. print "<br><br>";
  2611. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2612. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2613. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2614. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2615. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2616. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2617. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2618. print '</tr>' . "\n";
  2619. $sum_correct = 0;
  2620. if ($sum_correct_iassign) {
  2621. foreach ($sum_correct_iassign as $iassign) {
  2622. if (is_null($iassign->experiment))
  2623. $iassign->experiment = 0;
  2624. $bar = "";
  2625. $sum = $iassign->sum;
  2626. $percent = ($sum / $sum_student) * 100;
  2627. $text = number_format($percent, 1) . '%';
  2628. $sum_correct += $sum;
  2629. if ($sum > 0) {
  2630. for ($i = 1; $i < $percent * 2; $i ++)
  2631. $bar .= iassign_icons::insert('hbar_blue');
  2632. $bar .= iassign_icons::insert('hbar_blue_r');
  2633. } // if ($sum > 0)
  2634. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2635. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2636. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2637. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2638. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2639. print '</tr>' . "\n";
  2640. } // foreach ($sum_correct_iassign as $iassign)
  2641. }
  2642. print "</table>";
  2643. print "<br><br>";
  2644. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2645. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2646. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2647. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2648. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2649. print '</tr>' . "\n";
  2650. $sum_correct = 0;
  2651. foreach ($sum_correct_student as $student) {
  2652. $bar = "";
  2653. $sum = $student->sum;
  2654. $percent = ($sum / $sum_iassign) * 100;
  2655. $text = number_format($percent, 1) . '%';
  2656. $sum_correct += $sum;
  2657. if ($sum > 0) {
  2658. for ($i = 1; $i < $percent * 2; $i ++)
  2659. $bar .= iassign_icons::insert('hbar_blue');
  2660. $bar .= iassign_icons::insert('hbar_blue_r');
  2661. } // if ($sum > 0)
  2662. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2663. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2664. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2665. print '</tr>' . "\n";
  2666. } // foreach ($sum_correct_student as $student)
  2667. print "</table>\n";
  2668. print "<br><br>\n";
  2669. $var = 0;
  2670. $cv = 0;
  2671. $dv = 0;
  2672. $avg = 0;
  2673. if ($sum_correct_student) {
  2674. $avg = $sum_correct / $sum_student;
  2675. if ($avg > 0) {
  2676. foreach ($sum_correct_student as $student)
  2677. $var += pow($student->sum - $avg, 2);
  2678. $var = $var / $sum_student;
  2679. $dv = sqrt($var);
  2680. $cv = ($dv / $avg) * 100;
  2681. }
  2682. }
  2683. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2684. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2685. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2686. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2687. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2688. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2689. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2690. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2691. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2692. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2693. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2694. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2695. print "</table>\n";
  2696. print $OUTPUT->footer();
  2697. } else {
  2698. print "<STYLE TYPE='text/css'>
  2699. <!--
  2700. .boldtable {
  2701. font-family:sans-serif;
  2702. font-size:10pt;
  2703. }
  2704. -->
  2705. </STYLE>\n";
  2706. print '<table border=1 width=100%>' . "\n";
  2707. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2708. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2709. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2710. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2711. print '</tr>' . "\n";
  2712. $sum_correct = 0;
  2713. foreach ($sum_correct_iassign as $iassign) {
  2714. $bar = "";
  2715. $sum = $iassign->sum;
  2716. $percent = ($sum / $sum_student) * 100;
  2717. $text = number_format($percent, 1) . '%';
  2718. $sum_correct += $sum;
  2719. if ($sum > 0) {
  2720. for ($i = 1; $i < $percent * 2; $i ++)
  2721. $bar .= iassign_icons::insert('hbar_blue');
  2722. $bar .= iassign_icons::insert('hbar_blue_r');
  2723. } // if ($sum > 0)
  2724. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2725. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2726. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2727. print '</tr>' . "\n";
  2728. } // foreach ($sum_correct_iassign as $iassign)
  2729. print "</table>";
  2730. print "<br><br>";
  2731. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2732. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2733. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2734. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2735. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2736. print '</tr>' . "\n";
  2737. $sum_correct = 0;
  2738. foreach ($sum_correct_student as $student) {
  2739. $bar = "";
  2740. $sum = $student->sum;
  2741. $percent = ($sum / $sum_iassign) * 100;
  2742. $text = number_format($percent, 1) . '%';
  2743. $sum_correct += $sum;
  2744. if ($sum > 0) {
  2745. for ($i = 1; $i < $percent * 2; $i ++)
  2746. $bar .= iassign_icons::insert('hbar_blue');
  2747. $bar .= iassign_icons::insert('hbar_blue_r');
  2748. } // if ($sum > 0)
  2749. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2750. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2751. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2752. print '</tr>' . "\n";
  2753. } // foreach ($sum_correct_student as $student)
  2754. print "</table>\n";
  2755. print "<br/><br/>\n";
  2756. $var = 0;
  2757. $cv = 0;
  2758. $dv = 0;
  2759. $avg = 0;
  2760. if ($sum_correct_student) {
  2761. $avg = $sum_correct / $sum_student;
  2762. if ($avg > 0) {
  2763. foreach ($sum_correct_student as $student)
  2764. $var += pow($student->sum - $avg, 2);
  2765. $var = $var / $sum_student;
  2766. $dv = sqrt($var);
  2767. $cv = ($dv / $avg) * 100;
  2768. }
  2769. }
  2770. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2771. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2772. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2773. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2774. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2775. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2776. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2777. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2778. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2779. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2780. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2781. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2782. print "</table>\n";
  2783. } // if ($this->action != 'printstats')
  2784. die();
  2785. }
  2786. /// Display graphics of performance for students
  2787. function stats_students () {
  2788. global $USER, $CFG, $DB, $OUTPUT;
  2789. $id = $this->cm->id;
  2790. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2791. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2792. $title = get_string('results', 'iassign');
  2793. $sum_correct = 0;
  2794. $sum_incorrect = 0;
  2795. $sum_post = 0;
  2796. $sum_nopost = 0;
  2797. $sum_iassign = count($iassign_statement_list);
  2798. $bar_nopost = "";
  2799. $bar_correct = "";
  2800. $bar_incorrect = "";
  2801. $bar_post = "";
  2802. $text_nopost = "";
  2803. $text_correct = "";
  2804. $text_incorrect = "";
  2805. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2806. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2807. if ($iassign_submission) {
  2808. if ($iassign_submission->status == 3)
  2809. $sum_correct ++;
  2810. elseif ($iassign_submission->status == 2)
  2811. $sum_incorrect ++;
  2812. elseif ($iassign_submission->status == 1)
  2813. $sum_post ++;
  2814. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2815. $sum_nopost ++;
  2816. } // if ($iassign_submission)
  2817. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2818. if ($sum_iassign > 0) {
  2819. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2820. $text_correct = number_format($percent_correct, 1) . '%';
  2821. }
  2822. if ($sum_correct > 0) {
  2823. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2824. $bar_correct .= iassign_icons::insert('hbar_green');
  2825. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2826. } // if ($sum_correct > 0)
  2827. if ($sum_iassign > 0) {
  2828. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2829. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2830. }
  2831. if ($sum_incorrect > 0) {
  2832. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2833. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2834. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2835. } // if ($sum_incorrect > 0)
  2836. if ($sum_iassign > 0) {
  2837. $percent_post = ($sum_post / $sum_iassign) * 100;
  2838. $text_post = number_format($percent_post, 1) . '%';
  2839. }
  2840. if ($sum_post > 0) {
  2841. for ($i = 1; $i < $percent_post * 2; $i ++)
  2842. $bar_post .= iassign_icons::insert('hbar_blue');
  2843. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2844. } // if ($sum_post > 0)
  2845. if ($sum_iassign > 0) {
  2846. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2847. $text_nopost = number_format($percent_nopost, 1) . '%';
  2848. }
  2849. if ($sum_nopost > 0) {
  2850. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2851. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2852. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2853. } // if ($sum_nopost > 0)
  2854. print $OUTPUT->header();
  2855. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2856. print '<table width=100%><tr>';
  2857. print '<td align="right">' . $link_return . '</td>' . "\n";
  2858. print '</td></tr></table>' . "\n";
  2859. print "<br/><br/>\n";
  2860. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2861. print '<tr><th colspan=3 class="header c1">' . "\n";
  2862. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2863. // $imagetext = '');
  2864. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2865. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2866. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2867. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2868. print '</tr>' . "\n";
  2869. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2870. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2871. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2872. print '</tr>' . "\n";
  2873. if ($sum_post) {
  2874. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2875. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2876. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2877. print '</tr>' . "\n";
  2878. } // if ($sum_post)
  2879. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2880. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2881. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2882. print '</tr>' . "\n";
  2883. print "</table>";
  2884. print "<br><br>";
  2885. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2886. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2887. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2888. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2889. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2890. $sum_grade = 0;
  2891. $sum_grade_student = 0;
  2892. $avg = 0;
  2893. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2894. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2895. if (!$iassign_submission) {
  2896. $iassign_submission = new stdClass();
  2897. $iassign_submission->grade = 0;
  2898. }
  2899. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2900. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2901. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2902. print '</tr>' . "\n";
  2903. $sum_grade += $iassign_statement_activity_item->grade;
  2904. $sum_grade_student += $iassign_submission->grade;
  2905. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2906. if ($sum_grade > 0)
  2907. $avg = $sum_grade_student / $sum_grade * 100;
  2908. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2909. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2910. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2911. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2912. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2913. print "</table>";
  2914. print $OUTPUT->footer();
  2915. die();
  2916. } // function stats_students()
  2917. /// Display page of iAssign's activity
  2918. function view_iassigns () {
  2919. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2920. $id = $this->cm->id;
  2921. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2922. $notice = optional_param('notice', '', PARAM_TEXT);
  2923. if (strpos($notice, 'error'))
  2924. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2925. else if ($notice != '')
  2926. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2927. print $OUTPUT->box_start();
  2928. print '<table width=100% border=0><tr>' . "\n";
  2929. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2930. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2931. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2932. $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>";
  2933. $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>";
  2934. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2935. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2936. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2937. // Has capability to see "report": teacher or up
  2938. print '<td width=10% align="left">' . "\n";
  2939. print $link_help;
  2940. print '</td>' . "\n";
  2941. print '<td width=10% align="left">' . "\n";
  2942. print $link_report;
  2943. print '</td>' . "\n";
  2944. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2945. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2946. print '<td width=15% align="left">' . "\n";
  2947. print $link_add;
  2948. print "</td>\n";
  2949. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2950. //print '</tr></table>' . "\n";
  2951. print '<div style="float: right;">';
  2952. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2953. if ($iassign_list) {
  2954. print '<td align="right">' . "\n";
  2955. // $USER->iassignEdit == 0 view 'Turn editing off'
  2956. // $USER->iassignEdit == 1 view 'Turn editing on'
  2957. if (!isset($USER->iassignEdit))
  2958. $USER->iassignEdit = 0;
  2959. if ($USER->iassignEdit == 0) {
  2960. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2961. $botton = 1;
  2962. } // if ($USER->iassignEdit == 0)
  2963. elseif ($USER->iassignEdit == 1) {
  2964. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2965. $botton = 0;
  2966. } // elseif ($USER->iassignEdit == 1)
  2967. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2968. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2969. print " <input type=submit value='$bottonEdit_message'/>\n";
  2970. print "</form>\n";
  2971. print "</td>\n";
  2972. } // if ($iassign_list)
  2973. }
  2974. print '</tr></table>' . "\n";
  2975. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2976. // $this->view_legend_icons();
  2977. print $OUTPUT->box_end();
  2978. $iassign_array_exercise = array();
  2979. $i_exercise = 0;
  2980. $iassign_array_test = array();
  2981. $i_test = 0;
  2982. $iassign_array_example = array();
  2983. $i_example = 0;
  2984. $iassign_array_general = array();
  2985. $i_general = 0;
  2986. if ($iassign_list) {
  2987. if ($this->iassign->activity_group == 0) {
  2988. foreach ($iassign_list as $iassign) {
  2989. $iassign_array_general[$i_general] = $iassign;
  2990. $i_general ++;
  2991. }
  2992. } // if ($this->iassign->activity_group == 0)
  2993. else {
  2994. foreach ($iassign_list as $iassign) {
  2995. if ($iassign->type_iassign == 3) {
  2996. $iassign_array_exercise[$i_exercise] = $iassign;
  2997. $i_exercise ++;
  2998. } // if ($iassign->type_iassign == 3)
  2999. if ($iassign->type_iassign == 2) {
  3000. $iassign_array_test[$i_test] = $iassign;
  3001. $i_test ++;
  3002. } // if ($iassign->type_iassign == 2)
  3003. if ($iassign->type_iassign == 1) {
  3004. $iassign_array_example[$i_example] = $iassign;
  3005. $i_example ++;
  3006. } // if ($iassign->type_iassign == 1)
  3007. }
  3008. }
  3009. if ($iassign_array_exercise) {
  3010. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3011. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3012. }
  3013. if ($iassign_array_test) {
  3014. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3015. $this->show_iassign($title, $iassign_array_test, $i_test);
  3016. }
  3017. if ($iassign_array_example) {
  3018. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3019. $this->show_iassign($title, $iassign_array_example, $i_example);
  3020. }
  3021. if ($iassign_array_general) {
  3022. $title = "";
  3023. $this->show_iassign($title, $iassign_array_general, $i_general);
  3024. }
  3025. } else { // if ($iassign_list)
  3026. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3027. }
  3028. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3029. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3030. print $OUTPUT->box_start();
  3031. print '<table width=100% border=0><tr>' . "\n";
  3032. print '<td width=10% align="left">' . "\n";
  3033. print $link_report;
  3034. print '</td>' . "\n";
  3035. print '</tr></table>' . "\n";
  3036. print $OUTPUT->box_end();
  3037. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3038. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3039. print $OUTPUT->box_start();
  3040. print '<table width=100% border=0><tr>' . "\n";
  3041. print '<td align="left">' . "\n";
  3042. print $link_add;
  3043. print '</td>' . "\n";
  3044. print '</tr></table>' . "\n";
  3045. print $OUTPUT->box_end();
  3046. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3047. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3048. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3049. $this->view_legend_icons();
  3050. } // function view_iassigns()
  3051. /// Display all iAssigns
  3052. function show_iassign ($title, $iassign_array, $i) {
  3053. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3054. $id = $this->cm->id;
  3055. print $OUTPUT->box_start();
  3056. print " <script type='text/javascript'>
  3057. //<![CDATA[
  3058. function validate_move () {
  3059. var radios = document.getElementsByName('iassign_destiny');
  3060. var formValid = false;
  3061. //alert('aqui validate_move()');
  3062. var i = 0;
  3063. while (!formValid && i < radios.length) {
  3064. if (radios[i].checked) formValid = true;
  3065. i++;
  3066. }
  3067. if (!formValid) {
  3068. document.getElementById('move_dest').classList.add('alert-danger');
  3069. }
  3070. return formValid;
  3071. }
  3072. var modal;
  3073. function load_move(id_ias) {
  3074. document.form_move_activity.iassign_current.value = id_ias;
  3075. modal.style.display = 'block';
  3076. var radios = document.getElementsByName('iassign_destiny');
  3077. var i = 0;
  3078. while (i < radios.length) {
  3079. radios[i].checked = false;
  3080. i++;
  3081. }
  3082. document.getElementById('move_dest').classList.remove('alert-danger');
  3083. }
  3084. function load_modal_elements() {
  3085. modal = document.getElementById('myModal');
  3086. var span = document.getElementById('close_modal');
  3087. span.onclick = function() {
  3088. modal.style.display = 'none';
  3089. }
  3090. window.onclick = function(event) {
  3091. if (event.target == modal) {
  3092. modal.style.display = 'none';
  3093. }
  3094. }
  3095. }
  3096. window.onload = load_modal_elements;
  3097. //]]>
  3098. </script>\n";
  3099. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3100. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3101. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3102. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3103. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3104. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3105. <input type='hidden' name='iassign_current' value='' />";
  3106. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3107. $section = $course_sections[0];
  3108. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3109. for ($k = 0; $k < count($ids_sections); $k++) {
  3110. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3111. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3112. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3113. if ($c_cm) {
  3114. if ($ccm->instance == $c_cm->instance) {
  3115. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3116. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3117. }
  3118. else {
  3119. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3120. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3121. }
  3122. }
  3123. }
  3124. $radio_buttons .= "</ul>";
  3125. }
  3126. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3127. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3128. </form>
  3129. </div></div> </div></div>\n";
  3130. print " <style>.modal {
  3131. display: none;
  3132. position: fixed;
  3133. z-index: 1;
  3134. left: 0;
  3135. top: 0;
  3136. width: 100%;
  3137. height: 100%;
  3138. overflow: scroll;
  3139. background-color: rgb(0,0,0);
  3140. background-color: rgba(0,0,0,0.4);
  3141. }
  3142. .modal-content {
  3143. background-color: #fefefe;
  3144. margin: 15% auto;
  3145. padding: 10px 10px;
  3146. border: 1px solid #888;
  3147. width: 50%;
  3148. }
  3149. #close_modal {
  3150. color: #aaa;
  3151. float: right;
  3152. font-size: 28px;
  3153. font-weight: bold;
  3154. margin-top: -15px;
  3155. margin-right: -3px;
  3156. }
  3157. #close_modal:hover,
  3158. #close_modal:focus {
  3159. color: black;
  3160. text-decoration: none;
  3161. cursor: pointer;
  3162. }
  3163. #modal_title {
  3164. min-height: 3rem;
  3165. color: initial;
  3166. background: initial;
  3167. font-size: 1.5rem;
  3168. line-height: 1.5;
  3169. padding: 15px;
  3170. border-bottom: 1px solid #e5e5e5;
  3171. }
  3172. .input_move {
  3173. width: 90%;
  3174. padding: 2px;
  3175. }
  3176. .input_move:hover {
  3177. background: #eff0ef;
  3178. }
  3179. </style>";
  3180. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3181. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3182. for ($j = 0; $j < $i; $j ++) {
  3183. $iassign_current = $iassign_array[$j]->id;
  3184. // receiver=1 - message to teacher
  3185. // receiver=2 - message to student
  3186. $sum_comment = 0;
  3187. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3188. foreach ($iassign_submissions as $iassign_submission) {
  3189. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3190. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3191. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3192. if ($verify_message)
  3193. foreach ($verify_message as $tmp)
  3194. $sum_comment += $tmp;
  3195. } // foreach ($iassign_submissions as $iassign_submission)
  3196. if ($sum_comment == 0)
  3197. $comment_unread = "";
  3198. else {
  3199. $comment_unread_message = get_string('comment_unread', 'iassign');
  3200. if ($sum_comment == 1)
  3201. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3202. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3203. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3204. }
  3205. if ($j == $i - 1)
  3206. $iassign_down = $iassign_array[$j]->id;
  3207. else
  3208. $iassign_down = $iassign_array[$j + 1]->id;
  3209. if ($j > 0)
  3210. $iassign_up = $iassign_array[$j - 1]->id;
  3211. else
  3212. $iassign_up = $iassign_array[$j]->id;
  3213. if ($iassign_array[$j]->visible == 0)
  3214. $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>";
  3215. else
  3216. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3217. $links .= $comment_unread;
  3218. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3219. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3220. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3221. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3222. if ($j==0) // first activity
  3223. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3224. else
  3225. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3226. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3227. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3228. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3229. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3230. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3231. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3232. if (count($iassign_array) > 1) {
  3233. if ($j == 0)
  3234. $links .= $link_down;
  3235. elseif ($j == $i - 1)
  3236. $links .= $link_up;
  3237. else
  3238. $links .= $link_up . $link_down;
  3239. } // if (count($iassign_array) > 1)
  3240. $links .= $link_edit . $link_delete;
  3241. if ($iassign_array[$j]->visible == 0)
  3242. $links .= $link_visible_show;
  3243. else
  3244. $links .= $link_visible_hide;
  3245. $links .= $link_duplicate_activity . $link_move_activity;
  3246. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3247. print '<p>' . $links . '</p>' . "\n";
  3248. }
  3249. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3250. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3251. print '<table width=100% ><tr>' . "\n";
  3252. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3253. print '</tr></table>' . "\n";
  3254. for ($j = 0; $j < $i; $j ++) {
  3255. $icon_status = "";
  3256. $icon_comment = "";
  3257. if ($iassign_array[$j]->visible == 1) {
  3258. $iassign_current = $iassign_array[$j]->id;
  3259. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3260. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3261. $icon_status = "";
  3262. $icon_comment = "";
  3263. if ($iassign_submission) {
  3264. // receiver=1 - message to teacher
  3265. // receiver=2 - message to student
  3266. // $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");
  3267. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3268. $verify_message = $DB->get_record_sql(
  3269. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3270. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3271. if ($verify_message)
  3272. foreach ($verify_message as $tmp)
  3273. $sum_comment = $tmp;
  3274. if ($sum_comment > 0) {
  3275. $comment_unread_message = get_string('comment_unread', 'iassign');
  3276. if ($sum_comment == 1)
  3277. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3278. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3279. }
  3280. // $icon_comment = iassign_icons::insert('comment_unread');
  3281. if ($iassign_array[$j]->type_iassign == 3) {
  3282. if ($iassign_array[$j]->show_answer == 1) {
  3283. if ($iassign_submission->status == 3)
  3284. $icon_status = iassign_icons::insert('correct');
  3285. elseif ($iassign_submission->status == 2)
  3286. $icon_status = iassign_icons::insert('incorrect');
  3287. elseif ($iassign_submission->status == 1)
  3288. $icon_status = iassign_icons::insert('post');
  3289. elseif ($iassign_submission->status == 0)
  3290. $icon_status = iassign_icons::insert('not_post');
  3291. } // if ($iassign_array[$j]->show_answer==1)
  3292. else {
  3293. if ($iassign_submission->status == 0)
  3294. $icon_status = iassign_icons::insert('not_post');
  3295. else
  3296. $icon_status = iassign_icons::insert('post');
  3297. }
  3298. } // if ($iassign_array[$j]->type_iassign == 3)
  3299. } // if ($iassign_submission)
  3300. elseif ($iassign_array[$j]->type_iassign == 3) {
  3301. $icon_status = iassign_icons::insert('not_post');
  3302. } // if ($iassign_array[$j]->type_iassign == 3)
  3303. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3304. } // if ($iassign_array[$j]->visible == 1)
  3305. } // for ($j = 0; $j < $i; $j++)
  3306. } else if (isguestuser()) {
  3307. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3308. print '<table width=100% ><tr>' . "\n";
  3309. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3310. print '</tr></table>' . "\n";
  3311. for ($j = 0; $j < $i; $j ++) {
  3312. $icon_status = "";
  3313. $icon_comment = "";
  3314. if ($iassign_array[$j]->visible == 1) {
  3315. $iassign_current = $iassign_array[$j]->id;
  3316. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3317. print '<p>' . $links . '</p>' . "\n";
  3318. } // if ($iassign_array[$j]->visible == 1)
  3319. }
  3320. }
  3321. print $OUTPUT->box_end();
  3322. } // function show_iassign($title, $iassign_array, $i)
  3323. /// Show message of return
  3324. function return_home_course ($message) {
  3325. //D global $DB, $OUTPUT;
  3326. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3327. //D echo $OUTPUT->box_start();
  3328. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3329. //D echo '<tr><td align="left"><strong>' . "\n";
  3330. //D print_string($message, 'iassign');
  3331. //D echo '</strong></td>' . "\n";
  3332. //D echo '<td width=20% align="right">' . "\n";
  3333. //D echo $link_return;
  3334. //D echo '</td></tr></table>' . "\n";
  3335. //D echo $OUTPUT->box_end();
  3336. //D // echo $OUTPUT->footer();
  3337. redirect(new moodle_url($this->return . '&notice=' . $message));
  3338. exit;
  3339. }
  3340. /// Search comment of activity
  3341. function search_comment_submission ($iassign_submissionid) {
  3342. global $USER, $DB, $OUTPUT, $COURSE;
  3343. // $context = context_course::instance($COURSE->id);
  3344. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3345. $colorEdit2 = "#b7ceee";
  3346. $has_capability = 0;
  3347. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3348. $text = "";
  3349. if ($comments) {
  3350. $even = 1;
  3351. foreach ($comments as $tmp) {
  3352. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3353. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3354. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3355. // $text .= $tmp->comment . "</td></tr>";
  3356. //} else {
  3357. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3358. if ($even) {
  3359. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3360. $even = 0;
  3361. } else {
  3362. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3363. $even = 1;
  3364. }
  3365. $text .= $tmp->comment . "</td></tr>\n";
  3366. } // foreach ($comments as $tmp)
  3367. }
  3368. return $text;
  3369. }
  3370. /// Update comment of activity
  3371. function update_comment ($iassign_submissionid) {
  3372. global $USER, $DB, $OUTPUT;
  3373. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3374. $receiver = 1; // student message to teacher
  3375. else
  3376. $receiver = 2; // teacher message to student
  3377. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3378. if ($verify_message) {
  3379. foreach ($verify_message as $message) {
  3380. if ($message->receiver == $receiver) {
  3381. $newentry = new stdClass();
  3382. $newentry->id = $message->id;
  3383. $newentry->return_status = 1;
  3384. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3385. print_error('error_update', 'iassign');
  3386. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3387. } // if ($message->receiver == $receiver)
  3388. // Trigger module viewed event.
  3389. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3390. 'objectid' => $this->iassign->id,
  3391. 'context' => $this->context
  3392. ));
  3393. $event->add_record_snapshot('course', $this->course);
  3394. $event->trigger();
  3395. } // foreach ($verify_message as $message)
  3396. }
  3397. }
  3398. /// Record comment of activity
  3399. function write_comment_submission () {
  3400. global $USER, $CFG, $DB;
  3401. $id = $this->cm->id;
  3402. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3403. $row = optional_param('row', 0, PARAM_INT);
  3404. $column = optional_param('column', 0, PARAM_INT);
  3405. $sum_comment = 0;
  3406. $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);
  3407. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3408. $str1 = trim($submission_comment);
  3409. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3410. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3411. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3412. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3413. $receiver = 1; // student message to teacher
  3414. $this->action = 'view';
  3415. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3416. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3417. } else {
  3418. $receiver = 2; // teacher message to student
  3419. $this->action = 'viewsubmission';
  3420. //D $tousers = array(); //MOOC 2016
  3421. //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
  3422. }
  3423. //MOOC 2016: foi p/ 15 linhas acima:
  3424. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3425. if (!$iassign_submission) {
  3426. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3427. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3428. $this->iassign_submission_current = $id_submission;
  3429. } else {
  3430. $id_submission = $iassign_submission->id;
  3431. } // if (!$iassign_submission)
  3432. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3433. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3434. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3435. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3436. $comments = $DB->get_record_sql(
  3437. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3438. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3439. if ($comments)
  3440. foreach ($comments as $tmp)
  3441. $sum_comment = $tmp;
  3442. if ($sum_comment == 0) {
  3443. $newentry = new stdClass();
  3444. $newentry->iassign_submissionid = $id_submission;
  3445. $newentry->comment_authorid = $USER->id;
  3446. $newentry->timecreated = time();
  3447. $newentry->comment = $submission_comment;
  3448. $newentry->receiver = $receiver;
  3449. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3450. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3451. //T $eventdata = new stdClass();
  3452. //T $eventdata->component = 'mod_iassign'; //your component name
  3453. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3454. //T $eventdata->userfrom = $USER;
  3455. //T $eventdata->userto = $touser;
  3456. //T $eventdata->subject = "Teste de Subject";
  3457. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3458. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3459. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3460. //T $eventdata->smallmessage = "Teste de Mensagem";
  3461. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3462. //T // alteracao tulio faria
  3463. //T //message_send($eventdata);
  3464. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3465. // Trigger module viewed event.
  3466. $event = \mod_iassign\event\submission_comment_created::create(array(
  3467. 'objectid' => $this->iassign->id,
  3468. 'context' => $this->context
  3469. ));
  3470. $event->add_record_snapshot('course', $this->course);
  3471. $event->trigger();
  3472. }
  3473. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3474. // if ($this->action=='viewsubmission') {
  3475. // echo $OUTPUT->header();
  3476. // $this->return_last('confirm_add_comment', $link_return);
  3477. // die;
  3478. // }
  3479. return true;
  3480. } // function write_comment_submission()
  3481. /// Writes a new submission
  3482. // The first student answer is under 'function get_answer()'
  3483. function new_submission ($iassignid, $id_user, $receiver) {
  3484. global $USER, $DB, $OUTPUT;
  3485. $newentry = new stdClass();
  3486. $newentry->iassign_statementid = $iassignid;
  3487. $newentry->userid = $id_user;
  3488. $newentry->timecreated = time();
  3489. $newentry->timemodified = time();
  3490. $newentry->answer = 0; // student only submit message
  3491. if ($receiver == 2) // teacher message to student (write id teacher)
  3492. $newentry->teacher = $USER->id;
  3493. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3494. return_home_course('error_insert_submissions');
  3495. else {
  3496. // Trigger module view event
  3497. $event = \mod_iassign\event\submission_created::create(array(
  3498. 'objectid' => $this->iassign->id,
  3499. 'context' => $this->context
  3500. ));
  3501. $event->add_record_snapshot('course', $this->course);
  3502. $event->trigger();
  3503. }
  3504. return $newentry->id;
  3505. }
  3506. /// Return to a specific address of page
  3507. function return_last ($message, $link_return) {
  3508. global $DB, $OUTPUT;
  3509. print $OUTPUT->box_start();
  3510. print '<table width=100% border=0 valign="top">' . "\n";
  3511. print '<tr><td align="left"><strong>' . "\n";
  3512. print_string($message, 'iassign');
  3513. print '</strong></td>' . "\n";
  3514. print '<td width=20% align="right">' . "\n";
  3515. print $link_return;
  3516. print '</td></tr></table>' . "\n";
  3517. print $OUTPUT->box_end();
  3518. print $OUTPUT->footer();
  3519. die();
  3520. } // function return_last($message, $link_return)
  3521. } // class iassign
  3522. /// Class for manage activities
  3523. class activity {
  3524. var $activity;
  3525. /// Constructor of class.
  3526. // @param int $id Id of activity
  3527. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3528. //D public function activity($id) { self::__construct($id); }
  3529. function __construct ($id) {
  3530. global $DB;
  3531. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3532. if (empty($this->activity))
  3533. $this->activity = null;
  3534. }
  3535. /// Get an activity
  3536. // @return NULL
  3537. function get_activity () {
  3538. if ($this->activity != null)
  3539. return $this->activity;
  3540. else
  3541. return null;
  3542. }
  3543. /// Delete interactive activities
  3544. function delete ($return) {
  3545. global $USER, $CFG, $DB, $OUTPUT;
  3546. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3547. $output = $OUTPUT->header();
  3548. $output .= $OUTPUT->box_start();
  3549. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3550. if ($iassign_submission_currents) {
  3551. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3552. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3553. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3554. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3555. $output .= $OUTPUT->box_end();
  3556. $output .= $OUTPUT->footer();
  3557. print $output;
  3558. die();
  3559. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3560. } // if ($iassign_submission_currents)
  3561. else
  3562. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3563. $output .= '<table width=50% border=0>';
  3564. $output .= '<tr valign="top"><td>';
  3565. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3566. $output .= '</td><td>';
  3567. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3568. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3569. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3570. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3571. $output .= "</form>\n";
  3572. $output .= '</td><td>';
  3573. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3574. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3575. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3576. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3577. $output .= "</form>\n";
  3578. $output .= '</td></tr></table>' . "\n";
  3579. $output .= $OUTPUT->box_end();
  3580. $output .= $OUTPUT->footer();
  3581. print $output;
  3582. } // function delete($return)
  3583. /// Function for confirm the delete of activity
  3584. // @param String $return Url of return
  3585. // @param Object $iassign Object content an activity
  3586. function deleteyes ($return, $iassign) {
  3587. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3588. $msg = '';
  3589. if (!empty($this->activity->id)) {
  3590. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3591. if ($iassign_submission_currents) {
  3592. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3593. foreach ($iassign_submission_currents as $iassign_submission)
  3594. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3595. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3596. } // if ($iassign_submission_currents)
  3597. }
  3598. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3599. // Remove all files associated to this activity:
  3600. $fs = get_file_storage();
  3601. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3602. $this->delete_calendar($this->activity->id);
  3603. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3604. iassign::update_grade_iassign($this->activity->iassignid);
  3605. if ($delete_iassign_current) {
  3606. $iassign->return_home_course('confirm_delete_iassign');
  3607. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3608. } else {
  3609. $iassign->return_home_course('error_confirm_delete_iassign');
  3610. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3611. }
  3612. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3613. }
  3614. }
  3615. /// Changes position of activities (between those inside a group of interactive activities)
  3616. // @param $move_action = must be "up" or "down"
  3617. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3618. function move_iassign ($move_action, $target, $return) {
  3619. global $DB, $OUTPUT;
  3620. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3621. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3622. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3623. if ($move_action=="firstdown") {
  3624. $final_position_source = 2;
  3625. $final_position_target = 1;
  3626. }
  3627. else
  3628. if ($move_action=="down") {
  3629. $final_position_target = $this->activity->position;
  3630. $final_position_source = $final_position_target + 1;
  3631. }
  3632. else
  3633. if ($move_action=="up") {
  3634. $final_position_target = $this->activity->position;
  3635. $final_position_source = $final_position_target - 1;
  3636. }
  3637. else { // error:
  3638. print_error('error_update_move_iassign', 'iassign');
  3639. exit;
  3640. }
  3641. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3642. $newentry->id = $this->activity->id; // ID of the "source activity"
  3643. $newentry->position = $final_position_source;
  3644. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3645. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3646. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3647. print_error('error_update_move_iassign', 'iassign');
  3648. }
  3649. else { // first update performed successfully
  3650. $newentry->id = $iassign_target->id;
  3651. $newentry->position = $final_position_target;
  3652. if (!$DB->update_record('iassign_statement', $newentry))
  3653. print_error('error_update_move_iassign', 'iassign');
  3654. }
  3655. redirect($return);
  3656. }
  3657. /// Enable or disable the display of interactive activities
  3658. function visible_iassign ($return) {
  3659. global $DB;
  3660. $newentry = new stdClass();
  3661. $newentry->id = $this->activity->id;
  3662. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3663. if (!$DB->update_record('iassign_statement', $newentry))
  3664. print_error('error_update_visible_iassign', 'iassign');
  3665. redirect($return);
  3666. }
  3667. /// Add news interactive activities (register in table 'iassign_statement')
  3668. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3669. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3670. function new_iassign ($param) {
  3671. global $DB;
  3672. $newentry = new stdClass();
  3673. $newentry->iassignid = $param->iassignid;
  3674. $newentry->name = $param->name;
  3675. $newentry->type_iassign = $param->type_iassign;
  3676. $newentry->store_all_submissions = $param->store_all_submissions;
  3677. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3678. $proposition = $param->proposition;
  3679. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3680. else $proposition_text = $proposition;
  3681. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3682. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3683. //TODO Then get it directly from the form data $_POST!
  3684. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3685. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3686. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3687. $newentry->author_name = $param->author_name;
  3688. $newentry->author_modified_name = $param->author_modified_name;
  3689. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3690. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3691. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3692. $newentry->grade = $param->grade;
  3693. $newentry->timemodified = time();
  3694. $newentry->timecreated = time();
  3695. if ($param->type_iassign == 1) {
  3696. $newentry->timedue = 0;
  3697. $newentry->timeavailable = 0;
  3698. } // if ($param->type_iassign == 1)
  3699. else {
  3700. $newentry->timedue = $param->timedue;
  3701. $newentry->timeavailable = $param->timeavailable;
  3702. }
  3703. $newentry->preventlate = $param->preventlate;
  3704. $newentry->test = $param->test;
  3705. $newentry->special_param1 = $param->special_param1;
  3706. $newentry->visible = $param->visible;
  3707. $newentry->position = $param->position;
  3708. $newentry->max_experiment = $param->max_experiment;
  3709. $newentry->dependency = $param->dependency;
  3710. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3711. $newentry->show_answer = $param->show_answer;
  3712. $id = $DB->insert_record("iassign_statement", $newentry);
  3713. if ($id) {
  3714. $component = 'mod_iassign';
  3715. $filearea = 'exercise';
  3716. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3717. $file = $fs->get_file_by_id($param->file);
  3718. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3719. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  3720. //$itemid = $id;
  3721. // File already inserted in other context!
  3722. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3723. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3724. $updateentry = new stdClass();
  3725. $updateentry->id = $id;
  3726. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3727. $updateentry->file = $newfile->get_itemid();
  3728. if (!$DB->update_record("iassign_statement", $updateentry))
  3729. print_error('error_add', 'iassign');
  3730. if ($param->type_iassign == 3)
  3731. iassign::update_grade_iassign($param->iassignid);
  3732. //TODO iLM_HTML5 :: //MOOC2014
  3733. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3734. //D if ($iassign_ilm_configs) {
  3735. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3736. //D if ($iassign_ilm_config->param_type != 'static') {
  3737. //D $newentry = new stdClass();
  3738. //D $newentry->iassign_statementid = $id;
  3739. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3740. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3741. //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});
  3742. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3743. //D print_error('error_add_param', 'iassign');
  3744. //D }
  3745. //D }
  3746. //D }
  3747. // log event --------------------------------------------------------------------------------------
  3748. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3749. // log event --------------------------------------------------------------------------------------
  3750. return $id;
  3751. }
  3752. else
  3753. print_error('error_add', 'iassign');
  3754. } // function new_iassign($param)
  3755. /// Add the calendar entries for this iassign
  3756. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3757. // @return bool
  3758. static function add_calendar ($iassignid) {
  3759. global $DB, $CFG;
  3760. require_once($CFG->dirroot . '/calendar/lib.php');
  3761. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3762. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3763. $event = new stdClass();
  3764. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3765. $event->description = $iassign_statement_activity_item->name;
  3766. $event->courseid = $iassign->course;
  3767. $event->groupid = 0;
  3768. $event->userid = 0;
  3769. $event->modulename = 'iassign';
  3770. $event->instance = $iassign->id;
  3771. $event->eventtype = 'due';
  3772. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3773. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3774. calendar_event::create($event);
  3775. }
  3776. /// Update the calendar entries for this iassign
  3777. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3778. // @return bool
  3779. function update_calendar ($iassignid, $olddescription) {
  3780. global $DB, $CFG;
  3781. require_once($CFG->dirroot . '/calendar/lib.php');
  3782. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3783. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3784. $event = new stdClass();
  3785. $event->id = 0;
  3786. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3787. if ($events) {
  3788. foreach ($events as $value) {
  3789. if ($value->description == $olddescription) {
  3790. $event->id = $value->id;
  3791. }
  3792. }
  3793. }
  3794. if ($event->id != 0) {
  3795. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3796. $event->description = $iassign_statement_activity_item->name;
  3797. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3798. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3799. $calendarevent = calendar_event::load($event->id);
  3800. $calendarevent->update($event);
  3801. } else
  3802. $this->add_calendar($iassignid);
  3803. }
  3804. /// Update the calendar entries for this iassign
  3805. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3806. // @return bool
  3807. function delete_calendar ($iassignid) {
  3808. global $DB, $CFG;
  3809. require_once($CFG->dirroot . '/calendar/lib.php');
  3810. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3811. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3812. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3813. if ($events) {
  3814. foreach ($events as $value) {
  3815. if ($value->description == $iassign_statement_activity_item->name) {
  3816. $DB->delete_records('event', array('id' => $value->id));
  3817. }
  3818. }
  3819. }
  3820. }
  3821. /// Update interactive activities
  3822. function update_iassign ($param) {
  3823. global $DB;
  3824. $component = 'mod_iassign';
  3825. $filearea = 'exercise';
  3826. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3827. $file = $fs->get_file_by_id($param->file);
  3828. $fileold = $fs->get_file_by_id($param->fileold);
  3829. if ($param->file != $param->fileold) {
  3830. if ($fileold) {
  3831. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3832. foreach ($fileoldarea as $value) {
  3833. $value->delete();
  3834. }
  3835. }
  3836. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3837. $itemid = $file->get_itemid() + $param->iassign_id;
  3838. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3839. $param->file = $newfile->get_itemid();
  3840. } else
  3841. $param->file = $file->get_itemid();
  3842. } else {
  3843. $param->file = $file->get_itemid();
  3844. }
  3845. $newentry = new stdClass();
  3846. $newentry->id = $param->iassign_id;
  3847. $newentry->name = $param->name;
  3848. $newentry->type_iassign = $param->type_iassign;
  3849. $newentry->store_all_submissions = $param->store_all_submissions;
  3850. //2019 $newentry->proposition = $param->proposition;
  3851. $proposition = $param->proposition;
  3852. if (is_array($proposition))
  3853. $proposition_text = $proposition['text'];
  3854. else
  3855. $proposition_text = $proposition;
  3856. $newentry->proposition = $proposition_text;
  3857. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3858. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3859. $newentry->grade = $param->grade;
  3860. $newentry->author_modified_name = $param->author_modified_name;
  3861. $newentry->timemodified = time();
  3862. if ($param->type_iassign == 1) {
  3863. $newentry->timedue = 0;
  3864. $newentry->timeavailable = 0;
  3865. } // if ($param->type_iassign == 1)
  3866. else {
  3867. $newentry->timedue = $param->timedue;
  3868. $newentry->timeavailable = $param->timeavailable;
  3869. }
  3870. $newentry->preventlate = $param->preventlate;
  3871. $newentry->test = $param->test;
  3872. $newentry->special_param1 = $param->special_param1;
  3873. $newentry->visible = $param->visible;
  3874. $newentry->max_experiment = $param->max_experiment;
  3875. $newentry->dependency = $param->dependency;
  3876. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3877. $newentry->show_answer = $param->show_answer;
  3878. if (!$DB->update_record("iassign_statement", $newentry))
  3879. print_error('error_update', 'iassign');
  3880. if ($param->type_iassign == 3) {
  3881. iassign::update_grade_iassign($param->iassignid);
  3882. }
  3883. //$id = $newentry->id; // MOOC 2016 --- inicio
  3884. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3885. //if ($iassign_activity_item_configs) {
  3886. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3887. // $newentry = new stdClass();
  3888. // $newentry->id = $iassign_activity_item_config->id;
  3889. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3890. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3891. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3892. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3893. // print_error('error_edit_param', 'iassign');
  3894. // }
  3895. // } // MOOC 2016 --- final
  3896. // log event --------------------------------------------------------------------------------------
  3897. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3898. // log event --------------------------------------------------------------------------------------
  3899. return $newentry->id;
  3900. // if ($param->type_iassign==3)
  3901. // $this->update_grade_iassign($param->iassignid);
  3902. } // function update_iassign($param)
  3903. /// Show information of activity
  3904. function show_info_iassign () {
  3905. global $DB, $OUTPUT;
  3906. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3907. if ($this->activity->type_iassign == 3) {
  3908. if ($this->activity->dependency == 0) {
  3909. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3910. } else {
  3911. $dependencys = explode(';', $this->activity->dependency);
  3912. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3913. foreach ($dependencys as $dependency) {
  3914. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3915. if ($dependencyiassign)
  3916. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3917. } // foreach ($dependencys as $dependency)
  3918. } // if ($iassign_statement_activity_item->dependency == 0)
  3919. if ($this->activity->max_experiment == 0)
  3920. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3921. else
  3922. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3923. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3924. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3925. print $OUTPUT->box($output);
  3926. } // function show_info_iassign()
  3927. /// Shows date of opening and closing activities
  3928. function view_dates () {
  3929. global $USER, $CFG, $DB, $OUTPUT;
  3930. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3931. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3932. $status_iassign = "";
  3933. $status_iassign1 = "";
  3934. $status_iassign2 = "";
  3935. if ($this->activity->type_iassign == 1) // activity of type example
  3936. $type_iassign = get_string('example_iassign', 'iassign');
  3937. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3938. $type_iassign = get_string('test_iassign', 'iassign');
  3939. if ($this->activity->timeavailable > time()) {
  3940. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3941. } elseif ($this->activity->timedue < time()) {
  3942. $status_iassign = get_string('last_timedue', 'iassign');
  3943. }
  3944. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3945. $type_iassign = get_string('exercise_iassign', 'iassign');
  3946. if ($this->activity->timeavailable > time()) {
  3947. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3948. } elseif ($this->activity->timedue < time()) { // after delivery
  3949. $status_iassign = get_string('last_timedue', 'iassign');
  3950. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3951. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3952. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3953. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3954. if ($this->activity->test == 1) // allowed to test after of deadline
  3955. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3956. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3957. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3958. } // elseif ($iassign_statement_activity_item->test == 0)
  3959. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3960. } // elseif ($iassign_statement_activity_item->timedue < time())
  3961. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3962. $output = '<table width=100% >' . "\n";
  3963. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3964. $output .= '<tr>' . "\n";
  3965. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3966. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3967. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3968. // leo $output .= '<td width=80%>' . $type_iassign;
  3969. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3970. // $output .= '</td>' . "\n";
  3971. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3972. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3973. $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>";
  3974. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3975. } else {
  3976. $link_next = "";
  3977. $link_previous = "";
  3978. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3979. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3980. // previous_activity
  3981. if ($iassign_previous) {
  3982. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3983. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3984. } // next_activity
  3985. if ($iassign_next) {
  3986. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3987. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3988. }
  3989. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3990. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3991. $output .= '</tr></table>' . "\n";
  3992. $output .= '<table width=100% >' . "\n";
  3993. if ($this->activity->type_iassign > 1) {
  3994. if ($this->activity->timeavailable)
  3995. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3996. if ($this->activity->timedue)
  3997. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3998. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3999. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4000. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4001. $output .= '</table>' . "\n";
  4002. print $OUTPUT->box($output);
  4003. } // function view_dates()
  4004. } // class activity
  4005. /// Class to manage Interactive Learning Module (iLM)
  4006. class ilm {
  4007. var $ilm;
  4008. /// Constructor of class
  4009. // @param int $id Id of iLM
  4010. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4011. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4012. function __construct ($id) {
  4013. global $DB;
  4014. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4015. if (empty($this->ilm))
  4016. $this->ilm = null;
  4017. }
  4018. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4019. // @calledby view_iassign_current()
  4020. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4021. global $USER, $CFG, $DB;
  4022. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4023. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4024. $typec = strtolower($iassign_ilm->type);
  4025. require_once 'ilm_handlers/' . $typec . '.php';
  4026. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4027. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4028. return $retorno;
  4029. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4030. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4031. // @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);
  4032. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4033. // @param Object $file File in use in activity
  4034. // @return int Return the id of log
  4035. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4036. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4037. $newentry = new stdClass();
  4038. $newentry->iassign_statementid = $iassign_activity_itemid;
  4039. $newentry->userid = $USER->id;
  4040. $newentry->file = $content_or_id_from_ilm_security;
  4041. $newentry->timecreated = time();
  4042. $newentry->view = 1;
  4043. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4044. if (!$id_iLM_security) {
  4045. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4046. } // from (!$DB->insert_record("iassign_security", $newentry))
  4047. return $id_iLM_security;
  4048. }
  4049. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4050. // @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);
  4051. // @param int $userid
  4052. // @param int $iassign_activity_itemid Id of iassign statement
  4053. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4054. global $DB;
  4055. // 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")
  4056. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4057. }
  4058. } // class ilm
  4059. /// Class to manage settings of iLM.
  4060. class ilm_settings {
  4061. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4062. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4063. // @param int $ilm_id Id of iLM
  4064. // @param array $options An array with options for create dynamic tag html APPLET
  4065. // @return string Return with a tag html APPLET created
  4066. static function build_ilm_tags ($ilm_id, $options = array()) {
  4067. global $DB;
  4068. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4069. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4070. $typec = strtolower($iassign_ilm->type);
  4071. require_once 'ilm_handlers/' . $typec . '.php';
  4072. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4073. return $retorno;
  4074. } // static function build_ilm_tags($ilm_id, $options = array())
  4075. /// Function for get modified date of iLM file
  4076. // @param string $file_jar String with Ids of iLM files
  4077. // @return string Return with the filenames and modified date
  4078. static function applet_filetime ($file_jar) {
  4079. $filetime = "";
  4080. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4081. $files_jar = explode(",", $file_jar);
  4082. foreach ($files_jar as $one_file) {
  4083. $file = $fs->get_file_by_id($one_file);
  4084. if ($file)
  4085. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4086. }
  4087. return $filetime;
  4088. }
  4089. /// Function for verify an default applet
  4090. // @param String $file_jar String containing an list de ids of applet files
  4091. // @return boolean Return true or fale if applet is default
  4092. static function applet_default ($file_jar) {
  4093. $is_default = true;
  4094. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4095. $files_jar = explode(",", $file_jar);
  4096. foreach ($files_jar as $one_file) {
  4097. $file = $fs->get_file_by_id($one_file);
  4098. if ($file)
  4099. $is_default &= ($file->get_itemid() == 0);
  4100. }
  4101. return $is_default;
  4102. }
  4103. /// Function for get form variables for add, edit, or copy iLM
  4104. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4105. // @see settings_form.php
  4106. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4107. // @param int $ilm_id Id of iLM
  4108. // @param string $action String with the action
  4109. // @return object Return an object with forms variables
  4110. static function add_edit_copy_ilm ($ilm_id, $action) {
  4111. global $USER, $DB, $CFG;
  4112. require_once('settings_form.php'); // put the form
  4113. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4114. $param = new stdClass();
  4115. $param->action = $action;
  4116. $param->ilm_id = $ilm_id;
  4117. $CFG->action_ilm = $action;
  4118. $CFG->ilm_id = $ilm_id;
  4119. if ($action == 'add') {
  4120. $param->title = get_string('add_ilm', 'iassign');
  4121. $param->name = "";
  4122. $param->version = "";
  4123. $param->url = "";
  4124. $param->description = "";
  4125. $param->extension = "";
  4126. $param->author = $USER->id;
  4127. $param->file_jar = "";
  4128. $param->file_jar_static = "";
  4129. $param->file_class = "";
  4130. $param->width = 800;
  4131. $param->height = 600;
  4132. $param->enable = 0; // 0 - hide / 1 - show
  4133. $param->timecreated = time();
  4134. $param->timemodified = time();
  4135. $param->evaluate = 0;
  4136. $param->parent = 0;
  4137. }
  4138. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4139. if ($iassign_ilm) {
  4140. $description = json_decode($iassign_ilm->description);
  4141. $param->title = get_string('edit_ilm', 'iassign');
  4142. $param->id = $iassign_ilm->id;
  4143. $param->name_ilm = $iassign_ilm->name;
  4144. $param->name = $iassign_ilm->name;
  4145. $param->version = $iassign_ilm->version;
  4146. $param->ilm_type = $iassign_ilm->type;
  4147. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4148. $param->url = $iassign_ilm->url;
  4149. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4150. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4151. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4152. if (!isset($description->{current_language()})) {
  4153. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4154. else
  4155. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4156. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4157. }
  4158. else
  4159. $param->description = $description->{current_language()};
  4160. $param->description_lang = $iassign_ilm->description;
  4161. $param->extension = $iassign_ilm->extension;
  4162. $param->author = $iassign_ilm->author;
  4163. $param->file_jar = $iassign_ilm->file_jar;
  4164. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4165. $param->file_class = $iassign_ilm->file_class;
  4166. $param->width = $iassign_ilm->width;
  4167. $param->height = $iassign_ilm->height;
  4168. $param->enable = $iassign_ilm->enable;
  4169. $param->timecreated = $iassign_ilm->timecreated;
  4170. $param->timemodified = time();
  4171. $param->evaluate = $iassign_ilm->evaluate;
  4172. $param->parent = $iassign_ilm->parent;
  4173. }
  4174. }
  4175. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4176. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4177. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4178. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4179. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4180. // echo "Sem dados<br/>"; exit;
  4181. return;
  4182. }
  4183. $description = json_decode($iassign_ilm->description);
  4184. if ($iassign_ilm) {
  4185. if ($iassign_ilm->parent == 0)
  4186. $iassign_ilm->parent = $ilm_id;
  4187. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4188. $param->title = get_string('new_version_ilm', 'iassign');
  4189. $param->name_ilm = $iassign_ilm->name;
  4190. $param->name = $iassign_ilm->name;
  4191. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4192. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4193. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4194. $param->ilm_type = $iassign_ilm->type;
  4195. $param->url = $iassign_ilm->url;
  4196. $param->description = $description->{current_language()};
  4197. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4198. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4199. $param->extension = $iassign_ilm->extension;
  4200. $param->author = $USER->id;
  4201. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4202. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4203. $param->file_jar_static = '';
  4204. $param->file_class = $iassign_ilm->file_class;
  4205. $param->width = $iassign_ilm->width;
  4206. $param->height = $iassign_ilm->height;
  4207. $param->enable = 0;
  4208. $param->timecreated = time();
  4209. $param->timemodified = time();
  4210. $param->evaluate = $iassign_ilm->evaluate;
  4211. $param->parent = $iassign_ilm->parent;
  4212. }
  4213. }
  4214. elseif ($action == 'copy') {
  4215. $description = json_decode($iassign_ilm->description);
  4216. if ($iassign_ilm) {
  4217. if ($iassign_ilm->parent == 0)
  4218. $iassign_ilm->parent = $ilm_id;
  4219. $param->title = get_string('copy_ilm', 'iassign');
  4220. $param->id = $iassign_ilm->id;
  4221. $param->name_ilm = $iassign_ilm->name;
  4222. $param->name = $iassign_ilm->name;
  4223. $param->version = "";
  4224. $param->ilm_type = $iassign_ilm->type;
  4225. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4226. $param->url = $iassign_ilm->url;
  4227. $param->description = $description->{current_language()};
  4228. $param->description_lang = $iassign_ilm->description;
  4229. $param->extension = $iassign_ilm->extension;
  4230. $param->author = $USER->id;
  4231. $param->file_jar = '';
  4232. $param->file_jar_static = '';
  4233. $param->file_class = $iassign_ilm->file_class;
  4234. $param->width = $iassign_ilm->width;
  4235. $param->height = $iassign_ilm->height;
  4236. $param->enable = 0;
  4237. $param->timecreated = time();
  4238. $param->timemodified = time();
  4239. $param->evaluate = $iassign_ilm->evaluate;
  4240. $param->parent = $iassign_ilm->parent;
  4241. }
  4242. }
  4243. return $param;
  4244. } // static function add_edit_copy_ilm($ilm_id, $action)
  4245. /// Function for save iLM file in moodledata
  4246. // @param int $itemid Itemid of file save in draft (upload file)
  4247. // @param int $ilm_id Id of iLM
  4248. // @return string Return an string with ids of iLM files
  4249. static function new_file_ilm ($itemid, $iassign_ilm) {
  4250. global $CFG, $USER, $DB;
  4251. $return = null;
  4252. $file_jar = array();
  4253. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4254. $contextuser = context_user::instance($USER->id);
  4255. $contextsystem = context_system::instance();
  4256. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4257. if ($files_ilm) {
  4258. foreach ($files_ilm as $value) {
  4259. // CHECK IF file is HTML type
  4260. if ($iassign_ilm->type == 1) {
  4261. // Check if the file extension is ZIP
  4262. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4263. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4264. if ((strtolower($ext) == 'zip')) {
  4265. // Coping...:
  4266. $destination = 'ilm_debug/' . $value->get_filename();
  4267. $value->copy_content_to($destination);
  4268. // Extracting content...:
  4269. $zip = new ZipArchive();
  4270. $extracted = './ilm';
  4271. $dir = "";
  4272. if ($zip->open($destination) === TRUE) {
  4273. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4274. if (is_dir($dir)) {
  4275. $i = 1;
  4276. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4277. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4278. $i ++;
  4279. }
  4280. $name = $previous . "_" . $i;
  4281. $dir = './ilm/' . $name . "/";
  4282. $j = 0;
  4283. while ($item_name = $zip->getNameIndex($j)) {
  4284. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4285. $j++;
  4286. }
  4287. $zip->close();
  4288. }
  4289. $zip->open($destination);
  4290. $zip->extractTo($extracted);
  4291. $zip->close();
  4292. // After the extraction, remove it from DEBUG
  4293. unlink($destination);
  4294. } else { // Error trying to open destination...
  4295. // After the extraction error, also remove it from DEBUG
  4296. unlink($destination);
  4297. print_error('error_add_ilm_zip', 'iassign');
  4298. }
  4299. return $dir;
  4300. }
  4301. } // if ($iassign_ilm->type == 1)
  4302. if ($value->get_filename() != '.') {
  4303. $file_ilm = array(
  4304. 'userid' => $USER->id,
  4305. 'contextid' => $contextsystem->id,
  4306. 'component' => 'mod_iassign',
  4307. 'filearea' => 'ilm',
  4308. 'itemid' => rand(1, 999999999),
  4309. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4310. 'filename' => $value->get_filename());
  4311. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4312. array_push($file_jar, $file_ilm->get_id());
  4313. }
  4314. }
  4315. if (!empty($file_jar)) {
  4316. $return = implode(",", $file_jar);
  4317. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4318. foreach ($old_file_jar as $value) {
  4319. $file = $fs->get_file_by_id($value);
  4320. if ($file)
  4321. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4322. }
  4323. }
  4324. }
  4325. else // if ($files_ilm)
  4326. $return = $iassign_ilm->file_jar;
  4327. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4328. return $return;
  4329. } // static function new_file_ilm($itemid, $iassign_ilm)
  4330. /// Function for save in database an new iLM
  4331. // @param object $param An object with iLM params
  4332. static function new_ilm ($itemid) {
  4333. global $CFG, $USER, $OUTPUT;
  4334. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4335. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4336. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4337. }
  4338. $pathtemp = $CFG->dataroot . '/temp/';
  4339. $contextuser = context_user::instance($USER->id);
  4340. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4341. $zip = new zip_packer();
  4342. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4343. foreach ($files as $file) {
  4344. if (!$file->is_directory())
  4345. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4346. }
  4347. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4348. // Verifica se o pacote possui o XML
  4349. if (!$application_xml) {
  4350. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4351. return;
  4352. } else {
  4353. $missing = "";
  4354. if (!isset($application_xml->name)) {
  4355. $missing .= "name";
  4356. }
  4357. if (!isset($application_xml->version)) {
  4358. $missing .= ", version";
  4359. }
  4360. if (!isset($application_xml->type)) {
  4361. $missing .= ", type";
  4362. }
  4363. if (!isset($application_xml->extension)) {
  4364. $missing .= ", extension";
  4365. }
  4366. if (!isset($application_xml->file_jar)) {
  4367. $missing .= ", file_jar";
  4368. }
  4369. if (!isset($application_xml->file_class)) {
  4370. $missing .= ", file_class";
  4371. }
  4372. if (!isset($application_xml->width)) {
  4373. $missing .= ", width";
  4374. }
  4375. if (!isset($application_xml->height)) {
  4376. $missing .= ", height";
  4377. }
  4378. if (!isset($application_xml->evaluate)) {
  4379. $missing .= ", evaluate";
  4380. }
  4381. if (strlen($missing) > 2) {
  4382. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4383. return;
  4384. }
  4385. }
  4386. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4387. $typec = strtolower($application_xml->type);
  4388. require_once 'ilm_handlers/' . $typec . '.php';
  4389. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4390. return $retorno;
  4391. } // static function new_ilm($itemid)
  4392. /// Function for save in database an iLM edit
  4393. // @param object $param An object with iLM params
  4394. static function edit_ilm ($param, $itemid) {
  4395. // Descobrir o tipo de iLM:
  4396. global $DB, $USER, $CFG;
  4397. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4398. $pathtemp = $CFG->dataroot . '/temp/';
  4399. $contextuser = context_user::instance($USER->id);
  4400. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4401. $zip = new zip_packer();
  4402. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4403. $files_extract = null;
  4404. foreach ($files as $file) {
  4405. if (!$file->is_directory())
  4406. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4407. }
  4408. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4409. $typec = strtolower($iassign_t->type);
  4410. require_once 'ilm_handlers/' . $typec . '.php';
  4411. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4412. }
  4413. /// Function for register the new iLM (in database and in the directory)
  4414. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4415. // @param object $param An object with iLM params
  4416. static function copy_new_version_ilm ($param) {
  4417. global $DB, $CFG, $USER;
  4418. $itemid = $param->file;
  4419. $pathtemp = $CFG->dataroot . '/temp/';
  4420. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4421. //D echo "pathtemp=$pathtemp<br/>";
  4422. $contextuser = context_user::instance($USER->id);
  4423. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4424. $zip = new zip_packer();
  4425. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4426. $files_extract = null;
  4427. foreach ($files as $file) {
  4428. if (!$file->is_directory())
  4429. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4430. }
  4431. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4432. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4433. $typec = strtolower($iassign_t->type);
  4434. require_once 'ilm_handlers/' . $typec . '.php';
  4435. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4436. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4437. } // static function copy_new_version_ilm($param)
  4438. //VER::
  4439. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4440. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4441. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4442. /// Function for change visibility of iLM
  4443. // @param int $ilm_id Id of iLM
  4444. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4445. static function visible_ilm ($ilm_id, $status) {
  4446. global $DB;
  4447. if ($status == 0)
  4448. $visible = 1;
  4449. else
  4450. $visible = 0;
  4451. $newentry = new stdClass();
  4452. $newentry->id = $ilm_id;
  4453. $newentry->enable = $visible;
  4454. if (!$DB->update_record("iassign_ilm", $newentry))
  4455. error(get_string('error_edit_ilm', 'iassign'));
  4456. }
  4457. /// Function for confirm change default iLM
  4458. // @param int $ilm_id Id of iLM
  4459. // @param int $ilm_parent Id of parent iLM
  4460. // @return string Return with an string for create default page confirmation
  4461. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4462. global $OUTPUT, $DB;
  4463. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4464. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4465. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4466. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4467. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4468. return $return;
  4469. }
  4470. /// Function for change the default iLM
  4471. // @see settings_ilm.php
  4472. // @param int $ilm_id Id of iLM
  4473. // @return int Return Id of default iLM
  4474. static function default_ilm ($ilm_id) {
  4475. global $DB;
  4476. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4477. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4478. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4479. $iassign_ilm_default->id = $iassign_ilm->id;
  4480. $iassign_ilm_default->parent = 0;
  4481. $iassign_ilm->parent = $iassign_ilm_default->id;
  4482. $iassign_ilm->id = 0;
  4483. $iassign_ilm_default->enable = 1;
  4484. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4485. print_error('error_edit_ilm', 'iassign');
  4486. }
  4487. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4488. if (!$inserted) {
  4489. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4490. print_error($msg_error);
  4491. //xx print_error('error_add_ilm', 'iassign');
  4492. }
  4493. return $iassign_ilm_default->id;
  4494. } // static function default_ilm ($ilm_id)
  4495. /// Function for confirm delete iLM
  4496. // @param int $ilm_id Id of iLM
  4497. // @param int $ilm_parent Id of parent iLM
  4498. // @return string Return with an string for create delete page confirmation
  4499. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4500. global $OUTPUT, $DB;
  4501. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4502. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4503. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4504. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4505. }
  4506. /// Function for delete directory where the iLM is allocated.
  4507. // @param string $dirPath
  4508. // @throws InvalidArgumentException
  4509. public static function delete_dir ($dirPath) {
  4510. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4511. $dirPath .= '/';
  4512. }
  4513. $files = glob($dirPath . '*', GLOB_MARK);
  4514. foreach ($files as $file) {
  4515. if (is_dir($file)) {
  4516. ilm_settings::delete_dir($file);
  4517. } else {
  4518. unlink($file);
  4519. }
  4520. }
  4521. rmdir($dirPath);
  4522. }
  4523. /// Function for delete iLM
  4524. // @param int $ilm_id Id of iLM
  4525. // @return int Return Id of parent iLM
  4526. static function delete_ilm ($ilm_id) {
  4527. global $DB;
  4528. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4529. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4530. $typec = strtolower($iassign_ilm->type);
  4531. require_once 'ilm_handlers/' . $typec . '.php';
  4532. $retorno = $typec::delete_ilm($ilm_id);
  4533. return $retorno;
  4534. }
  4535. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4536. // @param int $ilm_id Id of iLM
  4537. static function export_ilm ($ilm_id) {
  4538. global $DB;
  4539. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4540. if (!$iassign_ilm) return; // security debug...
  4541. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4542. $typec = strtolower($iassign_ilm->type);
  4543. if (!$typec) $typec = "html5"; // security debug...
  4544. require_once 'ilm_handlers/' . $typec . '.php';
  4545. $typec::export_ilm($ilm_id);
  4546. } // static function export_ilm($ilm_id)
  4547. //TODO iLM_HTML5 :: //MOOC 2016
  4548. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4549. // @param int $ilm_id Id of iLM
  4550. static function export_update_ilm ($ilm_id) {
  4551. global $DB, $CFG;
  4552. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4553. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4554. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4555. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4556. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4557. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4558. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4559. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4560. $upgrade_descriptor .= '</upgrade>' . "\n";
  4561. file_put_contents($xml_filename, $upgrade_descriptor);
  4562. header("Pragma: public");
  4563. header("Expires: 0");
  4564. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4565. header("Cache-Control: private", false);
  4566. header('Content-Type: application/xml; charset=utf-8');
  4567. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4568. header("Content-Length: " . @filesize($xml_filename));
  4569. set_time_limit(0);
  4570. @readfile("$xml_filename") || die("File not found.");
  4571. unlink($xml_filename);
  4572. exit;
  4573. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4574. /// Function for save iLM from XML descriptor
  4575. // @param array $application_xml Data of XML descriptor
  4576. // @param array $files_extract Filenames of extract files
  4577. // @return array Return an array content id of JAR files
  4578. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4579. global $CFG, $USER;
  4580. // Tratamento diferenciado se for do tipo HTML5:
  4581. $source = "";
  4582. $diretorio = "";
  4583. if (strtolower($application_xml->type) == 'html5') {
  4584. $i = 0;
  4585. foreach ($files_extract as $key => $value) {
  4586. $file = $CFG->dataroot . '/temp/' . $key;
  4587. // Verifica se já existe a pasta no diretório dos iLM:
  4588. if ($i == 0) {
  4589. $source = $file;
  4590. if (file_exists("ilm/" . basename($file))) {
  4591. $j = 1;
  4592. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4593. $j ++;
  4594. }
  4595. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4596. // mkdir($diretorio, 0777, true);
  4597. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4598. }
  4599. else {
  4600. $diretorio = 'ilm/' . basename($file);
  4601. // mkdir($diretorio, 0777, true);
  4602. mkdir($diretorio, 0755, true);
  4603. }
  4604. break;
  4605. }
  4606. $i ++;
  4607. }
  4608. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4609. if ($item->isDir()) {
  4610. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4611. }
  4612. else {
  4613. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4614. }
  4615. }
  4616. ilm_settings::delete_dir($source);
  4617. return "./" . $diretorio;
  4618. }
  4619. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4620. $file_jar = array();
  4621. $files_ilm = explode(",", $application_xml->file_jar);
  4622. $contextsystem = context_system::instance();
  4623. foreach ($files_ilm as $value) {
  4624. $file_ilm = array(
  4625. 'userid' => $USER->id,
  4626. 'contextid' => $contextsystem->id,
  4627. 'component' => 'mod_iassign',
  4628. 'filearea' => 'ilm',
  4629. 'itemid' => rand(1, 999999999),
  4630. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4631. 'filename' => $value);
  4632. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4633. array_push($file_jar, $file_ilm->get_id());
  4634. }
  4635. foreach ($files_extract as $key => $value) {
  4636. $file = $CFG->dataroot . '/temp/' . $key;
  4637. if (file_exists($file))
  4638. unlink($file);
  4639. }
  4640. return $file_jar;
  4641. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4642. /// Function for import the iLM from an package
  4643. // @param int $itemid Itemid of zip file
  4644. static function import_ilm ($itemid) {
  4645. global $CFG, $USER, $OUTPUT;
  4646. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4647. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4648. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4649. }
  4650. $pathtemp = $CFG->dataroot . '/temp/';
  4651. $contextuser = context_user::instance($USER->id);
  4652. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4653. $zip = new zip_packer();
  4654. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4655. foreach ($files as $file) {
  4656. if (!$file->is_directory())
  4657. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4658. }
  4659. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4660. // Verifica se o pacote possui o XML
  4661. if (!$application_xml) {
  4662. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4663. return;
  4664. } else {
  4665. $missing = "";
  4666. if (!isset($application_xml->name)) {
  4667. $missing .= "name";
  4668. }
  4669. if (!isset($application_xml->version)) {
  4670. $missing .= ", version";
  4671. }
  4672. if (!isset($application_xml->type)) {
  4673. $missing .= ", type";
  4674. }
  4675. if (!isset($application_xml->extension)) {
  4676. $missing .= ", extension";
  4677. }
  4678. if (!isset($application_xml->file_jar)) {
  4679. $missing .= ", file_jar";
  4680. }
  4681. if (!isset($application_xml->file_class)) {
  4682. $missing .= ", file_class";
  4683. }
  4684. if (!isset($application_xml->width)) {
  4685. $missing .= ", width";
  4686. }
  4687. if (!isset($application_xml->height)) {
  4688. $missing .= ", height";
  4689. }
  4690. if (!isset($application_xml->evaluate)) {
  4691. $missing .= ", evaluate";
  4692. }
  4693. if (strlen($missing) > 2) {
  4694. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4695. return;
  4696. }
  4697. }
  4698. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4699. $typec = strtolower($application_xml->type);
  4700. require_once 'ilm_handlers/' . $typec . '.php';
  4701. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4702. } // static function import_ilm($itemid)
  4703. /// Function for list iLM defaults
  4704. // @return string Return an string with a table of iLM
  4705. static function list_ilm () {
  4706. global $DB, $OUTPUT;
  4707. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4708. $str = '';
  4709. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4710. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4711. if ($iassign_ilm) {
  4712. foreach ($iassign_ilm as $ilm) {
  4713. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4714. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4715. $str .= '<tr><td>';
  4716. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4717. $str .= '<tr>';
  4718. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4719. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4720. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4721. $str .= '</tr>';
  4722. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4723. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4724. $str .= '</table>';
  4725. $str .= '</td></tr>';
  4726. }
  4727. }
  4728. $str .= '</table>';
  4729. return $str;
  4730. }
  4731. /// Function for download and install an upgrade of an iLM
  4732. // @param int $ilm_id Id of iLM
  4733. static function upgrade_ilm ($ilm_id) {
  4734. global $DB, $CFG, $USER;
  4735. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4736. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4737. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4738. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4739. if (!$result)
  4740. print_error('error_upgrade_ilm', 'iassign');
  4741. else {
  4742. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4743. $extension = explode(".", $zip_filename);
  4744. if ($extension[count($extension) - 1] != 'ipz') {
  4745. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4746. die;
  4747. }
  4748. $zip = new zip_packer();
  4749. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4750. $contextuser = context_user::instance($USER->id);
  4751. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4752. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4753. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4754. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4755. if (file_exists($zip_filename))
  4756. unlink($zip_filename);
  4757. if (empty($file_jar)) {
  4758. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4759. print_error($msg_error);
  4760. //xx print_error('error_add_ilm', 'iassign');
  4761. }
  4762. else {
  4763. $newentry = new stdClass();
  4764. $newentry->name = (String) $application_xml->name;
  4765. $newentry->version = (String) $application_xml->version;
  4766. $newentry->url = (String) $application_xml->url;
  4767. $newentry->description = $description_str;
  4768. $newentry->extension = strtolower((String) $application_xml->extension);
  4769. $newentry->file_jar = implode(",", $file_jar);
  4770. $newentry->file_class = (String) $application_xml->file_class;
  4771. $newentry->width = (String) $application_xml->width;
  4772. $newentry->height = (String) $application_xml->height;
  4773. $newentry->enable = 0;
  4774. $newentry->timemodified = time();
  4775. $newentry->author = $USER->id;
  4776. $newentry->timecreated = time();
  4777. $newentry->evaluate = (String) $application_xml->evaluate;
  4778. $newentry->parent = $ilm_id;
  4779. }
  4780. }
  4781. return $iassign_ilm->id;
  4782. } // static function upgrade_ilm($ilm_id)
  4783. //MOOC2014 -- inicio
  4784. //TODO: REVIEW
  4785. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4786. // static function move_iassign($ilm_id)
  4787. //MOOC2014 -- final
  4788. /// Function for list iLM versions with all informations
  4789. // @return string Return an string with a table of iLM
  4790. static function view_ilm ($ilmid, $from) {
  4791. global $DB;
  4792. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4793. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4794. $typec = strtolower($iassign_ilm->type);
  4795. require_once 'ilm_handlers/' . $typec . '.php';
  4796. $retorno = $typec::view_ilm($ilmid, $from);
  4797. return $retorno;
  4798. }
  4799. /// Function for get form variables for add, edit, or copy iLM params
  4800. // @param int $ilm_param_id Id of iLM param
  4801. // @param string $action String with the action
  4802. // @return object Return an object with forms variables
  4803. static function add_edit_copy_param ($ilm_param_id, $action) {
  4804. global $DB;
  4805. require_once('params_form.php');
  4806. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4807. $param = new stdClass();
  4808. $param->action = $action;
  4809. $param->ilm_param_id = $ilm_param_id;
  4810. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4811. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4812. $type = $iassign_ilm_config->param_type;
  4813. if ($action == 'add') {
  4814. $param->title = get_string('add_ilm', 'iassign');
  4815. $param->iassign_ilmid = $ilm_param_id;
  4816. $param->param_name = "";
  4817. $param->param_value = "";
  4818. $param->description = "";
  4819. $param->visible = 1;
  4820. }
  4821. elseif ($action == 'edit') {
  4822. if ($iassign_ilm_config) {
  4823. $param->title = get_string('edit_ilm', 'iassign');
  4824. $param->id = $iassign_ilm_config->id;
  4825. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4826. $param->param_type = $type; //MOOC2014
  4827. $param->param_name = $iassign_ilm_config->param_name;
  4828. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4829. $param->param_value = $iassign_ilm_config->param_value;
  4830. else //MOOC2014
  4831. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4832. $param->param_value = $iassign_ilm_config->param_value;
  4833. $param->description = $iassign_ilm_config->description;
  4834. $param->visible = $iassign_ilm_config->visible;
  4835. }
  4836. }
  4837. elseif ($action == 'copy') {
  4838. if ($iassign_ilm_config) {
  4839. $param->title = get_string('copy_ilm', 'iassign');
  4840. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4841. $param->param_type = $type; //MOOC2014
  4842. $param->param_name = $iassign_ilm_config->param_name;
  4843. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4844. $param->param_value = $iassign_ilm_config->param_value;
  4845. else //MOOC2014
  4846. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4847. $param->description = $iassign_ilm_config->description;
  4848. $param->visible = $iassign_ilm_config->visible;
  4849. }
  4850. }
  4851. return $param;
  4852. } // static function add_edit_copy_param($ilm_param_id, $action)
  4853. /// Function for change visibility of iLM param
  4854. // @param int $ilm_param_id Id of iLM param
  4855. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4856. static function visible_param ($ilm_param_id, $status) {
  4857. global $DB, $CFG;
  4858. if ($status == 0)
  4859. $visible = 1;
  4860. else
  4861. $visible = 0;
  4862. $newentry = new stdClass();
  4863. $newentry->id = $ilm_param_id;
  4864. $newentry->visible = $visible;
  4865. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4866. error(get_string('error_edit_param', 'iassign'));
  4867. }
  4868. /// Function for save in database an new iLM param
  4869. // @param object $param An object with iLM params
  4870. static function add_param ($param) {
  4871. global $DB;
  4872. $newentry = new stdClass();
  4873. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4874. //MOOC2014 $newentry->param_name = $param->param_name;
  4875. $newentry->param_type = $param->param_type; //MOOC2014
  4876. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4877. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4878. $newentry->param_value = $param->param_value;
  4879. else //MOOC2014
  4880. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4881. $newentry->description = $param->description;
  4882. $newentry->visible = $param->visible;
  4883. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4884. if (!$newentry->id) {
  4885. print_error('error_add_param', 'iassign');
  4886. }
  4887. }
  4888. /// Function for save in database a iLM param edit
  4889. // @param object $param An object with iLM params
  4890. static function edit_param ($param) {
  4891. global $DB;
  4892. $updentry = new stdClass();
  4893. $updentry->id = $param->id;
  4894. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4895. $updentry->param_type = $param->param_type; //MOOC2014
  4896. // $updentry->param_name = $param->param_name;
  4897. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4898. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4899. $updentry->param_value = $param->param_value;
  4900. else //MOOC2014
  4901. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4902. $updentry->description = $param->description;
  4903. $updentry->visible = $param->visible;
  4904. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4905. error(get_string('error_edit_param', 'iassign'));
  4906. }
  4907. }
  4908. /// Function for save in database a iLM param copy
  4909. // @param object $param An object with iLM params
  4910. static function copy_param ($param) {
  4911. global $DB;
  4912. $newentry = new stdClass();
  4913. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4914. //$newentry->param_name = $param->param_name;
  4915. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4916. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4917. $newentry->param_value = $param->param_value;
  4918. else //MOOC2014
  4919. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4920. $newentry->description = $param->description;
  4921. $newentry->visible = $param->visible;
  4922. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4923. if (!$newentry->id) {
  4924. print_error('error_add_param', 'iassign');
  4925. }
  4926. }
  4927. /// Function for delete iLM param of database
  4928. // @param int $param_id Id of iLM param
  4929. static function delete_param ($param_id) {
  4930. global $DB;
  4931. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4932. print_error('error_delete_param', 'iassign');
  4933. }
  4934. }
  4935. } // class ilm_settings
  4936. /// Class for manage iLM files (editor).
  4937. class ilm_manager {
  4938. var $id; // course id
  4939. var $url;
  4940. var $from;
  4941. /// Constructor for the base ilm_manager class
  4942. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4943. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4944. function __construct ($id, $url, $from) {
  4945. $this->id = $id; // course id
  4946. $this->url = $url;
  4947. $this->from = $from;
  4948. }
  4949. /// Function to get iAssign content file in Moodle data (exercise)
  4950. // @calledby x function preview_ilm($iassign_ilm) :
  4951. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4952. function get_file_ilm () {
  4953. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4954. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4955. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4956. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4957. $md_file = $fs->get_file_by_id($fileid);
  4958. $ilm_content_file = $md_file->get_content();
  4959. return $ilm_content_file;
  4960. }
  4961. /// Function for creating a new file from the iLM online editor
  4962. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4963. function ilm_editor_new () {
  4964. global $CFG, $DB, $OUTPUT, $PAGE;
  4965. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4966. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4967. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4968. $context = context_course::instance($this->id);
  4969. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4970. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4971. if (!$iassign) {
  4972. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4973. die();
  4974. }
  4975. $temp = explode(",", $iassign->extension);
  4976. $extension = $temp[0]; // default extension for this iLM
  4977. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4978. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4979. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4980. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4981. if ($stringArchiveContent != NULL) {
  4982. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4983. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4984. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4985. $filename = optional_param('filename', NULL, PARAM_RAW);
  4986. //Leo $filename = iassign_utils::format_filename($filename); //
  4987. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4988. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4989. //2019/02 $arrayfilename = explode(".", $filename);
  4990. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4991. //2019/02 $count_dots = count($arrayfilename);
  4992. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4993. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4994. //2019/02 if ($last_name != $extension)
  4995. //2019/02 $filename = $filename . '.' . $extension;
  4996. //2019/02 }
  4997. //2019/02 else { // no extension...
  4998. //2019/02 $filename = $filename . '.' . $extension;
  4999. //2019/02 }
  5000. // Store the name of recent created file
  5001. $_SESSION['file_name'] = $filename;
  5002. //$this->write_file_iassign($string, $filename);
  5003. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5004. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5005. die();
  5006. }
  5007. else { // if ($stringArchiveContent != NULL)
  5008. // iLM On-line editor
  5009. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5010. $str_get_iLM = "window.frames.iLM";
  5011. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5012. }
  5013. else { // otherwise it is JAR named 'iLM'
  5014. $str_get_iLM = "document.iLM";
  5015. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5016. }
  5017. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5018. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5019. $files_array = '';
  5020. foreach ($files as $value) {
  5021. if ($value->get_filename() != ".")
  5022. $files_array .= "'" . $value->get_filename() . "',";
  5023. }
  5024. $files_array .= "''";
  5025. $file = null;
  5026. $ia_content = "";
  5027. $filename = "";
  5028. $error_files_exists = get_string('error_file_exists', 'iassign');
  5029. $output = "<script type='text/javascript'>
  5030. //<![CDATA[
  5031. //D alert('locallib.php: ilm_editor_new');
  5032. function submit_iLM_Answer () {
  5033. var docFormOnLineEditor = document.formEnvio;
  5034. var resposta_exerc = new Array(3);
  5035. var valor_resposta = new Array(3);
  5036. var sessao = new Array(3);
  5037. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5038. resposta_exerc[0] = doc_iLM.getAnswer();
  5039. valor_resposta[0] = doc_iLM.getEvaluation();
  5040. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5041. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5042. var files = new Array(" . $files_array . ");
  5043. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5044. if (docFormOnLineEditor.filename.value=='') {
  5045. // ERROR: the file name is empty
  5046. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5047. return false;
  5048. }
  5049. // }
  5050. for (i=0; i<files.length; i++) {
  5051. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5052. alert('" . $error_files_exists . "');
  5053. return false;
  5054. }
  5055. }
  5056. docFormOnLineEditor.submit();
  5057. return true;
  5058. }
  5059. //]]>
  5060. </script>\n";
  5061. $output .= "
  5062. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5063. $output .= $OUTPUT->box_start();
  5064. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5065. $output .= "
  5066. <table width='100%' cellpadding='20'>
  5067. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5068. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5069. </tr>
  5070. </table>\n";
  5071. $output .= $OUTPUT->box_end();
  5072. $output .= "<center>\n";
  5073. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5074. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5075. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5076. $output .= $output_ilm;
  5077. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5078. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5079. </center>
  5080. </form>\n";
  5081. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5082. $PAGE->navbar->add($title);
  5083. $PAGE->set_title($title);
  5084. $PAGE->set_heading($title); // insert title above the navigation bar
  5085. print $OUTPUT->header();
  5086. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5087. print $output;
  5088. print $OUTPUT->footer();
  5089. }
  5090. die();
  5091. } // function ilm_editor_new()
  5092. /// Function for editing an file in online editor
  5093. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5094. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5095. global $CFG, $DB, $OUTPUT, $PAGE;
  5096. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5097. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5098. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5099. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5100. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5101. // If iLM is not registered, error!
  5102. if (!$iassign) {
  5103. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5104. die;
  5105. }
  5106. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5107. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5108. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5109. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5110. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5111. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5112. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5113. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5114. if ($stringArchiveContent != NULL) {
  5115. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5116. die();
  5117. } else { // if ($stringArchiveContent != NULL)
  5118. $end_file = '';
  5119. if ($content_file) {
  5120. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5121. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5122. }
  5123. $temp = explode(",", $iassign->extension);
  5124. $extension = $temp[0]; // default extension for this iLM
  5125. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5126. $str_get_iLM = "window.frames.iLM";
  5127. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5128. } else { // otherwise it is JAR named 'iLM'
  5129. $str_get_iLM = "document.iLM";
  5130. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5131. }
  5132. $output = "<script type='text/javascript'>
  5133. //<![CDATA[
  5134. function submit_iLM_Answer () {
  5135. var docFormEditor = document.formEnvio;
  5136. var activityAnswer; // to get activity answer (text)
  5137. var activityValue; // to get activity answer value (float)
  5138. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5139. //activityAnswer = doc_iLM.getAnswer();
  5140. //activityValue = doc_iLM.getEvaluation();
  5141. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5142. activityValue = " . $str_get_iLM . ".getEvaluation();
  5143. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5144. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5145. docFormEditor.submit();
  5146. return true;
  5147. }
  5148. //]]>
  5149. </script>\n";
  5150. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5151. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5152. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5153. // return true;
  5154. // }
  5155. $output .= "
  5156. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5157. $output .= $OUTPUT->box_start();
  5158. $output .= "
  5159. <table width='100%' cellpadding='20'>
  5160. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5161. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5162. <input type='hidden' name='filename' value='$filename'/></td>
  5163. <td>
  5164. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5165. </tr>
  5166. </table>\n";
  5167. $output .= $OUTPUT->box_end();
  5168. $output .= " <center>\n";
  5169. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5170. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5171. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5172. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5173. </center>
  5174. </form>\n";
  5175. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5176. $PAGE->navbar->add($title);
  5177. $PAGE->set_title($title);
  5178. $PAGE->set_heading($title); // insert title above the navigation bar
  5179. print $OUTPUT->header();
  5180. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5181. print $output;
  5182. print $OUTPUT->footer();
  5183. } // else if ($stringArchiveContent != NULL)
  5184. die();
  5185. } // function ilm_editor_update()
  5186. /// Function for write iAssign file in Moodle data (exercise)
  5187. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5188. // @param string $stringArchiveContent Content of iassign file
  5189. // @param string $filename Filename of iassign file
  5190. function write_file_iassign ($stringArchiveContent, $filename) {
  5191. global $USER;
  5192. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5193. $context = context_course::instance($this->id);
  5194. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5195. $dirid = $this->get_dir_ilm('dirid');
  5196. $dir = $fs->get_file_by_id($dirid);
  5197. $fileinfo = array('contextid' => $context->id, // ID of course
  5198. 'component' => 'mod_iassign', // usually = table name
  5199. 'filearea' => 'activity', // usually = table name
  5200. 'itemid' => 0, // usually = ID of row in table
  5201. 'filepath' => '/', // any path beginning and ending whith '/'
  5202. 'userid' => $USER->id,
  5203. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5204. 'filename' => $filename); // any filename
  5205. // Create file containing text. '$stringArchiveContent'
  5206. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5207. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5208. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5209. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5210. // 'Activité interactive enregistrée avec succès sous le nom:';
  5211. // 'Atividade interativa gravada com sucesso sob o nome:'
  5212. $output = "
  5213. <script type='text/javascript'>
  5214. //<![CDATA[
  5215. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5216. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5217. //]]>
  5218. </script>";
  5219. print $output;
  5220. die();
  5221. }
  5222. /// Function for write iAssign file in Moodle data (exercise)
  5223. // @param string $stringArchiveContent Content of iassign file
  5224. // @param string $filename Filename of iassign file
  5225. // @param int $itemid Itemid of iassign file
  5226. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5227. global $OUTPUT, $USER;
  5228. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5229. $context = context_course::instance($this->id);
  5230. $dirid = $this->get_dir_ilm('dirid');
  5231. if ($stringArchiveContent != (-1)) {
  5232. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5233. $file = $fs->get_file_by_id($fileid);
  5234. if (!$file) {
  5235. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5236. die;
  5237. }
  5238. $fileinfo = array('contextid' => $context->id, // ID of context
  5239. 'component' => 'mod_iassign', // usually = table name
  5240. 'filearea' => 'activity', // usually = table name
  5241. 'itemid' => 0, // usually = ID of row in table
  5242. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5243. 'userid' => $USER->id,
  5244. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5245. 'license' => 'allrightsreserved', // allrightsreserved
  5246. 'timecreated' => $file->get_timecreated(),
  5247. 'filename' => $file->get_filename()); // any filename
  5248. $file->delete();
  5249. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5250. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5251. }
  5252. $output = "<script type='text/javascript'>
  5253. //<![CDATA[
  5254. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5255. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5256. //]]>
  5257. </script>";
  5258. print $output;
  5259. die();
  5260. }
  5261. /// Function for create an tag for iAssign filter
  5262. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5263. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5264. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5265. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5266. // @param int $fileid Id of file
  5267. // @return string Return an string with an tag of iassign filter
  5268. function tag_ilm ($fileid) {
  5269. global $DB;
  5270. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5271. $width = '600';
  5272. $height = '400';
  5273. $file = $fs->get_file_by_id($fileid);
  5274. $filetype = explode(".", $file->get_filename());
  5275. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5276. foreach ($iassign_ilm as $value) {
  5277. $extensions = explode(",", $value->extension);
  5278. if (in_array($filetype[1], $extensions)) {
  5279. $width = $value->width;
  5280. $height = $value->height;
  5281. }
  5282. }
  5283. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5284. }
  5285. /// Function for delete iAssign file in Moodle data (exercise)
  5286. function delete_file_ilm () {
  5287. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5288. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5289. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5290. $file = $fs->get_file_by_id($fileid);
  5291. if ($file)
  5292. $file->delete();
  5293. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5294. die();
  5295. }
  5296. /// Function for delete selected iAssign file in Moodle data (exercise)
  5297. function delete_selected_ilm () {
  5298. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5299. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5300. $context = context_course::instance($this->id);
  5301. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5302. $dirid = $this->get_dir_ilm('dirid');
  5303. foreach ($files_id as $file_id) {
  5304. $file = $fs->get_file_by_id($file_id);
  5305. if ($file) {
  5306. if (!$file->is_directory())
  5307. $file->delete();
  5308. else {
  5309. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5310. foreach ($files_delete as $value)
  5311. $value->delete();
  5312. $file->delete();
  5313. }
  5314. }
  5315. }
  5316. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5317. die();
  5318. }
  5319. /// Function for duplicate iAssign file from "online" edition
  5320. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5321. function duplicate_file_ilm () {
  5322. global $USER, $COURSE;
  5323. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5325. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5326. $filename = optional_param('filename', NULL, PARAM_RAW);
  5327. $file = $fs->get_file_by_id($fileid);
  5328. $context = context_course::instance($this->id);
  5329. $fileinfo = array(
  5330. 'contextid' => $context->id, // ID of context
  5331. 'component' => 'mod_iassign', // usually = table name
  5332. 'filearea' => 'activity', // usually = table name
  5333. 'itemid' => 0, // usually = ID of row in table
  5334. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5335. 'userid' => $USER->id,
  5336. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5337. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5338. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5339. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5340. die();
  5341. }
  5342. /// Function for rename iAssign file
  5343. function rename_file_ilm () {
  5344. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5345. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5346. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5347. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5348. $file = $fs->get_file_by_id($fileid);
  5349. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5350. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5351. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5352. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5353. die();
  5354. }
  5355. /// Function for get iassign file for iassign form
  5356. function add_ilm () {
  5357. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5358. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5359. $output = "
  5360. <script type='text/javascript'>
  5361. //<![CDATA[
  5362. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5363. iassign_file_link.innerHTML = '$filename';
  5364. window.opener.document.forms['mform1'].file.value='$fileid';
  5365. window.opener.document.forms['mform1'].filename.value='$filename';
  5366. window.close();
  5367. //]]>
  5368. </script>";
  5369. print $output;
  5370. die();
  5371. }
  5372. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5373. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5374. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5375. function preview_ilm ($courseid, $iassign_ilm) {
  5376. global $OUTPUT, $CFG, $USER;
  5377. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5378. $title = get_string('modulename', 'iassign'); // iAssign
  5379. print $OUTPUT->header();
  5380. print $OUTPUT->box_start();
  5381. $javascript = "
  5382. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5383. <script type='text/javascript'>
  5384. //<![CDATA[
  5385. function submit_close () {
  5386. window.opener.location.reload();
  5387. window.close();
  5388. }
  5389. //]]>
  5390. </script>\n";
  5391. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5392. // to the complete "applet" tag
  5393. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5394. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5395. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5396. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5397. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5398. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5399. if ($ilm_name != "ivprog") {
  5400. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5401. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5402. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5403. } else {
  5404. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5405. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5406. $timecreated = time();
  5407. $token = md5($timecreated);
  5408. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5409. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5410. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5411. $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)
  5412. }
  5413. $html = "
  5414. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5415. <table border='1'>
  5416. <tr><td>
  5417. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5418. <!-- iLM calls : end -->
  5419. </td></tr>
  5420. </table>
  5421. <table>
  5422. <tr>
  5423. <td align='center'>
  5424. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5425. </td></tr>
  5426. </table>
  5427. </form>\n";
  5428. print $javascript . $html;
  5429. print $OUTPUT->box_end();
  5430. //NAO echo format_string($html); // Moodle 3.X
  5431. die();
  5432. } // function preview_ilm($courseid, $iassign_ilm)
  5433. //r_ function preview_ilm ($iassign_ilm)
  5434. //r_ /// Function for preview iassign file from iassign filter.
  5435. //r_ function preview_ilm() {
  5436. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5437. //r_ $tag_filter = $this->tag_ilm($fileid);
  5438. //r_ $javascript = "<script type='text/javascript'>
  5439. //r_ //<![CDATA[
  5440. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5441. //r_ //]]>
  5442. //r_ </script>";
  5443. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5444. //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>
  5445. //r_ </table></form></body></html>";
  5446. //r_ echo $javascript . format_text($html);
  5447. //r_ die;
  5448. //r_ }
  5449. /// Function for export an package (zip) of iassign files
  5450. function export_files_ilm () {
  5451. global $CFG;
  5452. $context = context_course::instance($this->id);
  5453. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5454. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5455. $zip = new zip_archive();
  5456. $zip->open($zip_filename);
  5457. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5458. foreach ($files_id as $file_id) {
  5459. $file = $fs->get_file_by_id($file_id);
  5460. if (!$file->is_directory())
  5461. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5462. else {
  5463. $zip->add_directory($file->get_filepath());
  5464. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5465. foreach ($files_zip as $value) {
  5466. if (!$value->is_directory())
  5467. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5468. else
  5469. $zip->add_directory($value->get_filepath());
  5470. }
  5471. }
  5472. }
  5473. $zip->close();
  5474. header("Pragma: public");
  5475. header("Expires: 0");
  5476. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5477. header("Cache-Control: private", false);
  5478. header("Content-Type: application/zip");
  5479. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5480. header("Content-Transfer-Encoding: binary");
  5481. header("Content-Length: " . @filesize($zip_filename));
  5482. set_time_limit(0);
  5483. @readfile("$zip_filename") || die("File not found.");
  5484. unlink($zip_filename);
  5485. exit;
  5486. }
  5487. /// Function of execute a command in button editor tinymce
  5488. // @param int $fileid Id of file
  5489. function tinymce_ilm ($fileid) {
  5490. $tag_filter = $this->tag_ilm($fileid);
  5491. $output = "<script type='text/javascript'>
  5492. //<![CDATA[
  5493. var tag_filter = '$tag_filter';
  5494. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5495. // all right, insert it
  5496. } else {
  5497. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5498. }
  5499. // window.close();
  5500. //]]>
  5501. </script>\n";
  5502. print $output;
  5503. die();
  5504. }
  5505. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5506. /// Function to add content to the Editor Window
  5507. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5508. // @param int $fileid Id of file
  5509. function editor_ilm ($fileid, $editor) {
  5510. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5511. $output1 = "<script type='text/javascript'>
  5512. //<![CDATA[
  5513. var tag_filter = '$tag_filter';\n";
  5514. if ($editor == 'atto') {
  5515. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5516. } elseif ($editor == 'tinyMCE') {
  5517. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5518. } else
  5519. $output2 = "";
  5520. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5521. window.close();
  5522. //]]>
  5523. </script>\n";
  5524. //D var_dump($output);
  5525. print $output1 . $output2 . $output3;
  5526. die();
  5527. }
  5528. /// Function to add content to the Atto Editor Window
  5529. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5530. // @param int $fileid Id of file
  5531. function atto_ilm ($fileid) {
  5532. global $CFG, $DB;
  5533. $tag_filter = $this->tag_ilm($fileid);
  5534. $output = "<script type='text/javascript'>
  5535. //<![CDATA[
  5536. var tag_filter = '$tag_filter';
  5537. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5538. // all right, insert iLM tag to this editor
  5539. } else {
  5540. // error trying to insert
  5541. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5542. }
  5543. //window.close();
  5544. //]]>
  5545. </script>\n";
  5546. print $output;
  5547. die();
  5548. }
  5549. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5550. // @param string $key Key for return information
  5551. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5552. function get_dir_ilm ($key) {
  5553. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5554. $context = context_course::instance($this->id);
  5555. $dirid = optional_param('dirid', 0, PARAM_INT);
  5556. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5557. if ($dirid == 0) {
  5558. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5559. $dirid = $dir->get_id();
  5560. }
  5561. else {
  5562. $dir = $fs->get_file_by_id($dirid);
  5563. $dir_base = $dir->get_filepath();
  5564. }
  5565. $dir_parent = $dir->get_parent_directory();
  5566. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5567. return $data[$key];
  5568. }
  5569. /// Function for create an new dir
  5570. function new_dir_ilm () {
  5571. global $USER;
  5572. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5573. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5574. $dir_base = $this->get_dir_ilm('dir_base');
  5575. $context = context_course::instance($this->id);
  5576. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5577. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5578. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5579. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5580. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5581. }
  5582. /// Function for delete an dir
  5583. function delete_dir_ilm () { //
  5584. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5585. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5586. $context = context_course::instance($this->id);
  5587. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5588. $dir_parent = $this->get_dir_ilm('dir_parent');
  5589. if ($dir) {
  5590. if ($dir->is_directory()) {
  5591. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5592. foreach ($files_delete as $value)
  5593. $value->delete();
  5594. $dir->delete();
  5595. }
  5596. }
  5597. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5598. die();
  5599. }
  5600. /// Function for rename an dir
  5601. function rename_dir_ilm () {
  5602. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5603. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5604. $context = context_course::instance($this->id);
  5605. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5606. $dir_parent = $this->get_dir_ilm('dir_parent');
  5607. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5608. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5609. if ($dir->is_directory()) {
  5610. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5611. foreach ($files_rename_path as $value)
  5612. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5613. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5614. }
  5615. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5616. die();
  5617. }
  5618. /// Function for move an dir and your content for other dir
  5619. function selected_move_ilm () {
  5620. global $PAGE, $OUTPUT, $CFG;
  5621. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5622. $context = context_course::instance($this->id);
  5623. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5624. $dirid = $this->get_dir_ilm('dirid');
  5625. $dir_base = $this->get_dir_ilm('dir_base');
  5626. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5627. $code_javascript_ilm = "
  5628. <script type='text/javascript'>
  5629. //<![CDATA[
  5630. function getRadiobutton () {
  5631. var radioButtons = document.getElementsByTagName('input');
  5632. var param = '';
  5633. for (var counter=0; counter < radioButtons.length; counter++) {
  5634. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5635. param = radioButtons[counter].value;
  5636. }
  5637. return param;
  5638. }
  5639. function move_selected_ilm () {
  5640. var msgAnswer;
  5641. if (getRadiobutton() != '') {
  5642. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5643. if (msgAnswer)
  5644. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5645. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5646. }
  5647. else
  5648. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5649. }
  5650. function cancel_selected_ilm () {
  5651. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5652. }
  5653. //]]>
  5654. </script>\n";
  5655. $title = get_string('move_files', 'iassign');
  5656. $PAGE->set_title($title);
  5657. $PAGE->set_pagelayout('base');
  5658. print $OUTPUT->header();
  5659. print $OUTPUT->heading($title);
  5660. $dir_paths = array();
  5661. print $OUTPUT->box_start();
  5662. print "<center>";
  5663. foreach ($files_id as $file_id) {
  5664. $file = $fs->get_file_by_id($file_id);
  5665. if ($file) {
  5666. if (!$file->is_directory())
  5667. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5668. else {
  5669. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5670. array_push($dir_paths, $file->get_filepath());
  5671. }
  5672. }
  5673. }
  5674. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5675. if ($dir_base != '/') {
  5676. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5677. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5678. }
  5679. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5680. foreach ($files_tree as $file) {
  5681. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5682. $is_parent = false;
  5683. foreach ($dir_paths as $dir) {
  5684. $path = explode("/", $dir);
  5685. array_pop($path);
  5686. $path[count($path) - 1] = '';
  5687. $path = implode("/", $path);
  5688. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5689. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5690. }
  5691. if ($is_parent == false) {
  5692. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5693. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5694. }
  5695. }
  5696. }
  5697. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5698. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5699. print "</center>";
  5700. print $OUTPUT->box_end();
  5701. print $OUTPUT->footer();
  5702. print $code_javascript_ilm;
  5703. die;
  5704. }
  5705. /// Function for move files for an dir
  5706. function move_files_ilm () {
  5707. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5708. $context = context_course::instance($this->id);
  5709. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5710. $dirid = $this->get_dir_ilm('dirid');
  5711. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5712. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5713. foreach ($files_id as $file_id) {
  5714. $file = $fs->get_file_by_id($file_id);
  5715. if ($file) {
  5716. if ($file->is_directory()) {
  5717. $pathname = explode("/", $file->get_filepath());
  5718. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5719. foreach ($files_move_path as $value) {
  5720. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5721. $value->rename($path_move, $value->get_filename());
  5722. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5723. }
  5724. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5725. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5726. $file->rename($path_move, $file->get_filename());
  5727. } else {
  5728. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5729. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5730. }
  5731. }
  5732. }
  5733. //die;
  5734. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5735. die();
  5736. } // function move_files_ilm()
  5737. /// Function for recover files in use on all activities of a course
  5738. function recover_files_ilm () {
  5739. global $DB, $USER;
  5740. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5741. $courseid = optional_param('id', NULL, PARAM_INT);
  5742. $dirid = $this->get_dir_ilm('dirid');
  5743. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5744. $contextfile = context_course::instance($this->id);
  5745. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5746. foreach ($iassigns as $iassign) {
  5747. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5748. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5749. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5750. $context = context_module::instance($cm->id);
  5751. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5752. if ($files) {
  5753. foreach ($files as $value) {
  5754. $extension = explode(".", $value->get_filename());
  5755. if (!$value->is_directory()) {
  5756. $fileinfo = array('contextid' => $contextfile->id,
  5757. 'component' => 'mod_iassign',
  5758. 'filearea' => 'activity',
  5759. 'itemid' => 0,
  5760. 'filepath' => $this->get_dir_ilm('dir_base'),
  5761. 'userid' => $USER->id,
  5762. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5763. 'license' => 'allrightsreserved',
  5764. 'timecreated' => time(),
  5765. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5766. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5767. }
  5768. }
  5769. } // if ($files)
  5770. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5771. } // foreach ($iassigns as $iassign)
  5772. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5773. die();
  5774. } // function recover_files_ilm()
  5775. /// Auxiliary function the get all files in a given context
  5776. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5777. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5778. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5779. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5780. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5781. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5782. // (NAO s_iassign_statement.file = s_files.id)
  5783. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5784. $dir_base = $this->get_dir_ilm('dir_base');
  5785. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5786. $countf = 0;
  5787. $array_files_id = array(); // all files from this context
  5788. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5789. //$filename = $item_fc->get_filename();
  5790. //$filepath = $item_fc->get_filepath();
  5791. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5792. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5793. // $array_files_aux[] = $item_fc;
  5794. $itemid = $item_fc->get_id();
  5795. if (!in_array($itemid, $array_files_id)) {
  5796. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5797. if ($fileuserid == $userid)
  5798. $filesfrommine[] = $item_fc;
  5799. else
  5800. $filesfromothers[] = $item_fc;
  5801. $array_files_id[] = $itemid;
  5802. $countf++;
  5803. }
  5804. }
  5805. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5806. return $countf;
  5807. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5808. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5809. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5810. function get_all_ilm_files_by_fileid ($fileid) {
  5811. global $DB, $USER;
  5812. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5813. //TODO Criar coluna 'authorid'
  5814. $str_query = "SELECT * FROM {iassign_statement} " .
  5815. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5816. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5817. return $array_iassign_ilm;
  5818. }
  5819. //NN
  5820. //NN
  5821. // Build string with JavaScript code with function to edit/remove/double iLM files
  5822. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5823. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5824. global $CFG;
  5825. $error_files_exists = get_string('error_file_exists', 'iassign');
  5826. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5827. $code_javascript_ilm = "
  5828. <script type='text/javascript'>
  5829. //<![CDATA[
  5830. function preview_ilm (fileid, ilmid) { //JavaScript function
  5831. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5832. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5833. }
  5834. function update_ilm (ilmid, fileid) { //JavaScript function
  5835. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5836. }
  5837. function delete_ilm (ilmid, fileid) { //JavaScript function
  5838. var msgAnswer;
  5839. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5840. if (msgAnswer) {
  5841. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5842. }
  5843. }
  5844. function delete_selected_ilm () { //JavaScript function
  5845. var msgAnswer;
  5846. var param = getCheckbox();
  5847. if (param.join() != '') {
  5848. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5849. if (msgAnswer)
  5850. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5851. }
  5852. else
  5853. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5854. }
  5855. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5856. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5857. }
  5858. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5859. var filenamecopy;
  5860. var i;
  5861. var files = new Array(" . $files_array . ");
  5862. do {
  5863. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5864. } while (filenamecopy == '');
  5865. if (filenamecopy == null)
  5866. return false;\n
  5867. else {
  5868. for (i=0;i<files.length;i++) {
  5869. if (files[i]==filenamecopy) {
  5870. alert('" . $error_files_exists . "');
  5871. return false;\n
  5872. }
  5873. }\n" .
  5874. // @see: function 'duplicate_file_ilm()' above
  5875. "
  5876. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5877. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5878. } // else
  5879. }
  5880. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5881. var filenamecopy;
  5882. var i;
  5883. var files = new Array($files_array);
  5884. do {
  5885. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5886. } while (filenamecopy == '');
  5887. if (filenamecopy == null)
  5888. return false;
  5889. else {
  5890. for (i=0;i<files.length;i++) {
  5891. if (files[i]==filenamecopy) {
  5892. alert('" . $error_files_exists . "');
  5893. return false;
  5894. }
  5895. }
  5896. 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;
  5897. }
  5898. }
  5899. function export_files_ilm () { //JavaScript function
  5900. var param = getCheckbox();
  5901. if (param.join() != '')
  5902. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5903. else
  5904. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5905. }
  5906. function select_all_ilm () { //JavaScript function
  5907. var checkBoxes = document.getElementsByTagName('input');
  5908. var selectAll = document.getElementById('select_all');
  5909. for (var counter=0; counter < checkBoxes.length; counter++) {
  5910. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5911. checkBoxes[counter].checked = selectAll.checked;
  5912. }
  5913. }
  5914. function getCheckbox () { //JavaScript function
  5915. var checkBoxes = document.getElementsByTagName('input');
  5916. var param = new Array();
  5917. for (var counter=0; counter < checkBoxes.length; counter++) {
  5918. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5919. param.push(checkBoxes[counter].value);
  5920. }
  5921. return param;
  5922. }
  5923. function new_dir_ilm () { //JavaScript function
  5924. var dirname = '';
  5925. var i;
  5926. var dirs = new Array(" . $dirs_array . ");
  5927. do {
  5928. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5929. } while (dirname == '');
  5930. if (dirname == null)
  5931. return false;\n
  5932. else {
  5933. for (i=0;i<dirs.length;i++) {
  5934. if (dirs[i]==dirname) {
  5935. alert('" . $error_dir_exists . "');
  5936. return false;\n
  5937. }
  5938. }
  5939. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5940. }
  5941. }
  5942. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5943. var msgAnswer;
  5944. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5945. if (msgAnswer) {
  5946. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5947. }
  5948. }
  5949. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5950. var dirnamecopy;
  5951. var i;
  5952. var dirs = new Array($dirs_array);
  5953. do {
  5954. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5955. } while (dirnamecopy == '');
  5956. if (dirnamecopy == null)
  5957. return false;\n
  5958. else {
  5959. for (i=0;i<dirs.length;i++) {
  5960. if (dirs[i]==dirnamecopy) {
  5961. alert('" . $error_dir_exists . "');
  5962. return false;\n
  5963. }
  5964. }
  5965. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5966. }
  5967. }
  5968. function move_selected_ilm (ilmid) { //JavaScript function
  5969. var param = getCheckbox();
  5970. if (param.join() != '')
  5971. 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();
  5972. else
  5973. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5974. }
  5975. function recover_files_ilm () { //JavaScript function
  5976. var msgAnswer;
  5977. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5978. if (msgAnswer) {
  5979. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5980. }
  5981. }
  5982. window.onload = function() { //JavaScript function
  5983. var xPosition = 0;
  5984. var yPosition = 0;
  5985. element=document.getElementById('new_file');
  5986. while(element) {
  5987. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5988. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5989. element = element.offsetParent;
  5990. }
  5991. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5992. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5993. location.hash = '#new_file';
  5994. };
  5995. //]]>
  5996. </script>\n"; // end of $code_javascript_ilm
  5997. return $code_javascript_ilm;
  5998. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5999. /// List iassign files from course directory
  6000. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6001. function view_files_ilm ($iassign_ilm_class, $extension) {
  6002. global $CFG, $DB, $USER, $OUTPUT;
  6003. $fs = get_file_storage();
  6004. $context = context_course::instance($this->id);
  6005. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6006. $dirid = $this->get_dir_ilm('dirid');
  6007. $dir_base = $this->get_dir_ilm('dir_base');
  6008. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6009. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6010. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6011. $files_array = '';
  6012. foreach ($files_course as $value) {
  6013. if (!$value->is_directory())
  6014. $files_array .= "'" . $value->get_filename() . "',";
  6015. }
  6016. $files_array .= "''";
  6017. $error_files_exists = get_string('error_file_exists', 'iassign');
  6018. $dirs_array = '';
  6019. foreach ($files_course as $value) {
  6020. if ($value->is_directory()) {
  6021. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6022. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6023. }
  6024. }
  6025. $dirs_array .= "''";
  6026. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6027. // TODO Rever o preview pois só deixar ver uma vez.
  6028. $code_javascript_ilm = "
  6029. <script type='text/javascript'>
  6030. //<![CDATA[
  6031. function preview_ilm (fileid, ilmid) {
  6032. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6033. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6034. }
  6035. function update_ilm (ilmid, fileid) {
  6036. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6037. }
  6038. function delete_ilm (ilmid, fileid) {
  6039. var msgAnswer;
  6040. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6041. if (msgAnswer) {
  6042. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6043. }
  6044. }
  6045. function delete_selected_ilm () {
  6046. var msgAnswer;
  6047. var param = getCheckbox();
  6048. if (param.join() != '') {
  6049. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6050. if (msgAnswer)
  6051. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6052. }
  6053. else
  6054. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6055. }
  6056. function add_ilm_iassign (ilmid, filename, fileid) {
  6057. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6058. }
  6059. function duplicate_ilm (ilmid, filename, fileid) {
  6060. var filenamecopy;
  6061. var i;
  6062. var files = new Array($files_array);
  6063. do {
  6064. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6065. } while (filenamecopy == '');
  6066. if (filenamecopy == null)
  6067. return false;\n
  6068. else {
  6069. for (i=0;i<files.length;i++) {
  6070. if (files[i]==filenamecopy) {
  6071. alert('$error_files_exists');
  6072. return false;\n
  6073. }
  6074. }\n" .
  6075. // @see: function 'duplicate_file_ilm()' above
  6076. "
  6077. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6078. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6079. } // else
  6080. }
  6081. function rename_ilm (ilmid, filename, fileid) {
  6082. var filenamecopy;
  6083. var i;
  6084. var files = new Array($files_array);
  6085. do {
  6086. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6087. } while (filenamecopy == '');
  6088. if (filenamecopy == null)
  6089. return false;
  6090. else {
  6091. for (i=0;i<files.length;i++) {
  6092. if (files[i]==filenamecopy) {
  6093. alert('$error_files_exists');
  6094. return false;
  6095. }
  6096. }
  6097. 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;
  6098. }
  6099. }
  6100. function export_files_ilm () {
  6101. var param = getCheckbox();
  6102. if (param.join() != '')
  6103. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6104. else
  6105. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6106. }
  6107. function select_all_ilm () {
  6108. var checkBoxes = document.getElementsByTagName('input');
  6109. var selectAll = document.getElementById('select_all');
  6110. for (var counter=0; counter < checkBoxes.length; counter++) {
  6111. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6112. checkBoxes[counter].checked = selectAll.checked;
  6113. }
  6114. }
  6115. function getCheckbox () {
  6116. var checkBoxes = document.getElementsByTagName('input');
  6117. var param = new Array();
  6118. for (var counter=0; counter < checkBoxes.length; counter++) {
  6119. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6120. param.push(checkBoxes[counter].value);
  6121. }
  6122. return param;
  6123. }
  6124. function new_dir_ilm () {
  6125. var dirname = '';
  6126. var i;
  6127. var dirs = new Array($dirs_array);
  6128. do {
  6129. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6130. } while (dirname == '');
  6131. if (dirname == null)
  6132. return false;\n
  6133. else {
  6134. for (i=0;i<dirs.length;i++) {
  6135. if (dirs[i]==dirname) {
  6136. alert('$error_dir_exists');
  6137. return false;\n
  6138. }
  6139. }
  6140. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6141. }
  6142. }
  6143. function delete_dir_ilm (ilmid, dirid) {
  6144. var msgAnswer;
  6145. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6146. if (msgAnswer) {
  6147. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6148. }
  6149. }
  6150. function rename_dir_ilm (ilmid, dirname, dirid) {
  6151. var dirnamecopy;
  6152. var i;
  6153. var dirs = new Array($dirs_array);
  6154. do {
  6155. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6156. } while (dirnamecopy == '');
  6157. if (dirnamecopy == null)
  6158. return false;\n
  6159. else {
  6160. for (i=0;i<dirs.length;i++) {
  6161. if (dirs[i]==dirnamecopy) {
  6162. alert('$error_dir_exists');
  6163. return false;\n
  6164. }
  6165. }
  6166. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6167. }
  6168. }
  6169. function move_selected_ilm (ilmid) {
  6170. var param = getCheckbox();
  6171. if (param.join() != '')
  6172. 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();
  6173. else
  6174. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6175. }
  6176. function recover_files_ilm () {
  6177. var msgAnswer;
  6178. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6179. if (msgAnswer) {
  6180. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6181. }
  6182. }
  6183. window.onload = function() {
  6184. var xPosition = 0;
  6185. var yPosition = 0;
  6186. element=document.getElementById('new_file');
  6187. while(element) {
  6188. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6189. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6190. element = element.offsetParent;
  6191. }
  6192. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6193. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6194. location.hash = '#new_file';
  6195. };
  6196. //]]>
  6197. </script>\n";
  6198. $output = "";
  6199. $select_all = "";
  6200. $count_files = 0;
  6201. $extensions_allow = array();
  6202. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6203. foreach ($iassign_ilm as $item_iassign_ilm)
  6204. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6205. foreach ($files_course as $value) {
  6206. $filename = $value->get_filename();
  6207. $filepath = $value->get_filepath();
  6208. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6209. $pathname = $pathname[count($pathname) - 1];
  6210. $fileid = $value->get_id();
  6211. $tmp = explode(".", $filename);
  6212. if (count($tmp)>1) // avoid error if the file has no extension
  6213. $filetype = $tmp[1];
  6214. else // probably error...
  6215. $filetype = '';
  6216. $author = $value->get_author();
  6217. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6218. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6219. $extensions = explode(",", $extension);
  6220. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6221. $count_files ++;
  6222. // buscar fileid nas tabelas do iassign
  6223. $list_filein_use = "";
  6224. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6225. if ($iassign_statement_activity_list) {
  6226. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6227. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6228. }
  6229. }
  6230. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6231. if (!$iassign_ilm) {
  6232. $iassign_ilm = new stdClass();
  6233. $iassign_ilm->id = $ilmid;
  6234. }
  6235. // Do not use $var inside "..." - problem with some "unusual" operational system
  6236. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6237. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6238. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6239. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6240. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6241. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6242. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6243. $check_select = "";
  6244. $link_rename = "";
  6245. $link_delete = "";
  6246. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6247. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6248. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6249. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6250. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6251. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6252. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6253. if ($value->get_userid() == $USER->id) {
  6254. if ($iassign_statement_activity_list) {
  6255. $check_select = "";
  6256. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6257. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6258. $link_rename = "";
  6259. } else {
  6260. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6261. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6262. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6263. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6264. }
  6265. }
  6266. if (!in_array($filetype, $extensions_allow)) {
  6267. $link_edit = "";
  6268. $link_add_ilm_iassign = "";
  6269. $link_add_ilm_tinymce = "";
  6270. $link_add_ilm_atto = "";
  6271. $link_filter = "";
  6272. }
  6273. if ($value->is_directory()) {
  6274. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6275. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6276. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6277. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6278. <td><center>$author</center></td>
  6279. <td><center>$timecreated</center></td>
  6280. <td><center>$timemodified</center></td></tr>\n";
  6281. }
  6282. else if ($this->from == 'iassign') {
  6283. $new_id = "";
  6284. $new_class = "";
  6285. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6286. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6287. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6288. }
  6289. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6290. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6291. <td><center>$author</center></td>
  6292. <td><center>$timecreated</center></td>
  6293. <td><center>$timemodified</center></td></tr>\n";
  6294. }
  6295. else if ($this->from == 'block') {
  6296. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6297. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6298. <td><center>$author</center></td>
  6299. <td><center>$timecreated</center></td>
  6300. <td><center>$timemodified</center></td></tr>\n";
  6301. }
  6302. else if ($this->from == 'tinymce') {
  6303. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6304. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6305. <td><center>$author</center></td>
  6306. <td><center>$timecreated</center></td>
  6307. <td><center>$timemodified</center></td></tr>\n";
  6308. }
  6309. else if ($this->from == 'atto') {
  6310. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6311. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6312. <td><center>$author</center></td>
  6313. <td><center>$timecreated</center></td>
  6314. <td><center>$timemodified</center></td></tr>\n";
  6315. }
  6316. }
  6317. }
  6318. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6319. $dir_base = "";
  6320. $header = "";
  6321. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6322. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6323. foreach ($basename as $value) {
  6324. $dir_base .= $value . "/";
  6325. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6326. if ($dir_id) {
  6327. if ($value == "") {
  6328. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6329. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6330. } else {
  6331. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6332. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6333. }
  6334. }
  6335. } // foreach ($basename as $value)
  6336. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6337. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6338. $html .= "
  6339. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6340. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6341. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6342. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6343. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6344. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6345. </table>\n";
  6346. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6347. $html .= "<table width='100%'><tr>\n";
  6348. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6349. if ($count_files != 0) {
  6350. $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";
  6351. $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";
  6352. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6353. }
  6354. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6355. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6356. $html .= "</form>\n";
  6357. print $code_javascript_ilm;
  6358. print $html;
  6359. } // function view_files_ilm($extension)
  6360. } // class ilm_manager
  6361. /// Class to insert of icons
  6362. class iassign_icons {
  6363. static function insert ($icon) {
  6364. global $CFG;
  6365. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6366. return $string;
  6367. }
  6368. }
  6369. /// Class with util functions for plugin manage
  6370. class iassign_utils {
  6371. /// Function to return the filename extension
  6372. // @param string The $filename as an string
  6373. // @return string Return an string (last group after '.')
  6374. static function filename_extension ($filename) {
  6375. if ($filename == null || $filename == '') {
  6376. return null;
  6377. }
  6378. $itens = explode('.', $filename);
  6379. $num = count($itens);
  6380. if ($num < 2) {
  6381. return null;
  6382. }
  6383. return $itens[$num - 1];
  6384. }
  6385. /// Use the PHP class/package ZipArchive to create a Zip file
  6386. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6387. // 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
  6388. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6389. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6390. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6391. $zip = new zip_archive(); //2
  6392. $res = $zip->open($full_path_zip_filename);
  6393. $total_vet = count($vet_student_filename);
  6394. for ($ii=0; $ii<$total_vet; $ii++) {
  6395. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6396. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6397. }
  6398. $ret = $zip->close();
  6399. iassign_utils::download_file($full_path_zip_filename);
  6400. $filenameZip = $zip->filename;
  6401. return array($ret, $zip);
  6402. }
  6403. static function download_file ($zip_filename) {
  6404. header("Pragma: public");
  6405. header("Expires: 0");
  6406. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6407. header("Cache-Control: private", false);
  6408. header("Content-Type: application/zip");
  6409. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6410. header("Content-Transfer-Encoding: binary");
  6411. header("Content-Length: " . @filesize($zip_filename));
  6412. set_time_limit(0);
  6413. @readfile("$zip_filename") || die("File not found.");
  6414. unlink($zip_filename);
  6415. }
  6416. /// Function for format filename remove special caracters
  6417. // @param string $text String for clean
  6418. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6419. // @return string Return an string in clean format
  6420. static function format_filename ($text) {
  6421. if ($text != '.') {
  6422. //D $text = htmlspecialchars(urldecode($text));
  6423. //D echo "locallib.php: format_filename: $text<br/>";
  6424. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6425. $text = json_decode($text)->{current_language()};
  6426. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6427. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6428. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6429. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6430. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6431. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6432. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6433. // E.g. text = "exerc_midpoint.course.geo"
  6434. // 0123456789012345678901234
  6435. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6436. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6437. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6438. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6439. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6440. //$ext = strrpos($text, ".");
  6441. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6442. //$text = str_replace($array1, $array2, $text);
  6443. }
  6444. return $text;
  6445. }
  6446. /// Function to filter characters to the file name to iLM content
  6447. // @param string $text String for clean
  6448. // @param string $ext String ot the extension of the iLM
  6449. // @return string Return an string in clean format
  6450. static function filter_filename_extension ($filename, $ext) {
  6451. if ($filename != '.') {
  6452. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6453. $arrTo = array("_","","","","","","","","","","","","");
  6454. $filename = str_replace($arrFrom, $arrTo, $filename);
  6455. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6456. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6457. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6458. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6459. $index_lastposition = strlen($filenameF);
  6460. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6461. $text = str_replace(".", "_", $text); // erase all other "."
  6462. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6463. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6464. }
  6465. else
  6466. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6467. return $filenameF;
  6468. }
  6469. /// Function for format pathname remove special caracters
  6470. // @param string $text String for clean
  6471. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6472. // @return string Return an string in clean format
  6473. static function format_pathname ($text, $is_lowercase = true) {
  6474. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6475. $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", "-", "_", "", "", "");
  6476. $text = str_replace($array1, $array2, $text);
  6477. if ($is_lowercase)
  6478. $text = strtolower($text);
  6479. return $text;
  6480. }
  6481. /// Function for format file name from iLM original name
  6482. // @param string $text String to build the file neam
  6483. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6484. // @return string Return an string in clean format
  6485. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6486. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6487. $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", "-", "_", "", "", "");
  6488. $index_firstposition_blank = strpos($ilm_name, " ");
  6489. if ($index_firstposition_blank) { // truncate the name!
  6490. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6491. }
  6492. $index_firstposition_dots = strpos($ilm_name, ":");
  6493. if ($index_firstposition_dots) { // truncate the name!
  6494. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6495. }
  6496. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6497. if ($is_lowercase)
  6498. $namefiltered = strtolower($namefiltered);
  6499. return $namefiltered;
  6500. }
  6501. /// Function for insert version in the filename
  6502. // @param string $filename Name of file
  6503. // @return string Return the filename with version
  6504. static function version_filename ($filename) {
  6505. $array_filename = explode('.', $filename);
  6506. if (count($array_filename) > 1)
  6507. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6508. else
  6509. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6510. return $filename;
  6511. }
  6512. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6513. static function remove_code_message ($string) {
  6514. $array = explode("&lt;ia_uc&gt;", $string);
  6515. return $array[0];
  6516. }
  6517. }
  6518. // class iassign_utils
  6519. /// Class with language functions for plugin manage
  6520. class iassign_language {
  6521. /// Function for return text in language or get default language (en)
  6522. // @param string $lang Code of language
  6523. // @param string $description JSON text content all languages
  6524. // @return string Return an string in the language selected
  6525. static function get_description_lang ($lang, $descriptions) {
  6526. $description_lang = "";
  6527. $description = json_decode($descriptions);
  6528. if ($description == null) {
  6529. $description_lang = $descriptions;
  6530. }
  6531. else {
  6532. if (isset($description->{$lang}))
  6533. $description_lang = $description->{$lang};
  6534. else
  6535. if (isset($description->en)) //MOOC2014
  6536. $description_lang = $description->en;
  6537. else //MOOC2014
  6538. $description_lang = "en"; //MOOC2014
  6539. }
  6540. return $description_lang;
  6541. }
  6542. /// Function for return all language supported by iLM
  6543. // @param string $descriptions JSON text content all languages
  6544. // @return string Return as string with all languages
  6545. static function get_all_lang ($descriptions) {
  6546. $langs = "";
  6547. $description = json_decode($descriptions);
  6548. if ($description) {
  6549. foreach ($description as $key => $value) {
  6550. $langs .= $key . " ; ";
  6551. }
  6552. $langs = substr($langs, 0, strlen($langs) - 3);
  6553. }
  6554. return $langs;
  6555. }
  6556. /// Function for convert json in xml //MOOC2014
  6557. // @param string $json JSON text
  6558. // @return string Return as string with xml tags
  6559. static function json_to_xml ($json) {
  6560. $xml = "";
  6561. $json = json_decode($json);
  6562. foreach ($json as $key => $value) {
  6563. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6564. }
  6565. return $xml;
  6566. }
  6567. }
  6568. // class iassign_language
  6569. /// Class with log functions for plugin manage.
  6570. class iassign_log {
  6571. /// Function for insert log event
  6572. // @param string $action Code action of event
  6573. // @param string $information Text for describe action of event
  6574. // @param int $cmid Id of context module
  6575. // @param int $ilmid Id of iLM
  6576. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6577. global $COURSE, $CFG, $USER, $DB;
  6578. $newentry = new stdClass();
  6579. $newentry->time = time();
  6580. $newentry->userid = $USER->id;
  6581. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6582. $newentry->course = $COURSE->id;
  6583. $newentry->cmid = $cmid;
  6584. $newentry->ilmid = $ilmid;
  6585. $newentry->action = $action;
  6586. $newentry->info = $information;
  6587. $newentry->language = current_language();
  6588. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6589. if (ini_get("browscap") && function_exists('get_browse')) {
  6590. $browser = get_browse(null, true);
  6591. $newentry->javascript = $browser['javascript'];
  6592. $newentry->java = $browser['javaapplets'];
  6593. }
  6594. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6595. print_error('error_add_log', 'iassign');
  6596. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6597. } // class iassign_log