1
0

locallib.php 388 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. //'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'all_submissions' => '$this->all_submissions();',
  278. 'delete_submissions' => '$this->delete_submissions();',
  279. 'download_submissions' => '$this->download_submissions();',
  280. 'open_individual_submission' => '$this->open_individual_submission();',
  281. 'get_individual_submission' => '$this->get_individual_submission();',
  282. 'get_student_submission' => '$this->get_student_submission();',
  283. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  284. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  285. );
  286. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  287. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  288. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  289. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  290. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  291. }
  292. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  293. eval($action_iassign_limit[$this->action]);
  294. }
  295. else { // Student reaches this point
  296. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  297. // Arrive here with: "get_answer"; "view"
  298. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  299. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  300. }
  301. } // function action()
  302. /// This method prints the student submission to a specific exercise
  303. function get_student_submission () {
  304. global $DB;
  305. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  306. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  307. if (!$student || !$exercise) exit;
  308. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  309. if ($iassign_submission)
  310. print($iassign_submission->answer);
  311. die();
  312. }
  313. /// This method prints the teacher exercise
  314. function get_teacher_exercise () {
  315. global $DB, $COURSE;
  316. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  317. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  318. $fs = get_file_storage(); // Get reference to all files in Moodle data
  319. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  320. foreach ($files as $file) {
  321. if ($file->get_filename() != ".") {
  322. print($file->get_content());
  323. }
  324. }
  325. die();
  326. }
  327. /// This method receives the data from auto_eval event
  328. /// @see auto_evaluate()
  329. function post_auto_eval_result () {
  330. global $COURSE, $CFG, $USER, $DB;
  331. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  332. exit;
  333. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  334. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  335. $student = optional_param('student', -1, PARAM_INT);
  336. $grade = optional_param('grade', 0, PARAM_FLOAT);
  337. // 1: Recuperar a nota atual:
  338. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  339. // 2: Atualizar a tabela:
  340. $update_entry = new stdClass();
  341. $update_entry->id = $actual->id;
  342. $update_entry->previous_grade = $actual->grade;
  343. $update_entry->grade = $grade;
  344. // Update the iassign_submission
  345. $DB->update_record("iassign_submission", $update_entry);
  346. }
  347. /// Function to help download all_submissions files
  348. function download_submissions_help ($list) {
  349. global $DB, $CFG, $OUTPUT;
  350. // Get list of iLMs
  351. $ilm_list = $DB->get_records("iassign_ilm");
  352. // Get list of enrolled students:
  353. $params_temp = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  355. $context = context_course::instance($this->course->id);
  356. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  359. $json_obj = new stdclass();
  360. $json_obj->submissions = [];
  361. $csvfields = [];
  362. $csvfields[] = 'submissionid';
  363. $csvfields[] = 'file';
  364. $csvfields[] = 'filesize';
  365. $csvfields[] = 'timestamp';
  366. $csvfields[] = 'humandate';
  367. $csvfields[] = 'grade';
  368. $csvfields[] = 'userid';
  369. $csvfields[] = 'exerciseid';
  370. $json_obj->submissions[] = $csvfields;
  371. $exercise_dir = [];
  372. $exercises_list = [];
  373. foreach ($list as $item) {
  374. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  375. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  376. $exercises_list[] = $temp;
  377. $exercise_dir[] = $temp->id;
  378. }
  379. }
  380. $student_dir = [];
  381. $students_list = [];
  382. foreach ($list as $item) {
  383. if (!in_array($item->userid, $student_dir)) {
  384. $temp = $DB->get_record("user", array("id" => $item->userid));
  385. $students_list[] = $temp;
  386. $student_dir[] = $temp->id;
  387. }
  388. }
  389. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. //TODO: tem que criar moodledata/temp/iassign_files
  391. // Create $CFG->dataroot/temp/iassign_files
  392. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  393. if (!file_exists($tempfilespath)) {
  394. mkdir($tempfilespath, 0777, true);
  395. }
  396. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  397. if (!file_exists($iassignfilespath)) {
  398. mkdir($iassignfilespath, 0777, true);
  399. }
  400. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  401. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  402. if (!file_exists($diretorio)) {
  403. echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
  404. exit;
  405. }
  406. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  407. $zip = new zip_archive(); // create ZIP
  408. if (!$zip->open($zip_filename)) {
  409. echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
  410. exit;
  411. }
  412. ;
  413. foreach ($exercises_list as $exercise) {
  414. $dir_ex = iassign_utils::format_filename($exercise->name);
  415. $zip->add_directory($dir_ex);
  416. $extension_ilm = '';
  417. foreach ($ilm_list as $ilm) {
  418. if ($exercise->iassign_ilmid == $ilm->id) {
  419. $extension_ilm = $ilm->extension;
  420. break;
  421. }
  422. }
  423. foreach ($students_list as $student) {
  424. $individual_dir =
  425. $dir_ex . DIRECTORY_SEPARATOR .
  426. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  427. $zip->add_directory($individual_dir);
  428. $i = 1;
  429. foreach($list as $item) {
  430. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  431. $date = new DateTime();
  432. $date->setTimestamp($item->timecreated);
  433. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  434. $zip->add_file_from_string($new_file, $item->answer);
  435. $temp_json = [];
  436. $temp_json[] = intval($item->id);
  437. $temp_json[] = $new_file;
  438. $temp_json[] = strlen($new_file);
  439. $temp_json[] = intval($item->timecreated);
  440. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  441. $temp_json[] = doubleval($item->grade);
  442. $temp_json[] = intval($item->userid);
  443. $temp_json[] = intval($exercise->id);
  444. $json_obj->submissions[] = $temp_json;
  445. }
  446. }
  447. }
  448. }
  449. $csv_str = "";
  450. foreach($json_obj->submissions as $sub) {
  451. $csv_str .= $this->csvstr($sub) . "\n";
  452. }
  453. $zip->add_file_from_string('index.csv', $csv_str);
  454. $zip->close();
  455. iassign_utils::download_file($zip_filename);
  456. exit;
  457. }
  458. function csvstr(array $fields) : string {
  459. $f = fopen('php://memory', 'r+');
  460. if (fputcsv($f, $fields) === false) {
  461. return false;
  462. }
  463. rewind($f);
  464. $csv_line = stream_get_contents($f);
  465. return rtrim($csv_line);
  466. }
  467. /// Download submissions from table iassign_allsubmissions
  468. function download_submissions () {
  469. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  470. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  471. exit;
  472. $type = optional_param('type', NULL, PARAM_TEXT);
  473. $item = optional_param('item', NULL, PARAM_TEXT);
  474. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  475. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  476. $sub_list = [];
  477. if ($type == 'individual') {
  478. $sub_list[] = $DB->get_record(
  479. 'iassign_allsubmissions', array('id' => $item));
  480. } elseif ($type == 'student') {
  481. $sub_list = $DB->get_records(
  482. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  483. } elseif ($type == 'exercise') {
  484. $sub_list = $DB->get_records(
  485. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  486. } elseif ($type == 'block') {
  487. $exercises_in_block = $DB->get_records(
  488. 'iassign_statement', array('iassignid' => $iassign_id));
  489. foreach ($exercises_in_block as $exercise) {
  490. $temp = $DB->get_records(
  491. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  492. $sub_list = array_merge($sub_list, $temp);
  493. }
  494. }
  495. $this->download_submissions_help($sub_list);
  496. }
  497. /// Delete submissions in table iassign_allsubmissions
  498. function delete_submissions () {
  499. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  500. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  501. exit;
  502. $type = optional_param('type', NULL, PARAM_TEXT);
  503. $item = optional_param('item', NULL, PARAM_TEXT);
  504. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  505. if ($type == 'individual') {
  506. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  507. } elseif ($type == 'student') {
  508. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  509. } elseif ($type == 'exercise') {
  510. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  511. }
  512. }
  513. function get_individual_submission () {
  514. global $DB, $USER;
  515. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  516. exit;
  517. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  518. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  519. print $submission->answer;
  520. }
  521. /// Open individual submission
  522. function open_individual_submission () {
  523. global $DB, $USER, $CFG;
  524. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  525. exit;
  526. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  527. $id = $this->cm->id;
  528. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  529. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  530. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  531. $all_submissions = $DB->get_records('iassign_allsubmissions',
  532. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  533. $previous = null;
  534. $next = null;
  535. $i = 0;
  536. $found = false;
  537. foreach($all_submissions as $individual) {
  538. if (!$found && $individual->id != $submissionid) {
  539. $previous = $individual;
  540. }
  541. if ($found) {
  542. $next = $individual;
  543. break;
  544. }
  545. if ($individual->id === $submissionid) {
  546. $found = true;
  547. }
  548. $i ++;
  549. }
  550. print '<center style="padding-top: 2rem;">';
  551. if ($previous) {
  552. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  553. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  554. } else {
  555. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  556. }
  557. print ' (' . $i . '/' . count($all_submissions) . ')';
  558. if ($next) {
  559. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  560. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  561. } else {
  562. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  563. }
  564. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  565. print
  566. //array("type" => "editor_new", "notSEND" => "true")
  567. ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  568. print '</center>';
  569. }
  570. /// Manage all submissions in exercises to table iassign_allsubmissions
  571. function all_submissions () {
  572. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  573. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  574. exit;
  575. print $OUTPUT->header();
  576. $id = $this->cm->id;
  577. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  578. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  579. print '
  580. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  581. <div class="modal-dialog modal-dialog-centered" role="document">
  582. <div class="modal-content">
  583. <div class="modal-header">
  584. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  585. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  586. <span aria-hidden="true">&times;</span>
  587. </button>
  588. </div>
  589. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  590. <div class="modal-footer">
  591. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  592. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  593. </div>
  594. </div>
  595. </div>
  596. </div>'; // "
  597. print '
  598. <script>
  599. var sub_type;
  600. var sub_item;
  601. var sub_el;
  602. var sub_exercise;
  603. function delete_submission (type, item, el, exercise = 0) {
  604. sub_type = type;
  605. sub_item = item;
  606. sub_exercise = exercise;
  607. sub_el = el.closest("tr");
  608. if (!sub_el) sub_el = el.closest("a");
  609. $("#modalConfirm").modal();
  610. }
  611. function confirm_delete () {
  612. var url = "'.$enderecoPOST.'&action=delete_submissions";
  613. var xhttp = new XMLHttpRequest();
  614. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  615. xhttp.send();
  616. $("#modalConfirm").modal("hide");
  617. if ($(sub_el).attr("href"))
  618. $($(sub_el).attr("href")).remove();
  619. if (sub_el) sub_el.remove();
  620. }
  621. function download_submission(type, item, exercise = 0, iassign = 0) {
  622. var url = "'.$enderecoPOST.'&action=download_submissions";
  623. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  624. document.location = url;
  625. }
  626. function open_submission(item) {
  627. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  628. var poupup = window.open(url, "popup", "width=900,height=900");
  629. }
  630. </script>' . chr(13); // '
  631. // Get list of exercises in the instance:
  632. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  633. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  634. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  635. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  636. // Get list of enrolled students:
  637. $params_temp = array('shortname' => 'student');
  638. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  639. $context = context_course::instance($this->course->id);
  640. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  641. $students_list = $DB->get_records_sql(
  642. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  643. print '<div>';
  644. foreach ($exercises_list as $exercise) {
  645. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  646. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  647. print '
  648. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  649. . $exercise->name
  650. . ' - ' . $iassign_ilm->name
  651. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  652. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  653. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  654. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  655. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  656. . '</a>';
  657. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  658. foreach ($students_list as $student) {
  659. $total = 0;
  660. $student_submissions = [];
  661. foreach ($submissions_list as $submission) {
  662. if ($submission->userid == $student->userid) {
  663. $student_submissions[] = $submission;
  664. $total ++;
  665. }
  666. }
  667. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  668. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  669. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  670. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  671. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  672. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  673. . ' </a>';
  674. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  675. print '<table class="table table-striped table-hover"><thead>
  676. <tr>
  677. <th scope="col">#</th>
  678. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  679. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  680. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  681. </tr>
  682. </thead><tbody>'; // "
  683. $i = 1;
  684. foreach ($student_submissions as $individual) {
  685. $date = new DateTime();
  686. $date->setTimestamp($individual->timecreated);
  687. print '<tr>';
  688. print '<td>'.$i++.'</td>';
  689. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  690. print '<td>'.$individual->grade.'</td>';
  691. print '<td>
  692. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  693. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  694. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  695. print " </tr>\n";
  696. }
  697. print '</tbody></table>';
  698. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  699. print '</div>';
  700. }
  701. print '</div>';
  702. }
  703. print '</div>';
  704. print $OUTPUT->footer();
  705. } // function all_submissions()
  706. /// This method runs activities auto evaluation in teacher area
  707. function auto_evaluate () {
  708. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  709. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  710. exit;
  711. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  712. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  713. // Get list of exercises in the instance:
  714. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  715. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  716. // Get list of enrolled students:
  717. $params_temp = array('shortname' => 'student');
  718. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  719. $context = context_course::instance($this->course->id);
  720. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  721. $students_list = $DB->get_records_sql(
  722. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  723. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  724. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  725. print $OUTPUT->header();
  726. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  727. print '<ul style="list-style-type: none; margin: 1em;">';
  728. foreach ($exercises_list as $exercise) {
  729. $matches = [];
  730. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  731. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  732. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  733. if ($matches[0][0]) {
  734. 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>';
  735. } else {
  736. 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>';
  737. }
  738. } else {
  739. if ($matches[0][0]) {
  740. 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>';
  741. } else {
  742. 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>';
  743. }
  744. }
  745. }
  746. print '</ul>
  747. <center>
  748. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  749. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  750. <div id="evaluate_message" style="color: red"></div>
  751. <div id="evaluate_alerts"></div>
  752. <div>
  753. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  754. <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>
  755. </div>
  756. </center>'; // close "
  757. print ' </div>' + "\n";
  758. print ' <script>';
  759. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  760. print ' var submissions = [';
  761. // Get list of student id have submit for each exercise:
  762. foreach ($exercises_list as $exercise) {
  763. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  764. print '
  765. {
  766. "exerciseid": "' . $exercise->id . '",
  767. "grade": ' . $exercise->grade . ',
  768. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  769. "submited": ['; // "
  770. $params_temp = array('iassign_statementid' => $exercise->id);
  771. $submited = $DB->get_records_sql( // Get userid and his grade
  772. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  773. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  774. foreach ($submited as $ss) {
  775. print($ss->userid . ',');
  776. }
  777. print '],';
  778. print '"allgrades": [';
  779. foreach ($submited as $ss) {
  780. print( $ss->grade . ',');
  781. }
  782. print ']
  783. },'; // close "
  784. } // foreach ($exercises_list as $exercise)
  785. print " ];\n";
  786. print '
  787. var total_submissions = 0;
  788. var selected_exercises;
  789. var count_steps;
  790. var value_by_step;
  791. var stoped = false;
  792. var time_interval = 5000;
  793. var var_interval;
  794. function add_hover_th (id_th, id_li) { //AJAX
  795. $("#" + id_th).hover(function() {
  796. $("#" + id_li).css("background-color", "#d9d8d8");
  797. $(this).css("background-color", "#d9d8d8");
  798. }, function() {
  799. $("#" + id_li).css("background-color", "");
  800. $(this).css("background-color", "");
  801. });
  802. }
  803. function start_evaluation () {
  804. stoped = false;
  805. //AJAX
  806. $("#progress_bar").css("display", "none");
  807. $("#evaluate_message").text("");
  808. $("#evaluate_alerts").text("");
  809. $(".added-col").remove();
  810. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  811. selected_exercises = [];
  812. var c = 0;
  813. for (var i = 0; i < exercises.length; i++) {
  814. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  815. selected_exercises[c++] = exercises[i];
  816. }
  817. }
  818. if (selected_exercises.length == 0) {
  819. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  820. return;
  821. } else {
  822. $("input:checkbox").attr("disabled", true); //AJAX
  823. for (var i = 0; i < selected_exercises.length; i++) {
  824. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  825. //AJAX
  826. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  827. $("#table-results tbody tr").each(function(e) {
  828. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  829. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  830. });
  831. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  832. }
  833. //AJAX
  834. $("#button_start").prop("disabled", true);
  835. $("#button_stop").prop("disabled", false);
  836. $("#progress_bar").css("display", "block");
  837. }
  838. total_submissions = selected_exercises.length * students.length;
  839. count_steps = 0;
  840. value_by_step = 100/total_submissions;
  841. actual_exercise = 0;
  842. actual_student = 0;
  843. actual_submission = 0;
  844. get_original_propositions();
  845. var_interval = setInterval(verifyBreak, time_interval);
  846. } // function start_evaluation()
  847. var actual_exercise;
  848. var actual_student;
  849. var actual_submission;
  850. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  851. function run_individual_evaluation () {
  852. if (stoped) return;
  853. // Verify if student really sent his answer
  854. var found = false;
  855. for (var j = 0; j < submissions.length; j++) {
  856. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  857. for (var k = 0; k < submissions[j].submited.length; k++) {
  858. if (students[actual_student] == submissions[j].submited[k]) {
  859. found = true;
  860. break;
  861. }
  862. }
  863. break;
  864. }
  865. }
  866. if (found == false) {
  867. postResultAutoEval();
  868. } else {
  869. // If it was sent, search it...
  870. var final_url = "";
  871. 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];
  872. for (var j = 0; j < submissions.length; j++) {
  873. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  874. final_url = submissions[j].ilm;
  875. break;
  876. }
  877. }
  878. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  879. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  880. window.frames["ifrm"].location=final_url;
  881. }
  882. } // function run_individual_evaluation()
  883. var break_student = -1;
  884. var break_exercise = -1;
  885. function verifyBreak () {
  886. if (actual_student == break_student && actual_exercise == break_exercise) {
  887. postResultAutoEval(-6);
  888. break_student = -1;
  889. break_exercise = -1;
  890. return;
  891. } else {
  892. break_student = actual_student;
  893. break_exercise = actual_exercise;
  894. }
  895. }
  896. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  897. function getStudentAnswerURL () {
  898. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  899. }
  900. // This function is called by the iLM!!!
  901. function getAutoEvalOriginalData () {
  902. return original_propositions[actual_exercise];
  903. }
  904. function updateProgressBar () {
  905. if (stoped) return;
  906. var temp = (count_steps * value_by_step)|0;
  907. count_steps ++;
  908. temp = temp > 100 ? 100 : temp;
  909. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  910. if (temp >= 100) {
  911. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  912. $("#button_start").prop("disabled", false);
  913. $("#button_stop").prop("disabled", true);
  914. $("input:checkbox").attr("disabled", false);
  915. clearInterval(var_interval);
  916. }
  917. }
  918. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  919. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  920. function postResultAutoEval (grade = null) {
  921. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  922. if (grade == null) {
  923. $("#"+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>\');
  924. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  925. } else {
  926. // Verify if the re-evaluation grade is the of that one registered:
  927. var actual_value = 0;
  928. var actual_student_grade = 0;
  929. for (var k = 0; k < submissions.length; k++) {
  930. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  931. actual_value = submissions[k].grade;
  932. for (var h = 0; h < submissions[k].submited.length; h++) {
  933. if (submissions[k].submited[h] == students[actual_student]) {
  934. actual_student_grade = submissions[k].allgrades[h];
  935. break;
  936. }
  937. }
  938. break;
  939. }
  940. }
  941. // @FeedbackConvention
  942. if (grade < 0) {
  943. switch (grade) {
  944. case -1:
  945. // Test-cases are empty:
  946. $("#"+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>\');
  947. var mm = actual_exercise;
  948. $("#"+id_t).find(".details-button").click(function(e) {
  949. $(".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>\');
  950. });
  951. break;
  952. case -2:
  953. // Test-cases were manually altered by the student (fraud!):
  954. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  955. var mm = actual_exercise;
  956. $("#"+id_t).find(".details-button").click(function(e) {
  957. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  958. });
  959. //AJAX
  960. $.ajax({
  961. dataType: "html",
  962. 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",
  963. success: function(d) {} });
  964. break;
  965. case -5:
  966. // Execution failed:
  967. $("#"+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>\');
  968. var mm = actual_exercise;
  969. //AJAX
  970. $("#"+id_t).find(".details-button").click(function(e) {
  971. $(".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>\');
  972. });
  973. break;
  974. case -6: // iLM not answering was detected in "verifyBreak()"
  975. // The iLM are not answering:
  976. //AJAX
  977. $("#"+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>\');
  978. $("#"+id_t).find(".details-button").click(function(e) {
  979. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  980. });
  981. break;
  982. }
  983. //AJAX
  984. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  985. } else {
  986. console.log((grade), (actual_student_grade));
  987. if ((grade) == (actual_student_grade)) {
  988. $("#"+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>\');
  989. } else { // Notas diferem:
  990. $("#"+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>\');
  991. var mm = actual_exercise;
  992. //AJAX
  993. $("#"+id_t).find(".details-button").click(function(e) {
  994. $(".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>\');
  995. });
  996. //AJAX
  997. // Send to the endpoint the post_auto_eval_result to verify:
  998. $.ajax({
  999. dataType: "html",
  1000. 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),
  1001. success: function(d) {}
  1002. });
  1003. }
  1004. //AJAX
  1005. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1006. }
  1007. }
  1008. updateProgressBar();
  1009. // Does it must continue in the same exercise or stop?
  1010. if (actual_student < students.length) {
  1011. actual_student ++;
  1012. run_individual_evaluation();
  1013. } else {
  1014. actual_student = 0;
  1015. // Does it go to next exercise or is it finished?
  1016. if (actual_exercise < selected_exercises.length) {
  1017. actual_exercise++;
  1018. run_individual_evaluation();
  1019. } else {
  1020. //AJAX
  1021. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1022. }
  1023. }
  1024. }
  1025. var original_propositions;
  1026. function get_original_propositions () {
  1027. original_propositions = [];
  1028. var count = 0;
  1029. for (var i = 0; i < exercises.length; i++) {
  1030. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1031. //AJAX
  1032. $.ajax({
  1033. dataType: "html",
  1034. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1035. success: function(d) { // variable "d" has the iLM content
  1036. original_propositions[count] = d; // exercise original content
  1037. count ++;
  1038. if (count == selected_exercises.length) {
  1039. run_individual_evaluation();
  1040. }
  1041. }
  1042. });
  1043. }
  1044. }
  1045. }
  1046. function stop_evaluation () {
  1047. stoped = true;
  1048. //AJAX
  1049. $("#button_start").prop("disabled", false);
  1050. $("#button_stop").prop("disabled", true);
  1051. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1052. $("input:checkbox").attr("disabled", false);
  1053. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1054. clearInterval(var_interval);
  1055. }
  1056. var exercises = [ '; // '
  1057. foreach ($exercises_list as $exercise) {
  1058. print $exercise->id . ',';
  1059. }
  1060. print ' ];';
  1061. print ' var students = [ ';
  1062. foreach ($students_list as $student) {
  1063. print $student->userid . ',';
  1064. }
  1065. print '];';
  1066. print ' var ilms = [';
  1067. foreach ($exercises_list as $exercise) {
  1068. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1069. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1070. }
  1071. print ']';
  1072. print '</script>';
  1073. print '
  1074. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1075. <div class="modal-dialog modal-dialog-centered" role="document">
  1076. <div class="modal-content">
  1077. <div class="modal-header">
  1078. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1079. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1080. <span aria-hidden="true">&times;</span>
  1081. </button>
  1082. </div>
  1083. <div class="modal-body">
  1084. ...
  1085. </div>
  1086. <div class="modal-footer">
  1087. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1088. </div>
  1089. </div>
  1090. </div>
  1091. </div>'; //
  1092. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1093. print '<table id="table-results" class="table table-hover m-t-1">
  1094. <thead>
  1095. <tr id="cols-exercises">
  1096. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1097. </tr>
  1098. </thead>
  1099. <tbody>'; // "
  1100. foreach ($students_list as $student) {
  1101. $user = $DB->get_record('user', array('id' => $student->userid));
  1102. $avatar = new user_picture($user);
  1103. $avatar->courseid = $COURSE->id;
  1104. $avatar->link = true;
  1105. print ' <tr data-student="' . $student->userid . '">
  1106. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1107. </tr>' . "\n"; // "
  1108. }
  1109. print " </tbody>
  1110. </table>\n";
  1111. print $OUTPUT->footer();
  1112. } // function auto_evaluate()
  1113. /// This method moves an iAssign activity
  1114. function move_activity () {
  1115. global $USER, $CFG, $DB, $COURSE;
  1116. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1117. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1118. $update_entry_new_iassign = new stdClass();
  1119. $update_entry_new_iassign->id = $iassign_id;
  1120. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1121. // Update the iassign_statement
  1122. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1123. // Update file context
  1124. $c_i = context_module::instance($this->cm->id);
  1125. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1126. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1127. $path_module = context_course::instance($COURSE->id);
  1128. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1129. if ($context_file) {
  1130. $id_context = $context_file->id;
  1131. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1132. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1133. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1134. foreach ($files as $value) {
  1135. if ($value->get_filename() != ".") {
  1136. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1137. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1138. $updateentry = new stdClass();
  1139. $updateentry->id = $iassign_id;
  1140. $updateentry->filesid = $newfile->get_itemid();
  1141. $DB->update_record("iassign_statement", $updateentry);
  1142. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1143. break;
  1144. }
  1145. }
  1146. }
  1147. $this->return_home_course('moved_activity');
  1148. exit;
  1149. }
  1150. /// This method duplicates an iAssign activity
  1151. function duplicate_activity () {
  1152. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1153. $id = $this->cm->id;
  1154. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1155. $context = context_module::instance($this->cm->id);
  1156. $contextuser = context_user::instance($USER->id);
  1157. // Get the the iAssign acitivity to be duplicated
  1158. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1159. // Remove the current id of activity
  1160. $iassign_statement->id=0;
  1161. // Get the information about current author, and add this information in author_modified field
  1162. $author = $DB->get_record("user", array('id' => $USER->id));
  1163. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1164. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1165. // Store the activity in the table
  1166. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1167. // Duplicate activity file
  1168. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1169. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1170. foreach ($files as $value) {
  1171. if ($value->get_filename() != ".") {
  1172. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1173. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1174. $updateentry = new stdClass();
  1175. $updateentry->id = $id_;
  1176. $updateentry->filesid = $newfile->get_itemid();
  1177. // Update the duplicated iLM iAssign with new file id
  1178. $DB->update_record("iassign_statement", $updateentry);
  1179. }
  1180. }
  1181. }
  1182. // log event --------------------------------------------------------------------------------------
  1183. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1184. $this->return_home_course('duplicated_activity');
  1185. exit;
  1186. }
  1187. // / This method gets the content from comment and register it
  1188. function add_comment () {
  1189. global $USER, $DB;
  1190. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1191. $comment = false;
  1192. if ($submission_comment)
  1193. $comment = $this->write_comment_submission();
  1194. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1195. if (!$id_submission) {
  1196. $iassign_submission =
  1197. $DB->get_record("iassign_submission",
  1198. array(
  1199. "iassign_statementid" => $this->activity->get_activity()->id,
  1200. "userid" => $USER->id
  1201. )
  1202. );
  1203. if ($iassign_submission) {
  1204. $id_submission = $iassign_submission->id;
  1205. }
  1206. }
  1207. echo $this->search_comment_submission($id_submission);
  1208. }
  1209. /// This method gets the content from the iLM and register it
  1210. // It could be the "exercise template" (teacher) or an answer (student)
  1211. function get_answer () {
  1212. global $USER, $CFG, $DB, $OUTPUT;
  1213. $id = $this->cm->id;
  1214. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1215. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1216. if ($submission_ajax == 1) ob_start();
  1217. $comment = false;
  1218. if ($submission_comment)
  1219. $comment = $this->write_comment_submission();
  1220. // receives data of iLM using the current activity
  1221. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1222. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1223. // receives data of submission of current activity
  1224. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1225. // receives post and get
  1226. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1227. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1228. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1229. $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)
  1230. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1231. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1232. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1233. $msg = '';
  1234. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1235. $newentry = new stdClass();
  1236. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1237. $newentry->userid = $this->userid_iassign;
  1238. $newentry->timecreated = time();
  1239. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1240. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1241. $DB->insert_record("iassign_allsubmissions", $newentry);
  1242. }
  1243. // Feedback
  1244. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1245. $str_action = "view"; // repeat
  1246. if (strtolower($iassign_ilm->name) == "igeom") {
  1247. }
  1248. $title = get_string('evaluate_iassign', 'iassign');
  1249. print $OUTPUT->header();
  1250. print $OUTPUT->box_start();
  1251. // Action = { view ; repeat ; viewsubmission }
  1252. // * '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")
  1253. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1254. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1255. $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;
  1256. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1257. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1258. print '<table width=100% >';
  1259. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1260. //TODO alterar aqui???
  1261. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1262. // empty_answer_post = No solution was posted.
  1263. if ($comment)
  1264. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1265. else
  1266. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1267. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1268. } else {
  1269. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1270. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1271. // Correct answer!!
  1272. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1273. $this->write_solution = 1; //
  1274. $status = 3;
  1275. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1276. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1277. // log record
  1278. $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;
  1279. // Trigger module viewed event.
  1280. $event = \mod_iassign\event\submission_created::create(array(
  1281. 'objectid' => $this->iassign->id,
  1282. 'context' => $this->context,
  1283. 'other' => $info
  1284. ));
  1285. $event->add_record_snapshot('course', $this->course);
  1286. $event->trigger();
  1287. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1288. // Wrong answer...: get_answer_incorrect
  1289. $status = 2;
  1290. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1291. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1292. // log record
  1293. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1294. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1295. // Trigger module viewed event.
  1296. $event = \mod_iassign\event\submission_created::create(array(
  1297. 'objectid' => $this->iassign->id,
  1298. 'context' => $this->context,
  1299. 'other' => $info
  1300. ));
  1301. $event->add_record_snapshot('course', $this->course);
  1302. $event->trigger();
  1303. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1304. // Presents to the learner the result of the automatic evaluate?
  1305. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1306. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1307. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1308. print '<tr>';
  1309. // log record
  1310. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1311. // Trigger module viewed event.
  1312. $event = \mod_iassign\event\submission_created::create(array(
  1313. 'objectid' => $this->iassign->id,
  1314. 'context' => $this->context,
  1315. 'other' => $info
  1316. ));
  1317. $event->add_record_snapshot('course', $this->course);
  1318. $event->trigger();
  1319. } else { // yes!!!
  1320. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1321. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1322. print '<tr>';
  1323. print $msg;
  1324. }
  1325. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1326. $status = 1;
  1327. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1328. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1329. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1330. print '<tr>';
  1331. // log record
  1332. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1333. $event = \mod_iassign\event\submission_created::create(array(
  1334. 'objectid' => $this->iassign->id,
  1335. 'context' => $this->context,
  1336. 'other' => $info
  1337. ));
  1338. $event->add_record_snapshot('course', $this->course);
  1339. $event->trigger();
  1340. } // if ($iassign_ilm->evaluate == 1)
  1341. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1342. print '</tr></table>';
  1343. print $OUTPUT->box_end();
  1344. // add or update evaluate
  1345. if ($this->write_solution == 1) {
  1346. $timenow = time();
  1347. // new record
  1348. if (!$iassign_submission) {
  1349. $newentry = new stdClass();
  1350. $newentry->userid = $this->userid_iassign;
  1351. // $newentry->userid = $USER->id;
  1352. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1353. $newentry->timecreated = $timenow;
  1354. $newentry->timemodified = $timenow;
  1355. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1356. $newentry->grade = round($grade_student, 2);
  1357. $newentry->status = $status;
  1358. $newentry->experiment = 1;
  1359. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1360. print_error('error_insert', 'iassign');
  1361. } else {
  1362. // Trigger module viewed event.
  1363. $event = \mod_iassign\event\submission_created::create(array(
  1364. 'objectid' => $this->iassign->id,
  1365. 'context' => $this->context
  1366. ));
  1367. $event->add_record_snapshot('course', $this->course);
  1368. $event->trigger();
  1369. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1370. }
  1371. } elseif ($iassign_submission->status != 3) {
  1372. $newentry = new stdClass();
  1373. $newentry->id = $iassign_submission->id;
  1374. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1375. $newentry->userid = $iassign_submission->userid;
  1376. $newentry->timecreated = $iassign_submission->timecreated;
  1377. $newentry->timemodified = $timenow;
  1378. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1379. $newentry->grade = round($grade_student, 2);
  1380. $newentry->status = $status;
  1381. $newentry->experiment = $iassign_submission->experiment + 1;
  1382. if (!$DB->update_record("iassign_submission", $newentry)) {
  1383. print_error('error_update', 'iassign');
  1384. //D depurar...
  1385. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1386. //D $fp = fopen("teste1.txt","w");
  1387. //D fwrite($fp,$stringAux);
  1388. } else {
  1389. // Trigger module viewed event.
  1390. $event = \mod_iassign\event\submission_updated::create(array(
  1391. 'objectid' => $this->iassign->id,
  1392. 'context' => $this->context
  1393. ));
  1394. $event->add_record_snapshot('course', $this->course);
  1395. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1396. }
  1397. } else {
  1398. if ($return_get_answer == 1) {
  1399. $newentry = new stdClass();
  1400. $newentry->id = $iassign_submission->id;
  1401. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1402. $newentry->userid = $iassign_submission->userid;
  1403. $newentry->timecreated = $iassign_submission->timecreated;
  1404. $newentry->timemodified = $timenow;
  1405. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1406. $newentry->grade = round($grade_student, 2);
  1407. $newentry->status = $status;
  1408. $newentry->experiment = $iassign_submission->experiment + 1;
  1409. if (!$DB->update_record("iassign_submission", $newentry))
  1410. print_error('error_update', 'iassign');
  1411. else {
  1412. $event = \mod_iassign\event\submission_updated::create(array(
  1413. 'objectid' => $this->iassign->id,
  1414. 'context' => $this->context
  1415. ));
  1416. $event->add_record_snapshot('course', $this->course);
  1417. $event->trigger();
  1418. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1419. print $OUTPUT->box_start();
  1420. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1421. print $OUTPUT->box_end();
  1422. }
  1423. } elseif ($return_get_answer == 2) {
  1424. print $OUTPUT->box_start();
  1425. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1426. print $OUTPUT->box_end();
  1427. } else {
  1428. print $OUTPUT->box_start();
  1429. print "
  1430. <script type='text/javascript'>
  1431. //<![CDATA[
  1432. function overwrite () {
  1433. document.formEnvio.return_get_answer.value = 1;
  1434. document.formEnvio.submit();
  1435. }
  1436. function nooverwrite () {
  1437. document.formEnvio.return_get_answer.value = 2;
  1438. document.formEnvio.submit();
  1439. }
  1440. //]]>
  1441. </script>";
  1442. $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;
  1443. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1444. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1445. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1446. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1447. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1448. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1449. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1450. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1451. <input type='hidden' name='return_get_answer'/> ";
  1452. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1453. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1454. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1455. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1456. print " </form>";
  1457. print $OUTPUT->box_end();
  1458. }
  1459. }
  1460. } // if ($this->write_solution == 1)
  1461. print $OUTPUT->footer();
  1462. if ($submission_ajax == 1) {
  1463. ob_end_clean();
  1464. print 'OK';
  1465. }
  1466. die();
  1467. } // function get_answer()
  1468. /// Export in file the answer of student.
  1469. function export_file_answer () {
  1470. global $DB;
  1471. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1472. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1473. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1474. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1475. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1476. $extensions = explode(",", $iassign_ilm->extension);
  1477. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1478. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1479. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1480. header("Pragma: public");
  1481. header("Expires: 0");
  1482. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1483. header("Cache-Control: private", false);
  1484. header("Content-Type: document/unknown");
  1485. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1486. set_time_limit(0);
  1487. print($iassign_submission->answer);
  1488. exit;
  1489. } // function export_file_answer()
  1490. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1491. // @calledby $this->export_package_answer()
  1492. //TODO Precisa terminar! //TODO_HTML
  1493. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1494. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1495. <head>
  1496. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1497. $str_html .= " </head>
  1498. <body>\n";
  1499. $tam = sizeof($array_iassign_name);
  1500. for ($ii=0; $ii<$tam; $ii++) {
  1501. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1502. }
  1503. $str_html .= "
  1504. </body>\n</html>";
  1505. return $str_html;
  1506. }
  1507. /// Export an package (zip) with all answer of students
  1508. // @calledby $this->action()
  1509. function export_package_answer () {
  1510. global $DB, $CFG, $OUTPUT;
  1511. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1512. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1513. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1514. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1515. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1516. $userid = optional_param('userid', NULL, PARAM_INT);
  1517. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1518. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1519. //TODO_HTML echo "username=$username<br/>"; exit;
  1520. $current_date = date('Y_m_d_H');
  1521. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1522. // If temporary directory under Moodle data does not exists => create it
  1523. if (!is_dir($diretorio)) {
  1524. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1525. // created directory with permissions to be seen by everyone
  1526. }
  1527. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1528. if (!is_writable($diretorio)) { // send a highlighted message!
  1529. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1530. exit; // just in case
  1531. }
  1532. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1533. $zip = new zip_archive(); // create ZIP
  1534. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1535. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1536. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1537. $vet_student_filename = array();
  1538. $vet_student_content = array();
  1539. foreach ($iassign_statements as $iassign_statement) {
  1540. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1541. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1542. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1543. $extensions = explode(",", $iassign_ilm->extension);
  1544. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1545. if ($iassign_submission) {
  1546. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1547. $student_content = $iassign_submission->answer;
  1548. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1549. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1550. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1551. if ($resp) {
  1552. $vet_student_filename[] = $student_filename;
  1553. $vet_student_content[] = $student_content;
  1554. }
  1555. else { // send a highlighted message!
  1556. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1557. exit; // just in case
  1558. }
  1559. }
  1560. }
  1561. $zip->close(); // close the ZIP file
  1562. if (count($vet_student_filename)>0) {
  1563. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1564. $result_tf = $vet_result[0];
  1565. $filenameZip = $vet_result[1]->filename;
  1566. }
  1567. iassign_utils::download_file($zip_filename); // download the ZIP file
  1568. exit;
  1569. } // function export_package_answer()
  1570. /// Editing status of interactive activities
  1571. function edit_status () {
  1572. global $USER, $DB, $OUTPUT;
  1573. $newentry = new stdClass();
  1574. $newentry->id = $this->iassign_submission_current;
  1575. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1576. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1577. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1578. $newentry->status = $iassign_submission->status;
  1579. $newentry->teacher = $USER->id;
  1580. if (!$DB->update_record('iassign_submission', $newentry))
  1581. print_error('error_update', 'iassign');
  1582. else {
  1583. // Trigger module viewed event.
  1584. $event = \mod_iassign\event\submission_updated::create(array(
  1585. 'objectid' => $this->iassign->id,
  1586. 'context' => $this->context
  1587. ));
  1588. $event->add_record_snapshot('course', $this->course);
  1589. $event->trigger();
  1590. $this->action = 'viewsubmission';
  1591. $this->view_iassign_current();
  1592. } // if (!$DB->update_record('iassign_submission', $newentry))
  1593. } // function edit_status()
  1594. /// Editing grade of interactive activities
  1595. function edit_grade () {
  1596. global $USER, $DB, $OUTPUT;
  1597. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1598. if ($newgrade && $newgrade >= 0) {
  1599. $newentry = new stdClass();
  1600. $newentry->id = $this->iassign_submission_current;
  1601. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1602. $newentry->teacher = $USER->id;
  1603. if (!$DB->update_record('iassign_submission', $newentry))
  1604. print_error('error_update', 'iassign');
  1605. else {
  1606. // Trigger module viewed event.
  1607. $event = \mod_iassign\event\submission_updated::create(array(
  1608. 'objectid' => $this->iassign->id,
  1609. 'context' => $this->context
  1610. ));
  1611. $event->add_record_snapshot('course', $this->course);
  1612. $event->trigger();
  1613. }
  1614. } // if ($newgrade >= 0)
  1615. $this->action = 'viewsubmission';
  1616. $this->view_iassign_current();
  1617. }
  1618. /// Add or Edit interactive activities
  1619. // Get here when editing form and and submitted form data
  1620. // @calledby $this->action()
  1621. function add_edit_iassign () {
  1622. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1623. require_once('iassign_form.php');
  1624. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1625. $iassignid = $this->iassign->id;
  1626. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1627. $param->action = $this->action; // hidden
  1628. $param->id = $id; // hidden
  1629. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1630. $COURSE->cm = $id;
  1631. $COURSE->iassignid = $iassignid;
  1632. $COURSE->iassign_file_id = NULL;
  1633. $context = context_module::instance($this->cm->id);
  1634. $contextuser = context_user::instance($USER->id);
  1635. $component = 'mod_iassign';
  1636. $filearea = 'exercise';
  1637. if (!empty($this->iassign_current))
  1638. $COURSE->iassign_id = $this->iassign_current;
  1639. else
  1640. $COURSE->iassign_id = 0;
  1641. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1642. if ($this->action == 'add') {
  1643. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1644. $params_temp = array('iassignid' => $iassignid);
  1645. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1646. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1647. $total_of_activities = count($iassign_statement);
  1648. $param->iassignid = $iassignid;
  1649. $param->name = "";
  1650. $param->oldname = "";
  1651. $param->type_iassign = 3;
  1652. $param->proposition = "";
  1653. $author = $DB->get_record("user", array("id" => $USER->id));
  1654. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1655. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1656. $param->author = $param->author_name;
  1657. $param->author_modified = $param->author_modified_name;
  1658. $COURSE->iassign_list = array();
  1659. $param->iassign_list = array();
  1660. if ($iassign_statement) {
  1661. foreach ($iassign_statement as $iassign) {
  1662. $iassignid = $iassign->id;
  1663. $param->iassign_list[$iassignid] = 0;
  1664. $COURSE->iassign_list[$iassignid] = new stdClass();
  1665. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1666. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1667. $COURSE->iassign_list[$iassignid]->enable = 1;
  1668. } // foreach ($iassign_statement as $iassign)
  1669. }
  1670. $param->iassign_ilmid = 0;
  1671. $param->file = 0;
  1672. $param->fileold = 0;
  1673. $param->filename = "";
  1674. $param->grade = $iassign_data->grade;
  1675. $param->timemodified = time();
  1676. $param->timecreated = time();
  1677. $param->timeavailable = $iassign_data->timeavailable;
  1678. $param->timedue = $iassign_data->timedue;
  1679. $param->preventlate = $iassign_data->preventlate;
  1680. $param->test = $iassign_data->test;
  1681. $param->special_param1 = 0;
  1682. $param->visible = 1;
  1683. $param->max_experiment = $iassign_data->max_experiment;
  1684. $param->dependency = 0;
  1685. $param->automatic_evaluate = 1;
  1686. $param->show_answer = 1;
  1687. } // if ($this->action == 'add')
  1688. elseif ($this->action == 'edit') {
  1689. $COURSE->iassign_list = array();
  1690. $this_activity = $this->activity->get_activity();
  1691. if ($this_activity != null) { // first enter here: fill form data
  1692. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1693. $param->iassign_id = $iassign_statement_current->id; // oculto
  1694. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1695. $param->name = $iassign_statement_current->name;
  1696. $param->oldname = $iassign_statement_current->name;
  1697. $param->type_iassign = $iassign_statement_current->type_iassign;
  1698. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1699. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1700. $param->author_name = $iassign_statement_current->author_name; // oculto
  1701. $param->author = $iassign_statement_current->author_name;
  1702. $author = $DB->get_record("user", array('id' => $USER->id));
  1703. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1704. $param->author_modified = $param->author_modified_name;
  1705. $dependency = explode(';', $iassign_statement_current->dependency);
  1706. $param->iassign_list = array();
  1707. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1708. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1709. $array_dependency = array();
  1710. $subdependency = "";
  1711. $sub_subdependency = "";
  1712. // Dependents on this exercise
  1713. if ($iassign_statement_dependency) {
  1714. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1715. // to whom this exercise depends
  1716. foreach ($inter as $tmp)
  1717. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1718. $list_dependency = $subdependency . $sub_subdependency;
  1719. $array_dependency = explode(";", $list_dependency);
  1720. }
  1721. // Get all activities in the same iAssigment block:
  1722. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1723. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1724. $total_of_activities = count($all_others_iassign_statement) + 1;
  1725. $inter = array();
  1726. if ($all_others_iassign_statement) {
  1727. foreach ($all_others_iassign_statement as $iassign)
  1728. if (in_array($iassign->id, $dependency))
  1729. $inter[] = $iassign->id;
  1730. }
  1731. if ($all_others_iassign_statement) {
  1732. foreach ($all_others_iassign_statement as $iassign) {
  1733. $iassignid = $iassign->id;
  1734. $COURSE->iassign_list[$iassignid] = new stdClass();
  1735. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1736. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1737. if (in_array($iassignid, $dependency))
  1738. $param->iassign_list[$iassignid] = 1;
  1739. else
  1740. $param->iassign_list[$iassignid] = 0;
  1741. if (in_array($iassignid, $array_dependency))
  1742. $COURSE->iassign_list[$iassignid]->enable = 0;
  1743. else
  1744. $COURSE->iassign_list[$iassignid]->enable = 1;
  1745. } // foreach ($all_others_iassign_statement as $iassign)
  1746. } // if ($all_others_iassign_statement)
  1747. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1748. $param->fileold = 0;
  1749. $param->filesid = 0;
  1750. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1751. $param->filename = '';
  1752. $param->grade = $iassign_statement_current->grade;
  1753. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  1754. $param->timeavailable = $iassign_statement_current->timeavailable;
  1755. $param->timedue = $iassign_statement_current->timedue;
  1756. $param->preventlate = $iassign_statement_current->preventlate;
  1757. $param->test = $iassign_statement_current->test;
  1758. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  1759. $param->position = $iassign_statement_current->position; // hidden
  1760. $param->visible = $iassign_statement_current->visible;
  1761. $param->max_experiment = $iassign_statement_current->max_experiment;
  1762. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1763. $param->show_answer = $iassign_statement_current->show_answer;
  1764. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1765. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  1766. if ($files) {
  1767. foreach ($files as $file) {
  1768. if ($file->get_filename() != '.') {
  1769. $param->filename = $file->get_filename();
  1770. $param->file = $file->get_id();
  1771. $param->fileold = $file->get_id();
  1772. $COURSE->iassign_file_id = $file->get_id();
  1773. }
  1774. }
  1775. }
  1776. //TODO //MOOC2014 -- inicio
  1777. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1778. //D if ($iassign_ilm_configs) {
  1779. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1780. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1781. //D } //MOOC2014 -- fim
  1782. } // if ($this_activity != null)
  1783. } // elseif ($this->action == 'edit')
  1784. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1785. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1786. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1787. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1788. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1789. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1790. $param->position = $total_of_activities;
  1791. // Create form and associate its data
  1792. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  1793. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  1794. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  1795. if (isset($param->iassign_ilmid)) {
  1796. // array is additional atributes to 'form'
  1797. // 'special_param1 == 1' => script of iGeom : <select class="custom-select" name="special_param1" id="id_special_param1"> "Assignment with script(algorithm)? (Applicable only to iGeom iLM)"
  1798. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  1799. }
  1800. else {
  1801. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1802. }
  1803. $mform->set_data($param); // define data in the form
  1804. if ($mform->is_cancelled()) {
  1805. $this->return_home_course('iassign_cancel');
  1806. exit;
  1807. }
  1808. else { // else if ($mform->is_cancelled())
  1809. $result = $mform->get_data();
  1810. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1811. if ($result) {
  1812. $result->context = $context;
  1813. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1814. $result->grade = 0;
  1815. if ($result->type_iassign == 1) {
  1816. $result->automatic_evaluate = 0;
  1817. $result->show_answer = 0;
  1818. }
  1819. elseif ($result->automatic_evaluate == 0)
  1820. $result->show_answer = 0;
  1821. // $_POST['iassign_list']
  1822. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1823. if ($result->iassign_list) {
  1824. foreach ($result->iassign_list as $key => $value)
  1825. $result->dependency .= $key . ';';
  1826. }
  1827. else
  1828. $result->dependency = 0;
  1829. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1830. //TODO Then get it directly from the form data $_POST!
  1831. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1832. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1833. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1834. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1835. if ($this->action == 'add') {
  1836. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1837. if ($iassign_statement_name) {
  1838. $this->return_home_course('error_iassign_name');
  1839. die();
  1840. }
  1841. // Really insert the new iActivity in table '*_iassign_statement'
  1842. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1843. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1844. // Trigger module viewed event.
  1845. $event = \mod_iassign\event\iassign_created::create(array(
  1846. 'objectid' => $iassignid,
  1847. 'context' => $context
  1848. ));
  1849. $event->add_record_snapshot('course', $this->course);
  1850. $event->trigger();
  1851. $this->return_home_course('iassign_add');
  1852. } // if ($this->action == 'add')
  1853. elseif ($this->action == 'edit') {
  1854. $iassignid = $this->activity->update_iassign($result);
  1855. $this->activity->update_calendar($iassignid, $result->oldname);
  1856. // Trigger module viewed event.
  1857. $event = \mod_iassign\event\iassign_updated::create(array(
  1858. 'objectid' => $iassignid,
  1859. 'context' => $context
  1860. ));
  1861. $event->add_record_snapshot('course', $this->course);
  1862. $event->trigger();
  1863. $this->return_home_course('iassign_update');
  1864. } // elseif ($this->action == 'edit')
  1865. die();
  1866. } // if ($result)
  1867. } // else if ($mform->is_cancelled())
  1868. print $OUTPUT->header();
  1869. $mform->display();
  1870. print $OUTPUT->footer();
  1871. die();
  1872. } // function add_edit_iassign()
  1873. /// Search for dependencies
  1874. function search_dependency ($search_iassing_id, $iassign_statement) {
  1875. global $DB, $OUTPUT;
  1876. $dependency = "";
  1877. if ($iassign_statement)
  1878. foreach ($iassign_statement as $iassign) {
  1879. $inter_dependency = explode(';', $iassign->dependency);
  1880. if (in_array($search_iassing_id, $inter_dependency)) {
  1881. $dependency .= $iassign->id . ";";
  1882. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1883. } // if (in_array($search_iassing_id, $inter_dependency))
  1884. } // foreach ($iassign_statement as $iassign)
  1885. return $dependency;
  1886. }
  1887. /// Search for "sub"dependency
  1888. function search_sub_dependency ($search_iassing_id) {
  1889. global $DB, $OUTPUT;
  1890. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1891. $dependency = "";
  1892. if ($iassign_statement) {
  1893. $inter_dependency = explode(';', $iassign_statement->dependency);
  1894. foreach ($inter_dependency as $tmp) {
  1895. if ($tmp != 0)
  1896. $dependency .= $tmp . ";";
  1897. $dependency .= $this->search_sub_dependency($tmp);
  1898. } // foreach ($inter_dependency as $tmp)
  1899. } // if ($iassign_statement)
  1900. return $dependency;
  1901. }
  1902. // Warning message
  1903. static function warning_message_iassign ($strcode) {
  1904. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1905. }
  1906. /// Update grade of iAssign
  1907. // Called always any iAssign activity is created
  1908. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1909. static function update_grade_iassign ($iassignid) {
  1910. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1911. require_once($CFG->libdir . '/gradelib.php');
  1912. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1913. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1914. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1915. // Each iAssign item is associated with one item on the "gradebook"
  1916. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1917. //$sum_grade = 0;
  1918. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1919. //foreach($grade as $tmp) {
  1920. // $sum_grade += $tmp->grade;
  1921. // }
  1922. //1 Solution 1
  1923. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1924. //1 $sum_grade = 0; //1
  1925. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1926. //2 Solution 2
  1927. $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
  1928. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1929. if (key($array_sum_grade))
  1930. $sum_grade = key($array_sum_grade); //2
  1931. else
  1932. $sum_grade = 0; //2
  1933. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1934. $grades = NULL;
  1935. $params_temp = array('itemname' => $grade_iassign->name);
  1936. $params_temp['iteminstance'] = $iassignid;
  1937. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  1938. //2016 if ($sum_grade != 0) {
  1939. $params_temp['grademax'] = $sum_grade;
  1940. $params_temp['rawgrademax'] = $sum_grade;
  1941. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  1942. $params_temp['grademin'] = 0;
  1943. // @calls /lib/gradelib.php: call to grade_item->insert()
  1944. //TODO: is there any error here in Moodle version 3.0?
  1945. //TODO: Incorrect property 'grademax' found when inserting grade object
  1946. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1947. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  1948. }
  1949. /// Update grade of student
  1950. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1951. global $CFG, $DB, $OUTPUT;
  1952. require_once($CFG->libdir . '/gradelib.php');
  1953. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1954. // Review all the student submission for this iAssign activity
  1955. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1956. $total_grade = 0;
  1957. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1958. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1959. if ($iassign_submission)
  1960. $total_grade += $iassign_submission->grade;
  1961. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1962. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1963. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1964. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1965. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1966. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1967. $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
  1968. if (key($array_sum_grade))
  1969. $sum_grade = key($array_sum_grade); //2
  1970. else
  1971. $sum_grade = 0; //2
  1972. $grades['userid'] = $userid;
  1973. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1974. $params_temp = array('itemname' => $grade_iassign->name);
  1975. $params_temp['iteminstance'] = $iassignid;
  1976. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  1977. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1978. $params_temp['grademax'] = $sum_grade;
  1979. $params_temp['rawgrademax'] = $sum_grade;
  1980. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  1981. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  1982. }
  1983. /// Display caption of icons
  1984. function view_legend_icons () {
  1985. global $USER, $CFG, $DB, $OUTPUT;
  1986. $id = $this->cm->id;
  1987. if ($this->action == 'print')
  1988. print '<table border=1 width=100%><tr>';
  1989. else
  1990. print '<table width=100%><tr>';
  1991. print '<td >';
  1992. if ($this->action != 'print')
  1993. print $OUTPUT->help_icon('legend', 'iassign');
  1994. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1995. // $imagetext = '');
  1996. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1997. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1998. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1999. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  2000. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  2001. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  2002. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2003. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  2004. print '</td>' . "\n";
  2005. if ($this->action != 'print') {
  2006. $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>";
  2007. $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>";
  2008. $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>";
  2009. $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>";
  2010. $link_all_submissions_manager = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=all_submissions&iassignid=" . $this->iassign->id . "'><i class='fa fa-files-o' aria-hidden='true' style='color: red'></i>&nbsp;" . get_string('all_submissions_manager', 'iassign') . "</a>";
  2011. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  2012. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2013. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  2014. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  2015. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2016. } // if ($this->action != 'print')
  2017. print '</tr></table>' . "\n";
  2018. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2019. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  2020. $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>";
  2021. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  2022. print '</tr></table>' . "\n";
  2023. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2024. else
  2025. print '</td></tr></table>' . "\n";
  2026. } // function view_legend_icons()
  2027. /// Display activity current
  2028. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2029. function view_iassign_current () {
  2030. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2031. $id = $this->cm->id;
  2032. $iassignid = $this->iassign->id;
  2033. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2034. $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
  2035. // 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 ...
  2036. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2037. if (!$iassign_statement_activity_item) {
  2038. print $OUTPUT->header();
  2039. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2040. print $OUTPUT->footer();
  2041. exit;
  2042. }
  2043. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2044. $ilm_name = '';
  2045. if ($ilm->ilm)
  2046. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2047. // 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
  2048. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2049. // log record
  2050. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2051. //Trigger module viewed event.
  2052. $event = \mod_iassign\event\submission_viewed::create(array(
  2053. 'objectid' => $iassign->id,
  2054. 'context' => $this->context,
  2055. 'other' => $info
  2056. ));
  2057. $event->add_record_snapshot('course', $this->course);
  2058. $event->trigger();
  2059. // Search of iLM data used in the current activity
  2060. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2061. // Add actual activity to navbar:
  2062. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2063. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2064. print $OUTPUT->header();
  2065. if ($this->action == 'viewsubmission') {
  2066. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2067. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2068. else
  2069. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2070. } else {
  2071. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2072. }
  2073. if ($iassign_submission)
  2074. $this->update_comment($iassign_submission->id);
  2075. $file = $iassign_statement_activity_item->filesid;
  2076. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2077. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2078. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2079. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2080. $this->bottonPost = 0; // hide submit button
  2081. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2082. $this->view_iassign = false; // disable visualization of activity
  2083. $repeat = "";
  2084. $last_iassign = "";
  2085. $student_answer = "";
  2086. $comment = "";
  2087. // *** Teacher access (view learner's submission)
  2088. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2089. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2090. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2091. // ---> access teacher for test
  2092. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2093. $this->bottonPost = 1;
  2094. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2095. $this->activity->view_dates();
  2096. $USER->iassignEdit = $this->bottonPost;
  2097. $this->activity->show_info_iassign();
  2098. if ($iassign_submission) {
  2099. //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;
  2100. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2101. } else {
  2102. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2103. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2104. }
  2105. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2106. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2107. // Prepare tags to present the iLM
  2108. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2109. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2110. // *** (end) Teacher access (view the activity)
  2111. // *** Teacher access (view learner's submission to the activity)
  2112. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2113. // It is teacher or 'nonediting teacher' that can evaluate
  2114. // ----> area teacher evaluate
  2115. $row = optional_param('row', 0, PARAM_INT);
  2116. $column = optional_param('column', 0, PARAM_INT);
  2117. $link_next = iassign_icons::insert('right_disable');
  2118. $link_previous = iassign_icons::insert('left_disable');
  2119. $link_up = iassign_icons::insert('up_disable');
  2120. $link_down = iassign_icons::insert('down_disable');
  2121. // next_activity
  2122. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2123. $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);
  2124. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2125. }
  2126. // previous_activity
  2127. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2128. $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);
  2129. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2130. }
  2131. // previous_student
  2132. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2133. $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);
  2134. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2135. }
  2136. // next_student
  2137. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2138. $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);
  2139. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2140. }
  2141. if ($iassign_submission) {
  2142. $student_answer = $iassign_submission->answer;
  2143. }
  2144. $last_iassign = get_string('last_iassign', 'iassign');
  2145. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2146. // Messages related to due date (and user role)
  2147. $this->activity->view_dates();
  2148. print $OUTPUT->box_start();
  2149. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2150. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2151. print $OUTPUT->user_picture($user_data);
  2152. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2153. print '</td>' . "\n";
  2154. print '<td width=20% align=right>' . "\n";
  2155. print '<table width=50 cellpadding="0">';
  2156. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2157. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2158. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2159. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2160. print '</table>' . "\n";
  2161. print '</td></tr></table>' . "\n";
  2162. print $OUTPUT->box_end();
  2163. print $OUTPUT->box_start();
  2164. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2165. print '<td width=60% valign="top">' . "\n";
  2166. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2167. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2168. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2169. $resp = get_string('yes');
  2170. else
  2171. $resp = get_string('no');
  2172. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2173. if ($iassign_statement_activity_item->show_answer == 1)
  2174. $resp = get_string('yes');
  2175. else
  2176. $resp = get_string('no');
  2177. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2178. print '</td>';
  2179. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2180. print '<td width=40% valign="top" align="left">';
  2181. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2182. // check status of solution sent by the student
  2183. if ($iassign_submission) {
  2184. switch ($iassign_submission->status) {
  2185. case 3 :
  2186. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2187. break;
  2188. case 2 :
  2189. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2190. break;
  2191. case 1 :
  2192. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2193. break;
  2194. default :
  2195. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2196. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2197. } // switch ($iassign_submission->status)
  2198. }
  2199. else { // if ($iassign_submission)
  2200. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2201. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2202. }
  2203. // update_status
  2204. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2205. $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);
  2206. print " <script type='text/javascript'>
  2207. //<![CDATA[
  2208. function overwriteStatus (newstatus) {
  2209. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2210. document.formEditStatus.return_status.value=newstatus;
  2211. document.formEditStatus.submit();
  2212. }
  2213. else
  2214. document.formEditStatus.return_status.value=-1;
  2215. }
  2216. //]]>
  2217. </script>";
  2218. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2219. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2220. 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";
  2221. print " <input type='hidden' name='return_status'>\n";
  2222. print "</form>\n";
  2223. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2224. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2225. $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);
  2226. print "
  2227. <script type='text/javascript'>
  2228. //<![CDATA[
  2229. function overwriteGrade (newgrade,maxgrade) {
  2230. if (newgrade<0 || newgrade>maxgrade) {
  2231. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2232. document.formEditGrade.return_grade.value=-1;
  2233. document.formEditGrade.submit();
  2234. }
  2235. else {
  2236. document.formEditGrade.return_grade.value=newgrade;
  2237. document.formEditGrade.submit();
  2238. }
  2239. }
  2240. //]]>
  2241. </script>";
  2242. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2243. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2244. print " <input type='text' name='grade' size='6'>";
  2245. print " <input type='hidden' name='return_grade'> ";
  2246. 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";
  2247. print "</form>";
  2248. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2249. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2250. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2251. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2252. if ($teacher)
  2253. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2254. } // if ($iassign_submission->experiment > 0)
  2255. print '</td>';
  2256. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2257. print '</tr></table>';
  2258. print $OUTPUT->box_end();
  2259. $USER->iassignEdit = $this->bottonPost;
  2260. if ($iassign_submission && $allow_resubmission) {
  2261. // Put the iLM to
  2262. print $OUTPUT->box_start();
  2263. print '<p><strong>' . $last_iassign . '</strong></p>';
  2264. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2265. $enderecoPOST = "";
  2266. // Prepare tags to present the iLM
  2267. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2268. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2269. print $OUTPUT->box_end();
  2270. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2271. // ATTENTION: exception used by iGeom (exercise with "script")
  2272. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2273. if (substr($ilm_name, 0, 5)=="igeom") {
  2274. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2275. $loadTeacherActivity = true;
  2276. }
  2277. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2278. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2279. // Prepare tags to present the iLM
  2280. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2281. }
  2282. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2283. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2284. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2285. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2286. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2287. // *** (end) Teacher access (view learner's submission to the activity)
  2288. // *** Student access (view the activity)
  2289. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2290. // It could be the learner (he could send or resend the activity)
  2291. // ---> access student
  2292. $time_now = time();
  2293. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2294. // activity of type example - not submit button for submission
  2295. $this->view_iassign = true;
  2296. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2297. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2298. // activity of type test - iLM automatic evaluator - submit button for submission
  2299. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2300. $this->bottonPost = 1;
  2301. $this->view_iassign = true;
  2302. } else
  2303. $this->view_iassign = false;
  2304. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2305. // activity of type exercise (learner can send his answer, if yet open...)
  2306. $this->view_iassign = true;
  2307. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2308. $this->view_iassign = false;
  2309. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2310. $this->bottonPost = 1; // allow the submit button
  2311. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2312. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2313. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2314. if (!$iassign_submission) {
  2315. $str_iassign_submission_id = '';
  2316. $str_iassign_submission_answer = '';
  2317. }
  2318. else {
  2319. $str_iassign_submission_id = $iassign_submission->id;
  2320. $str_iassign_submission_answer = $iassign_submission->answer;
  2321. }
  2322. if ($this->action != 'repeat') {
  2323. $repeat = "<a href='view.php?action=repeat&id="
  2324. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2325. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2326. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2327. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2328. }
  2329. $this->bottonPost = 1;
  2330. $this->write_solution = 1; // can register his submission
  2331. $student_answer = $str_iassign_submission_answer;
  2332. }
  2333. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2334. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2335. $last_iassign = get_string('last_iassign', 'iassign');
  2336. if ($iassign_submission) {
  2337. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2338. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2339. $student_answer = $iassign_submission->answer;
  2340. } else {
  2341. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2342. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2343. }
  2344. }
  2345. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2346. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2347. $this->bottonPost = 1;
  2348. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2349. } else {
  2350. $last_iassign = get_string('last_iassign', 'iassign');
  2351. if ($iassign_submission) {
  2352. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2353. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2354. $student_answer = $iassign_submission->answer;
  2355. } else {
  2356. // Symbol of "redo activity"
  2357. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2358. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2359. }
  2360. }
  2361. } // elseif ($iassign_statement_activity_item->test == 1)
  2362. elseif ($iassign_statement_activity_item->test == 0)
  2363. $this->view_iassign = false;
  2364. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2365. if ($iassign_submission)
  2366. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2367. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2368. else
  2369. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2370. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2371. $this->activity->view_dates();
  2372. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2373. print $OUTPUT->box_start();
  2374. print '<table width=100% border=0 valign="top">' . "\n";
  2375. print '<tr><td width=60% valign="top">' . "\n";
  2376. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2377. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2378. $flag_dependency = true;
  2379. if ($iassign_statement_activity_item->type_iassign == 3) {
  2380. if ($iassign_statement_activity_item->dependency == 0) {
  2381. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2382. } else {
  2383. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2384. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2385. foreach ($dependencys as $dependency) {
  2386. if ($dependency) {
  2387. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2388. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2389. if ($dependencysubmissions) {
  2390. if ($dependencysubmissions->status == 3)
  2391. $icon = iassign_icons::insert('correct');
  2392. elseif ($dependencysubmissions->status == 2) {
  2393. $icon = iassign_icons::insert('incorrect');
  2394. $flag_dependency = false;
  2395. } elseif ($dependencysubmissions->status == 1) {
  2396. $icon = iassign_icons::insert('post');
  2397. $flag_dependency = false;
  2398. } elseif ($dependencysubmissions->status == 0) {
  2399. $icon = iassign_icons::insert('not_post');
  2400. $flag_dependency = false;
  2401. }
  2402. } else {
  2403. $icon = iassign_icons::insert('not_post');
  2404. $flag_dependency = false;
  2405. } // if ($dependencysubmissions)
  2406. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2407. } // if ($dependency)
  2408. } // foreach ($dependencys as $dependency)
  2409. } // if ($iassign_statement_activity_item->dependency == 0)
  2410. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2411. if ($flag_dependency == false) {
  2412. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2413. $this->view_iassign = false;
  2414. print '</tr></table>' . "\n";
  2415. }
  2416. else {
  2417. $this->view_iassign = true;
  2418. print '</td>' . "\n";
  2419. } // if ($flag_dependency == false)
  2420. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2421. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2422. // receiver=1 - message to teacher
  2423. // receiver=2 - message to student
  2424. if ($iassign_submission) {
  2425. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2426. if ($verify_message)
  2427. $comment = iassign_icons::insert('comment_unread');
  2428. }
  2429. print '<td width=40% valign="top" align="left">';
  2430. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2431. if ($iassign_statement_activity_item->show_answer == 1) {
  2432. // check status of solution sent by the student
  2433. if ($iassign_submission) {
  2434. switch ($iassign_submission->status) {
  2435. case 3 :
  2436. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2437. break;
  2438. case 2 :
  2439. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2440. break;
  2441. case 1 :
  2442. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2443. break;
  2444. default :
  2445. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2446. $repeat = "";
  2447. $last_iassign = "";
  2448. } // switch ($iassign_submission->status)
  2449. } else {
  2450. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2451. $repeat = "";
  2452. $last_iassign = "";
  2453. }
  2454. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2455. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2456. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2457. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2458. if ($iassign_statement_activity_item->max_experiment == 0)
  2459. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2460. else {
  2461. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2462. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2463. $repeat = "";
  2464. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2465. $this->bottonPost = 0;
  2466. $this->write_solution = 0;
  2467. }
  2468. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2469. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2470. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2471. if ($teacher)
  2472. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2473. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2474. } // if ($iassign_statement_activity_item->show_answer==1)
  2475. else {
  2476. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2477. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2478. $repeat = "";
  2479. $last_iassign = "";
  2480. } elseif ($iassign_submission->status == 1) {
  2481. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2482. }
  2483. }
  2484. print '</td>';
  2485. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2486. print '</tr></table>' . "\n";
  2487. // Presents the iLM
  2488. print '<table width=100% border=0 valign="top">' . "\n";
  2489. print '<td width=80% align="left">';
  2490. 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\".
  2491. print '<td width=20% align="rigth">';
  2492. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2493. print $repeat; // symbol of "redo activity"
  2494. print '</td></tr></table>' . "\n";
  2495. //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)'
  2496. $output = '';
  2497. if (!$iassign_ilm) {
  2498. $iassign_ilm = new stdClass();
  2499. $iassign_ilm->file_jar = "";
  2500. }
  2501. $output .= $OUTPUT->box_start();
  2502. $USER->iassignEdit = $this->bottonPost;
  2503. // ---
  2504. // Presents the iLM
  2505. // Prepare tags to present the iLM
  2506. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2507. $student_answer = ""; //?
  2508. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2509. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2510. $student_answer = "";
  2511. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2512. } else {
  2513. // When student is redoing his activity
  2514. // ATTENTION: exception used by iGeom (exercise with "script")
  2515. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2516. if (substr($ilm_name, 0, 5)=="igeom") {
  2517. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2518. $loadTeacherActivity = true;
  2519. }
  2520. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2521. }
  2522. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2523. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2524. //1 $history_comment = '';
  2525. //1 if ($iassign_submission) {
  2526. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2527. //1 }
  2528. //1 if (!empty($history_comment)) {
  2529. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2530. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2531. //1 $output .= $history_comment;
  2532. //1 $output .= "</table>\n";
  2533. //1 }
  2534. //1 $output .= "</form></center>\n";
  2535. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2536. //1 }
  2537. $output .= $OUTPUT->box_end();
  2538. print $output;
  2539. } // if ($this->view_iassign)
  2540. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2541. } // if ($this->view_iassign)
  2542. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2543. else
  2544. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2545. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2546. print '<table width=100% border=0 valign="top">' . "\n";
  2547. print '<tr><td width=60% valign="top">' . "\n";
  2548. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2549. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2550. print '</tr></table>' . "\n";
  2551. $student_answer = "";
  2552. $enderecoPOST = "";
  2553. // Prepare tags to present the iLM
  2554. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2555. print $output;
  2556. }
  2557. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2558. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2559. 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
  2560. // Put a block with area to sent/answer comments
  2561. $output = '';
  2562. $history_comment = '';
  2563. $row = optional_param('row', 0, PARAM_INT);
  2564. $column = optional_param('column', 0, PARAM_INT);
  2565. if ($iassign_submission) {
  2566. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2567. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2568. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2569. }
  2570. else {
  2571. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2572. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2573. }
  2574. $output .= $OUTPUT->box_start();
  2575. //if (!empty($history_comment)) {
  2576. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2577. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2578. $output .= "</table>";
  2579. print " <script type='text/javascript'>
  2580. //<![CDATA[
  2581. function submit_comment(url) {
  2582. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2583. var formData = new FormData();
  2584. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2585. var request = new XMLHttpRequest();
  2586. request.open('POST', url);
  2587. document.getElementById('comments_history').innerHTML = '';
  2588. request.onload = function (e) {
  2589. if (request.readyState === 4) {
  2590. if (request.status === 200) {
  2591. document.getElementById('comments_history').innerHTML = request.responseText;
  2592. document.getElementById('check-message-success').style.visibility = 'visible';
  2593. setTimeout(function(){
  2594. document.getElementById('check-message-success').style.visibility = 'hidden';
  2595. }, 3000);
  2596. }
  2597. }
  2598. };
  2599. document.formEnvioComment.submission_comment.value = '';
  2600. request.send(formData);
  2601. }
  2602. //]]>
  2603. </script>";
  2604. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2605. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2606. $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
  2607. $output .= "</form> </center>\n";
  2608. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2609. // }
  2610. $output .= $OUTPUT->box_end();
  2611. print $output;
  2612. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2613. // final block 'studant'
  2614. print $OUTPUT->footer();
  2615. die();
  2616. } // function view_iassign_current()
  2617. /// Export the data from performance report into CSV file format
  2618. function export_csv () {
  2619. global $USER, $CFG, $DB, $OUTPUT;
  2620. $str = "";
  2621. $fields = "student_id, student_name";
  2622. // Finding all iassign activities for the iassign:
  2623. $id = $this->cm->id;
  2624. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2625. $c = 1;
  2626. foreach ($iassign_list as $iassign) {
  2627. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2628. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2629. $c ++;
  2630. }
  2631. // Finding enrolled students:
  2632. $params_temp = array('shortname' => 'student');
  2633. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2634. $context = context_course::instance($this->course->id);
  2635. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2636. $students = $DB->get_records_sql(
  2637. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2638. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2639. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2640. foreach ($students as $student) {
  2641. $str .= $student->userid . ',';
  2642. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2643. foreach ($iassign_list as $iassign) {
  2644. $str .= ',' . $iassign->id . ',';
  2645. $str .= '"' . $iassign->name . '",';
  2646. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2647. if ($student_submissions) {
  2648. $str .= $student_submissions->experiment . ',';
  2649. $str .= $student_submissions->grade . ',';
  2650. switch ($student_submissions->status) {
  2651. case 3:
  2652. $str .= '"correct",';
  2653. break;
  2654. case 2:
  2655. $str .= '"incorrect",';
  2656. break;
  2657. case 1:
  2658. $str .= '"post",';
  2659. break;
  2660. case 0:
  2661. $str .= '"not_post",';
  2662. break;
  2663. }
  2664. }
  2665. else {
  2666. $str .= ',,"not_post",';
  2667. }
  2668. $str .= $iassign->iassign_ilmid . ',';
  2669. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2670. $str .= '"' . $ilm_activity->name . '"';
  2671. }
  2672. $str .= "\n";
  2673. }
  2674. $str = $fields . "\n" . $str;
  2675. header("Content-type: text/csv");
  2676. header("Content-disposition: attachment; filename=report.csv");
  2677. header("Pragma: no-cache");
  2678. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2679. header('Content-Length: ' . strlen($str));
  2680. header('Connection: close');
  2681. print $str;
  2682. flush();
  2683. } // function export_csv()
  2684. /// Display report of performance
  2685. function report () {
  2686. global $USER, $CFG, $DB, $OUTPUT;
  2687. $id = $this->cm->id;
  2688. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2689. if ($this->action != 'print') {
  2690. $title = get_string('report', 'iassign');
  2691. print $OUTPUT->header();
  2692. } // if ($this->action != 'print')
  2693. print $OUTPUT->box_start();
  2694. $this->view_legend_icons();
  2695. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2696. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2697. print $OUTPUT->box_end();
  2698. if ($this->action == 'print')
  2699. print '<table border=1 width="100%">' . "\n";
  2700. else
  2701. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped" width="100%">' . "\n";
  2702. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2703. // $num = array();
  2704. $i = 1;
  2705. $num = array();
  2706. $stylebutton = "background: none; -webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75); min-width: 4.5rem;";
  2707. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2708. $test_exercise = "";
  2709. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2710. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2711. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2712. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2713. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2714. $num[$i] = new stdClass();
  2715. $num[$i]->name = $iassign->name;
  2716. $num[$i]->id = $i;
  2717. $num[$i]->iassignid = $iassign->id;
  2718. print ' <tr >' . "\n";
  2719. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2720. print "<td class=\"cell c0 actvity\">";
  2721. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2722. print ' </tr>' . "\n";
  2723. $i++;
  2724. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2725. } // foreach ($iassign_list as $iassign)
  2726. $num_exerc = $i; // total of exercises
  2727. print "</table>";
  2728. print "<p></p>";
  2729. if ($this->action == 'print')
  2730. print '<table border=1 width="100%">' . "\n";
  2731. else // ./theme/boost/style/moodle.css: .generaltable
  2732. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2733. $context = context_course::instance($this->course->id);
  2734. if ($num_exerc > 1) {
  2735. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2736. $params_temp = array('shortname' => 'student');
  2737. $role = $DB->get_record_sql(
  2738. "SELECT s.id, s.shortname FROM {role} s " .
  2739. " WHERE s.shortname = :shortname", $params_temp);
  2740. // $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");
  2741. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2742. $students = $DB->get_records_sql(
  2743. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2744. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2745. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2746. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2747. $width = 90/$num_exerc;
  2748. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2749. $sum_iassign_correct[$j] = 0;
  2750. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2751. }
  2752. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2753. $sum_iassign = $j - 1;
  2754. print '</tr>' . "\n";
  2755. $total = 0;
  2756. $sum_student = 0;
  2757. $comment = iassign_icons::insert('comment_read');
  2758. $sum_comment = 0;
  2759. $sum_correct_iassign = array();
  2760. $sum_correct_student = array();
  2761. $USER->matrix_iassign = array();
  2762. if ($students) {
  2763. $w = 0;
  2764. foreach ($students as $tmp) { // count students
  2765. $users_array[$w] = $tmp;
  2766. $w++;
  2767. }
  2768. for ($x=0; $x<$w; $x++) { // for all students
  2769. print '<tr>' . "\n";
  2770. $sum_student ++;
  2771. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2772. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2773. $total_student = 0;
  2774. $tentativas = 0;
  2775. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2776. $sum_comment = $sum_verify_message = 0;
  2777. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2778. if ($student_submissions) {
  2779. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2780. $tentativas = $student_submissions->experiment;
  2781. // Get student comments
  2782. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2783. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  2784. $student_submissions_comment = $DB->get_record_sql(
  2785. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2786. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  2787. if ($student_submissions_comment) // student has comment
  2788. foreach ($student_submissions_comment as $tmp)
  2789. $sum_comment = $tmp;
  2790. // informations to previous activities
  2791. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2792. else $iassign_previous = $num[$j - 1]->iassignid;
  2793. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2794. else $user_previous = $users_array[$x - 1]->userid;
  2795. // next
  2796. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2797. else $iassign_next = "-1";
  2798. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2799. else $user_next = "-1";
  2800. $position = "&row= $x&column=$j";
  2801. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2802. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2803. $url .= $position;
  2804. // receiver=1 - message to teacher
  2805. // receiver=2 - message to student
  2806. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2807. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2808. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2809. $verify_message = $DB->get_record_sql(
  2810. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2811. "WHERE iassign_submissionid = :iassign_submissionid " .
  2812. " AND return_status= :return_status " .
  2813. " AND receiver= :receiver", $params_temp);
  2814. if ($verify_message)
  2815. foreach ($verify_message as $tmp)
  2816. $sum_verify_message = $tmp;
  2817. if ($sum_verify_message > 0)
  2818. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2819. else
  2820. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2821. if ($student_submissions->status == 3) {
  2822. $sum_iassign_correct[$j] ++;
  2823. $total_student ++;
  2824. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2825. }
  2826. elseif ($student_submissions->status == 2) {
  2827. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  2828. }
  2829. elseif ($student_submissions->status == 1) {
  2830. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2831. }
  2832. elseif ($student_submissions->status == 0) {
  2833. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2834. }
  2835. if ($this->action != 'print') {
  2836. if ($tentativas > 0)
  2837. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2838. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2839. . $feedback
  2840. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2841. . $tentativas
  2842. . '</span> </button>'
  2843. . '</a>' . "\n";
  2844. else
  2845. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2846. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2847. . $feedback
  2848. .'</button>'
  2849. . '</a>' . "\n";
  2850. if ($sum_comment > 0 && $sum_verify_message > 0)
  2851. print '<a href="' . $url . '"> '
  2852. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2853. . $comment
  2854. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2855. . $sum_verify_message . '/' . $sum_comment
  2856. . '</span> </button>'
  2857. . '</a>';
  2858. else if ($sum_comment > 0)
  2859. print '<a href="' . $url . '"> '
  2860. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  2861. . $comment
  2862. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2863. . $sum_comment
  2864. . '</span> </button>'
  2865. . '</a>';
  2866. print '</td>' . "\n";
  2867. }
  2868. if ($this->action == 'print')
  2869. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2870. } // if ($student_submissions)
  2871. else { // if ($student_submissions)
  2872. // Student does not have any submission
  2873. // informations to browse previous activities
  2874. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  2875. else $iassign_previous = $num[$j - 1]->iassignid;
  2876. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2877. else $user_previous = $users_array[$x - 1]->userid;
  2878. // next
  2879. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2880. else $iassign_next = "-1";
  2881. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2882. else $user_next = "-1";
  2883. $position = "&row= $x&column=$j";
  2884. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2885. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2886. $url .= $position;
  2887. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2888. if ($this->action == 'print')
  2889. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2890. else {
  2891. print '<td style="text-align: center;"> <a href="' . $url . '">'
  2892. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2893. . $feedback
  2894. .'</button>'
  2895. . '</a>' . "\n";
  2896. // print '<td> &nbsp;</td>';
  2897. if ($sum_comment > 0)
  2898. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  2899. // else print '<td> &nbsp;</td>';
  2900. print '</td>';
  2901. }
  2902. } // else if ($student_submissions)
  2903. $USER->matrix_iassign[$x][$j] = new stdClass();
  2904. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2905. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2906. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2907. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2908. if ($student_submissions)
  2909. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2910. else
  2911. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2912. //print '</td>' . "\n";
  2913. } // for ($j=1; $j<$num_exerc; $j++)
  2914. $total = $total + $total_student;
  2915. $porcentagem = ($total_student / ($j - 1)) * 100;
  2916. if ($tentativas != 0 && $tentativas != null) {
  2917. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2918. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2919. }
  2920. else {
  2921. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2922. }
  2923. print '</tr>' . "\n";
  2924. $sum_correct_student[$sum_student] = new stdClass();
  2925. $sum_correct_student[$sum_student]->name = $name;
  2926. $sum_correct_student[$sum_student]->sum = $total_student;
  2927. } // for ($x = 0; $x < $w; $x ++)
  2928. for ($i = 1; $i < $j; $i ++) {
  2929. if (is_null($sum_iassign_correct[$i]))
  2930. $sum_iassign_correct[$i] = 0;
  2931. $sum_correct_iassign[$i] = new stdClass();
  2932. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2933. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2934. }
  2935. // print '</tr></table>' . "\n";
  2936. }
  2937. } // if ($i>1)
  2938. else {
  2939. print_string('no_activity', 'iassign');
  2940. }
  2941. print "</table>\n";
  2942. if ($this->action != 'print')
  2943. print $OUTPUT->footer();
  2944. die();
  2945. } // function report()
  2946. /// Display graphics of performance
  2947. function stats () {
  2948. global $USER, $CFG, $DB, $OUTPUT;
  2949. $id = $this->cm->id;
  2950. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2951. if ($this->action != 'printstats')
  2952. $title = get_string('graphic', 'iassign');
  2953. $num = array();
  2954. $sum_correct_iassign = array();
  2955. $sum_correct_student = array();
  2956. $sum_student = 0;
  2957. $i = 1;
  2958. foreach ($iassign_list as $iassign) {
  2959. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2960. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2961. $sum_iassign_correct[$i] = 0;
  2962. $num[$i] = new stdClass();
  2963. $num[$i]->name = $iassign->name;
  2964. $num[$i]->id = $i;
  2965. $num[$i]->iassignid = $iassign->id;
  2966. $i ++;
  2967. } // if ($iassign->type_iassign == 3)
  2968. } // foreach ($iassign_list as $iassign)
  2969. $sum_iassign = $i - 1;
  2970. $context = context_course::instance($this->course->id);
  2971. if ($i > 1) {
  2972. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2973. $params_temp = array('shortname' => 'student');
  2974. $role = $DB->get_record_sql(
  2975. "SELECT s.id, s.shortname FROM {role} s " .
  2976. " WHERE s.shortname = :shortname", $params_temp);
  2977. // $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");
  2978. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2979. $students = $DB->get_records_sql(
  2980. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2981. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2982. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2983. $total = 0;
  2984. $sum_student = 0;
  2985. $j = 0;
  2986. $sum_correct_iassign = array();
  2987. $sum_correct_student = array();
  2988. $sum_experiment = array();
  2989. if ($students) {
  2990. foreach ($students as $users) {
  2991. $sum_student ++;
  2992. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2993. // rows
  2994. $total_student = 0;
  2995. for ($j = 1; $j < $i; $j ++) {
  2996. $total_experiment = 0;
  2997. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2998. if ($student_submissions) {
  2999. if ($student_submissions->status == 3) {
  3000. $sum_iassign_correct[$j] ++;
  3001. $total_student ++;
  3002. } // if ($student_submissions->status == 3)
  3003. $total_experiment += $student_submissions->experiment;
  3004. }
  3005. $sum_experiment[$j] = $total_experiment;
  3006. } // for ($j=1; $j<$i; $j++)
  3007. $total = $total + $total_student;
  3008. $sum_correct_student[$sum_student] = new stdClass();
  3009. $sum_correct_student[$sum_student]->name = $name;
  3010. $sum_correct_student[$sum_student]->sum = $total_student;
  3011. } // foreach ($students as $users)
  3012. }
  3013. for ($i = 1; $i < $j; $i ++) {
  3014. if (is_null($sum_iassign_correct[$i]))
  3015. $sum_iassign_correct[$i] = 0;
  3016. $sum_correct_iassign[$i] = new stdClass();
  3017. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3018. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3019. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3020. } // for ($i = 1; $i < $j; $i++)
  3021. } // if ($i > 1)
  3022. if ($this->action != 'printstats') {
  3023. $title = get_string('graphic', 'iassign');
  3024. print $OUTPUT->header();
  3025. $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>";
  3026. $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>";
  3027. print '<table width=100%><tr>';
  3028. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3029. print '<td width=15% align="right">' . $link_report . '</td>';
  3030. print '</td></tr></table>' . "\n";
  3031. print "<br><br>";
  3032. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3033. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3034. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3035. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3036. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3037. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3038. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3039. print '</tr>' . "\n";
  3040. $sum_correct = 0;
  3041. if ($sum_correct_iassign) {
  3042. foreach ($sum_correct_iassign as $iassign) {
  3043. if (is_null($iassign->experiment))
  3044. $iassign->experiment = 0;
  3045. $bar = "";
  3046. $sum = $iassign->sum;
  3047. $percent = ($sum / $sum_student) * 100;
  3048. $text = number_format($percent, 1) . '%';
  3049. $sum_correct += $sum;
  3050. if ($sum > 0) {
  3051. for ($i = 1; $i < $percent * 2; $i ++)
  3052. $bar .= iassign_icons::insert('hbar_blue');
  3053. $bar .= iassign_icons::insert('hbar_blue_r');
  3054. } // if ($sum > 0)
  3055. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3056. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3057. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3058. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3059. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3060. print '</tr>' . "\n";
  3061. } // foreach ($sum_correct_iassign as $iassign)
  3062. }
  3063. print "</table>";
  3064. print "<br><br>";
  3065. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3066. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3067. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3068. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3069. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3070. print '</tr>' . "\n";
  3071. $sum_correct = 0;
  3072. foreach ($sum_correct_student as $student) {
  3073. $bar = "";
  3074. $sum = $student->sum;
  3075. $percent = ($sum / $sum_iassign) * 100;
  3076. $text = number_format($percent, 1) . '%';
  3077. $sum_correct += $sum;
  3078. if ($sum > 0) {
  3079. for ($i = 1; $i < $percent * 2; $i ++)
  3080. $bar .= iassign_icons::insert('hbar_blue');
  3081. $bar .= iassign_icons::insert('hbar_blue_r');
  3082. } // if ($sum > 0)
  3083. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3084. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3085. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3086. print '</tr>' . "\n";
  3087. } // foreach ($sum_correct_student as $student)
  3088. print "</table>\n";
  3089. print "<br><br>\n";
  3090. $var = 0;
  3091. $cv = 0;
  3092. $dv = 0;
  3093. $avg = 0;
  3094. if ($sum_correct_student) {
  3095. $avg = $sum_correct / $sum_student;
  3096. if ($avg > 0) {
  3097. foreach ($sum_correct_student as $student)
  3098. $var += pow($student->sum - $avg, 2);
  3099. $var = $var / $sum_student;
  3100. $dv = sqrt($var);
  3101. $cv = ($dv / $avg) * 100;
  3102. }
  3103. }
  3104. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3105. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3106. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3107. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3108. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3109. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3110. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3111. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3112. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3113. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3114. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3115. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3116. print "</table>\n";
  3117. print $OUTPUT->footer();
  3118. } else {
  3119. print "<STYLE TYPE='text/css'>
  3120. <!--
  3121. .boldtable {
  3122. font-family:sans-serif;
  3123. font-size:10pt;
  3124. }
  3125. -->
  3126. </STYLE>\n";
  3127. print '<table border=1 width=100%>' . "\n";
  3128. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3129. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3130. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3131. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3132. print '</tr>' . "\n";
  3133. $sum_correct = 0;
  3134. foreach ($sum_correct_iassign as $iassign) {
  3135. $bar = "";
  3136. $sum = $iassign->sum;
  3137. $percent = ($sum / $sum_student) * 100;
  3138. $text = number_format($percent, 1) . '%';
  3139. $sum_correct += $sum;
  3140. if ($sum > 0) {
  3141. for ($i = 1; $i < $percent * 2; $i ++)
  3142. $bar .= iassign_icons::insert('hbar_blue');
  3143. $bar .= iassign_icons::insert('hbar_blue_r');
  3144. } // if ($sum > 0)
  3145. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3146. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3147. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3148. print '</tr>' . "\n";
  3149. } // foreach ($sum_correct_iassign as $iassign)
  3150. print "</table>";
  3151. print "<br><br>";
  3152. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3153. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3154. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3155. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3156. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3157. print '</tr>' . "\n";
  3158. $sum_correct = 0;
  3159. foreach ($sum_correct_student as $student) {
  3160. $bar = "";
  3161. $sum = $student->sum;
  3162. $percent = ($sum / $sum_iassign) * 100;
  3163. $text = number_format($percent, 1) . '%';
  3164. $sum_correct += $sum;
  3165. if ($sum > 0) {
  3166. for ($i = 1; $i < $percent * 2; $i ++)
  3167. $bar .= iassign_icons::insert('hbar_blue');
  3168. $bar .= iassign_icons::insert('hbar_blue_r');
  3169. } // if ($sum > 0)
  3170. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3171. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3172. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3173. print '</tr>' . "\n";
  3174. } // foreach ($sum_correct_student as $student)
  3175. print "</table>\n";
  3176. print "<br/><br/>\n";
  3177. $var = 0;
  3178. $cv = 0;
  3179. $dv = 0;
  3180. $avg = 0;
  3181. if ($sum_correct_student) {
  3182. $avg = $sum_correct / $sum_student;
  3183. if ($avg > 0) {
  3184. foreach ($sum_correct_student as $student)
  3185. $var += pow($student->sum - $avg, 2);
  3186. $var = $var / $sum_student;
  3187. $dv = sqrt($var);
  3188. $cv = ($dv / $avg) * 100;
  3189. }
  3190. }
  3191. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3192. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3193. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3194. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3195. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3196. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3197. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3198. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3199. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3200. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3201. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3202. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3203. print "</table>\n";
  3204. } // if ($this->action != 'printstats')
  3205. die();
  3206. }
  3207. /// Display graphics of performance for students
  3208. function stats_students () {
  3209. global $USER, $CFG, $DB, $OUTPUT;
  3210. $id = $this->cm->id;
  3211. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3212. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3213. $title = get_string('results', 'iassign');
  3214. $sum_correct = 0;
  3215. $sum_incorrect = 0;
  3216. $sum_post = 0;
  3217. $sum_nopost = 0;
  3218. $sum_iassign = count($iassign_statement_list);
  3219. $bar_nopost = "";
  3220. $bar_correct = "";
  3221. $bar_incorrect = "";
  3222. $bar_post = "";
  3223. $text_nopost = "";
  3224. $text_correct = "";
  3225. $text_incorrect = "";
  3226. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3227. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3228. if ($iassign_submission) {
  3229. if ($iassign_submission->status == 3)
  3230. $sum_correct ++;
  3231. elseif ($iassign_submission->status == 2)
  3232. $sum_incorrect ++;
  3233. elseif ($iassign_submission->status == 1)
  3234. $sum_post ++;
  3235. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3236. $sum_nopost ++;
  3237. } // if ($iassign_submission)
  3238. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3239. if ($sum_iassign > 0) {
  3240. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3241. $text_correct = number_format($percent_correct, 1) . '%';
  3242. }
  3243. if ($sum_correct > 0) {
  3244. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3245. $bar_correct .= iassign_icons::insert('hbar_green');
  3246. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3247. } // if ($sum_correct > 0)
  3248. if ($sum_iassign > 0) {
  3249. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3250. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3251. }
  3252. if ($sum_incorrect > 0) {
  3253. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3254. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3255. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3256. } // if ($sum_incorrect > 0)
  3257. if ($sum_iassign > 0) {
  3258. $percent_post = ($sum_post / $sum_iassign) * 100;
  3259. $text_post = number_format($percent_post, 1) . '%';
  3260. }
  3261. if ($sum_post > 0) {
  3262. for ($i = 1; $i < $percent_post * 2; $i ++)
  3263. $bar_post .= iassign_icons::insert('hbar_blue');
  3264. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3265. } // if ($sum_post > 0)
  3266. if ($sum_iassign > 0) {
  3267. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3268. $text_nopost = number_format($percent_nopost, 1) . '%';
  3269. }
  3270. if ($sum_nopost > 0) {
  3271. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3272. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3273. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3274. } // if ($sum_nopost > 0)
  3275. print $OUTPUT->header();
  3276. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3277. print '<table width=100%><tr>';
  3278. print '<td align="right">' . $link_return . '</td>' . "\n";
  3279. print '</td></tr></table>' . "\n";
  3280. print "<br/><br/>\n";
  3281. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3282. print '<tr><th colspan=3 class="header c1">' . "\n";
  3283. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3284. // $imagetext = '');
  3285. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3286. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3287. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3288. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3289. print '</tr>' . "\n";
  3290. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3291. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3292. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3293. print '</tr>' . "\n";
  3294. if ($sum_post) {
  3295. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3296. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3297. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3298. print '</tr>' . "\n";
  3299. } // if ($sum_post)
  3300. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3301. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3302. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3303. print '</tr>' . "\n";
  3304. print "</table>";
  3305. print "<br><br>";
  3306. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3307. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3308. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3309. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3310. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3311. $sum_grade = 0;
  3312. $sum_grade_student = 0;
  3313. $avg = 0;
  3314. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3315. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3316. if (!$iassign_submission) {
  3317. $iassign_submission = new stdClass();
  3318. $iassign_submission->grade = 0;
  3319. }
  3320. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3321. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3322. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3323. print '</tr>' . "\n";
  3324. $sum_grade += $iassign_statement_activity_item->grade;
  3325. $sum_grade_student += $iassign_submission->grade;
  3326. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3327. if ($sum_grade > 0)
  3328. $avg = $sum_grade_student / $sum_grade * 100;
  3329. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3330. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3331. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3332. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3333. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3334. print "</table>";
  3335. print $OUTPUT->footer();
  3336. die();
  3337. } // function stats_students()
  3338. /// Display page of iAssign's activity
  3339. function view_iassigns () {
  3340. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3341. $id = $this->cm->id;
  3342. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3343. $notice = optional_param('notice', '', PARAM_TEXT);
  3344. if (strpos($notice, 'error'))
  3345. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3346. else if ($notice != '')
  3347. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3348. print $OUTPUT->box_start();
  3349. print '<table width=100% border=0><tr>' . "\n";
  3350. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3351. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3352. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3353. $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>";
  3354. $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>";
  3355. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3356. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3357. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3358. // Has capability to see "report": teacher or up
  3359. print '<td width=10% align="left">' . "\n";
  3360. print $link_help;
  3361. print '</td>' . "\n";
  3362. print '<td width=10% align="left">' . "\n";
  3363. print $link_report;
  3364. print '</td>' . "\n";
  3365. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3366. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3367. print '<td width=15% align="left">' . "\n";
  3368. print $link_add;
  3369. print "</td>\n";
  3370. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3371. //print '</tr></table>' . "\n";
  3372. print '<div style="float: right;">';
  3373. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3374. if ($iassign_list) {
  3375. print '<td align="right">' . "\n";
  3376. // $USER->iassignEdit == 0 view 'Turn editing off'
  3377. // $USER->iassignEdit == 1 view 'Turn editing on'
  3378. if (!isset($USER->iassignEdit))
  3379. $USER->iassignEdit = 0;
  3380. if ($USER->iassignEdit == 0) {
  3381. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3382. $botton = 1;
  3383. } // if ($USER->iassignEdit == 0)
  3384. elseif ($USER->iassignEdit == 1) {
  3385. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3386. $botton = 0;
  3387. } // elseif ($USER->iassignEdit == 1)
  3388. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3389. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3390. print " <input type=submit value='$bottonEdit_message'/>\n";
  3391. print "</form>\n";
  3392. print "</td>\n";
  3393. } // if ($iassign_list)
  3394. }
  3395. print '</tr></table>' . "\n";
  3396. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3397. // $this->view_legend_icons();
  3398. print $OUTPUT->box_end();
  3399. $iassign_array_exercise = array();
  3400. $i_exercise = 0;
  3401. $iassign_array_test = array();
  3402. $i_test = 0;
  3403. $iassign_array_example = array();
  3404. $i_example = 0;
  3405. $iassign_array_general = array();
  3406. $i_general = 0;
  3407. if ($iassign_list) {
  3408. if ($this->iassign->activity_group == 0) {
  3409. foreach ($iassign_list as $iassign) {
  3410. $iassign_array_general[$i_general] = $iassign;
  3411. $i_general ++;
  3412. }
  3413. } // if ($this->iassign->activity_group == 0)
  3414. else {
  3415. foreach ($iassign_list as $iassign) {
  3416. if ($iassign->type_iassign == 3) {
  3417. $iassign_array_exercise[$i_exercise] = $iassign;
  3418. $i_exercise ++;
  3419. } // if ($iassign->type_iassign == 3)
  3420. if ($iassign->type_iassign == 2) {
  3421. $iassign_array_test[$i_test] = $iassign;
  3422. $i_test ++;
  3423. } // if ($iassign->type_iassign == 2)
  3424. if ($iassign->type_iassign == 1) {
  3425. $iassign_array_example[$i_example] = $iassign;
  3426. $i_example ++;
  3427. } // if ($iassign->type_iassign == 1)
  3428. }
  3429. }
  3430. if ($iassign_array_exercise) {
  3431. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3432. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3433. }
  3434. if ($iassign_array_test) {
  3435. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3436. $this->show_iassign($title, $iassign_array_test, $i_test);
  3437. }
  3438. if ($iassign_array_example) {
  3439. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3440. $this->show_iassign($title, $iassign_array_example, $i_example);
  3441. }
  3442. if ($iassign_array_general) {
  3443. $title = "";
  3444. $this->show_iassign($title, $iassign_array_general, $i_general);
  3445. }
  3446. } else { // if ($iassign_list)
  3447. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3448. }
  3449. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3450. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3451. print $OUTPUT->box_start();
  3452. print '<table width=100% border=0><tr>' . "\n";
  3453. print '<td width=10% align="left">' . "\n";
  3454. print $link_report;
  3455. print '</td>' . "\n";
  3456. print '</tr></table>' . "\n";
  3457. print $OUTPUT->box_end();
  3458. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3459. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3460. print $OUTPUT->box_start();
  3461. print '<table width=100% border=0><tr>' . "\n";
  3462. print '<td align="left">' . "\n";
  3463. print $link_add;
  3464. print '</td>' . "\n";
  3465. print '</tr></table>' . "\n";
  3466. print $OUTPUT->box_end();
  3467. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3468. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3469. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3470. $this->view_legend_icons();
  3471. } // function view_iassigns()
  3472. /// Display all iAssigns
  3473. function show_iassign ($title, $iassign_array, $i) {
  3474. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3475. $id = $this->cm->id;
  3476. print $OUTPUT->box_start();
  3477. print " <script type='text/javascript'>
  3478. //<![CDATA[
  3479. function validate_move () {
  3480. var radios = document.getElementsByName('iassign_destiny');
  3481. var formValid = false;
  3482. //alert('aqui validate_move()');
  3483. var i = 0;
  3484. while (!formValid && i < radios.length) {
  3485. if (radios[i].checked) formValid = true;
  3486. i++;
  3487. }
  3488. if (!formValid) {
  3489. document.getElementById('move_dest').classList.add('alert-danger');
  3490. }
  3491. return formValid;
  3492. }
  3493. var modal;
  3494. function load_move(id_ias) {
  3495. document.form_move_activity.iassign_current.value = id_ias;
  3496. modal.style.display = 'block';
  3497. var radios = document.getElementsByName('iassign_destiny');
  3498. var i = 0;
  3499. while (i < radios.length) {
  3500. radios[i].checked = false;
  3501. i++;
  3502. }
  3503. document.getElementById('move_dest').classList.remove('alert-danger');
  3504. }
  3505. function load_modal_elements() {
  3506. modal = document.getElementById('myModal');
  3507. var span = document.getElementById('close_modal');
  3508. span.onclick = function() {
  3509. modal.style.display = 'none';
  3510. }
  3511. window.onclick = function(event) {
  3512. if (event.target == modal) {
  3513. modal.style.display = 'none';
  3514. }
  3515. }
  3516. }
  3517. window.onload = load_modal_elements;
  3518. //]]>
  3519. </script>\n";
  3520. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3521. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3522. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3523. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3524. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3525. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3526. <input type='hidden' name='iassign_current' value='' />";
  3527. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3528. $section = $course_sections[0];
  3529. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3530. for ($k = 0; $k < count($ids_sections); $k++) {
  3531. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3532. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3533. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3534. if ($c_cm) {
  3535. if ($ccm->instance == $c_cm->instance) {
  3536. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3537. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3538. }
  3539. else {
  3540. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3541. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3542. }
  3543. }
  3544. }
  3545. $radio_buttons .= "</ul>";
  3546. }
  3547. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3548. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3549. </form>
  3550. </div></div> </div></div>\n";
  3551. print " <style>.modal {
  3552. display: none;
  3553. position: fixed;
  3554. z-index: 1;
  3555. left: 0;
  3556. top: 0;
  3557. width: 100%;
  3558. height: 100%;
  3559. overflow: scroll;
  3560. background-color: rgb(0,0,0);
  3561. background-color: rgba(0,0,0,0.4);
  3562. }
  3563. .modal-content {
  3564. background-color: #fefefe;
  3565. margin: 15% auto;
  3566. padding: 10px 10px;
  3567. border: 1px solid #888;
  3568. width: 50%;
  3569. }
  3570. #close_modal {
  3571. color: #aaa;
  3572. float: right;
  3573. font-size: 28px;
  3574. font-weight: bold;
  3575. margin-top: -15px;
  3576. margin-right: -3px;
  3577. }
  3578. #close_modal:hover,
  3579. #close_modal:focus {
  3580. color: black;
  3581. text-decoration: none;
  3582. cursor: pointer;
  3583. }
  3584. #modal_title {
  3585. min-height: 3rem;
  3586. color: initial;
  3587. background: initial;
  3588. font-size: 1.5rem;
  3589. line-height: 1.5;
  3590. padding: 15px;
  3591. border-bottom: 1px solid #e5e5e5;
  3592. }
  3593. .input_move {
  3594. width: 90%;
  3595. padding: 2px;
  3596. }
  3597. .input_move:hover {
  3598. background: #eff0ef;
  3599. }
  3600. </style>";
  3601. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3602. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3603. for ($j = 0; $j < $i; $j ++) {
  3604. $iassign_current = $iassign_array[$j]->id;
  3605. // receiver=1 - message to teacher
  3606. // receiver=2 - message to student
  3607. $sum_comment = 0;
  3608. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3609. foreach ($iassign_submissions as $iassign_submission) {
  3610. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3611. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3612. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3613. if ($verify_message)
  3614. foreach ($verify_message as $tmp)
  3615. $sum_comment += $tmp;
  3616. } // foreach ($iassign_submissions as $iassign_submission)
  3617. if ($sum_comment == 0)
  3618. $comment_unread = "";
  3619. else {
  3620. $comment_unread_message = get_string('comment_unread', 'iassign');
  3621. if ($sum_comment == 1)
  3622. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3623. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3624. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3625. }
  3626. if ($j == $i - 1)
  3627. $iassign_down = $iassign_array[$j]->id;
  3628. else
  3629. $iassign_down = $iassign_array[$j + 1]->id;
  3630. if ($j > 0)
  3631. $iassign_up = $iassign_array[$j - 1]->id;
  3632. else
  3633. $iassign_up = $iassign_array[$j]->id;
  3634. if ($iassign_array[$j]->visible == 0)
  3635. $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>";
  3636. else
  3637. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3638. $links .= $comment_unread;
  3639. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3640. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3641. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3642. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3643. if ($j==0) // first activity
  3644. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3645. else
  3646. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3647. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3648. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3649. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3650. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3651. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3652. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3653. if (count($iassign_array) > 1) {
  3654. if ($j == 0)
  3655. $links .= $link_down;
  3656. elseif ($j == $i - 1)
  3657. $links .= $link_up;
  3658. else
  3659. $links .= $link_up . $link_down;
  3660. } // if (count($iassign_array) > 1)
  3661. $links .= $link_edit . $link_delete;
  3662. if ($iassign_array[$j]->visible == 0)
  3663. $links .= $link_visible_show;
  3664. else
  3665. $links .= $link_visible_hide;
  3666. $links .= $link_duplicate_activity . $link_move_activity;
  3667. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3668. print '<p>' . $links . '</p>' . "\n";
  3669. }
  3670. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3671. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3672. print '<table width=100% ><tr>' . "\n";
  3673. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3674. print '</tr></table>' . "\n";
  3675. for ($j = 0; $j < $i; $j ++) {
  3676. $icon_status = "";
  3677. $icon_comment = "";
  3678. if ($iassign_array[$j]->visible == 1) {
  3679. $iassign_current = $iassign_array[$j]->id;
  3680. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3681. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3682. $icon_status = "";
  3683. $icon_comment = "";
  3684. if ($iassign_submission) {
  3685. // receiver=1 - message to teacher
  3686. // receiver=2 - message to student
  3687. // $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");
  3688. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3689. $verify_message = $DB->get_record_sql(
  3690. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3691. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  3692. if ($verify_message)
  3693. foreach ($verify_message as $tmp)
  3694. $sum_comment = $tmp;
  3695. if ($sum_comment > 0) {
  3696. $comment_unread_message = get_string('comment_unread', 'iassign');
  3697. if ($sum_comment == 1)
  3698. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3699. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3700. }
  3701. // $icon_comment = iassign_icons::insert('comment_unread');
  3702. if ($iassign_array[$j]->type_iassign == 3) {
  3703. if ($iassign_array[$j]->show_answer == 1) {
  3704. if ($iassign_submission->status == 3)
  3705. $icon_status = iassign_icons::insert('correct');
  3706. elseif ($iassign_submission->status == 2)
  3707. $icon_status = iassign_icons::insert('incorrect');
  3708. elseif ($iassign_submission->status == 1)
  3709. $icon_status = iassign_icons::insert('post');
  3710. elseif ($iassign_submission->status == 0)
  3711. $icon_status = iassign_icons::insert('not_post');
  3712. } // if ($iassign_array[$j]->show_answer==1)
  3713. else {
  3714. if ($iassign_submission->status == 0)
  3715. $icon_status = iassign_icons::insert('not_post');
  3716. else
  3717. $icon_status = iassign_icons::insert('post');
  3718. }
  3719. } // if ($iassign_array[$j]->type_iassign == 3)
  3720. } // if ($iassign_submission)
  3721. elseif ($iassign_array[$j]->type_iassign == 3) {
  3722. $icon_status = iassign_icons::insert('not_post');
  3723. } // if ($iassign_array[$j]->type_iassign == 3)
  3724. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3725. } // if ($iassign_array[$j]->visible == 1)
  3726. } // for ($j = 0; $j < $i; $j++)
  3727. } else if (isguestuser()) {
  3728. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3729. print '<table width=100% ><tr>' . "\n";
  3730. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3731. print '</tr></table>' . "\n";
  3732. for ($j = 0; $j < $i; $j ++) {
  3733. $icon_status = "";
  3734. $icon_comment = "";
  3735. if ($iassign_array[$j]->visible == 1) {
  3736. $iassign_current = $iassign_array[$j]->id;
  3737. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3738. print '<p>' . $links . '</p>' . "\n";
  3739. } // if ($iassign_array[$j]->visible == 1)
  3740. }
  3741. }
  3742. print $OUTPUT->box_end();
  3743. } // function show_iassign($title, $iassign_array, $i)
  3744. /// Show message of return
  3745. function return_home_course ($message) {
  3746. //D global $DB, $OUTPUT;
  3747. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3748. //D echo $OUTPUT->box_start();
  3749. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3750. //D echo '<tr><td align="left"><strong>' . "\n";
  3751. //D print_string($message, 'iassign');
  3752. //D echo '</strong></td>' . "\n";
  3753. //D echo '<td width=20% align="right">' . "\n";
  3754. //D echo $link_return;
  3755. //D echo '</td></tr></table>' . "\n";
  3756. //D echo $OUTPUT->box_end();
  3757. //D // echo $OUTPUT->footer();
  3758. redirect(new moodle_url($this->return . '&notice=' . $message));
  3759. exit;
  3760. }
  3761. /// Search comment of activity
  3762. function search_comment_submission ($iassign_submissionid) {
  3763. global $USER, $DB, $OUTPUT, $COURSE;
  3764. // $context = context_course::instance($COURSE->id);
  3765. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3766. $colorEdit2 = "#d2e5fc";
  3767. $has_capability = 0;
  3768. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3769. $text = "";
  3770. if ($comments) {
  3771. $even = 1;
  3772. foreach ($comments as $tmp) {
  3773. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3774. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3775. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3776. // $text .= $tmp->comment . "</td></tr>";
  3777. //} else {
  3778. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3779. $avatar = new user_picture($user_data);
  3780. $avatar->courseid = $COURSE->id;
  3781. $avatar->link = true;
  3782. $user_picture = $OUTPUT->render($avatar);
  3783. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3784. if ($even) {
  3785. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3786. $even = 0;
  3787. } else {
  3788. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3789. $even = 1;
  3790. }
  3791. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3792. } // foreach ($comments as $tmp)
  3793. }
  3794. return $text;
  3795. }
  3796. /// Update comment of activity
  3797. function update_comment ($iassign_submissionid) {
  3798. global $USER, $DB, $OUTPUT;
  3799. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3800. $receiver = 1; // student message to teacher
  3801. else
  3802. $receiver = 2; // teacher message to student
  3803. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3804. if ($verify_message) {
  3805. foreach ($verify_message as $message) {
  3806. if ($message->receiver == $receiver) {
  3807. $newentry = new stdClass();
  3808. $newentry->id = $message->id;
  3809. $newentry->return_status = 1;
  3810. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3811. print_error('error_update', 'iassign');
  3812. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3813. } // if ($message->receiver == $receiver)
  3814. // Trigger module viewed event.
  3815. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3816. 'objectid' => $this->iassign->id,
  3817. 'context' => $this->context
  3818. ));
  3819. $event->add_record_snapshot('course', $this->course);
  3820. $event->trigger();
  3821. } // foreach ($verify_message as $message)
  3822. }
  3823. }
  3824. /// Record comment of activity
  3825. function write_comment_submission () {
  3826. global $USER, $CFG, $DB;
  3827. $id = $this->cm->id;
  3828. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3829. $row = optional_param('row', 0, PARAM_INT);
  3830. $column = optional_param('column', 0, PARAM_INT);
  3831. $sum_comment = 0;
  3832. $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);
  3833. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3834. $str1 = trim($submission_comment);
  3835. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3836. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3837. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3838. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3839. $receiver = 1; // student message to teacher
  3840. $this->action = 'view';
  3841. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3842. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3843. } else {
  3844. $receiver = 2; // teacher message to student
  3845. $this->action = 'viewsubmission';
  3846. //D $tousers = array(); //MOOC 2016
  3847. //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
  3848. }
  3849. //MOOC 2016: foi p/ 15 linhas acima:
  3850. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3851. // verificar se existe uma submissão para o exercício e aluno informados
  3852. if (!$iassign_submission) {
  3853. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3854. }
  3855. if (!$iassign_submission) {
  3856. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3857. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3858. $this->iassign_submission_current = $id_submission;
  3859. }
  3860. else {
  3861. $id_submission = $iassign_submission->id;
  3862. } // if (!$iassign_submission)
  3863. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3864. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3865. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3866. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3867. $comments = $DB->get_record_sql(
  3868. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3869. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  3870. if ($comments)
  3871. foreach ($comments as $tmp)
  3872. $sum_comment = $tmp;
  3873. if ($sum_comment == 0) {
  3874. $newentry = new stdClass();
  3875. $newentry->iassign_submissionid = $id_submission;
  3876. $newentry->comment_authorid = $USER->id;
  3877. $newentry->timecreated = time();
  3878. $newentry->comment = $submission_comment;
  3879. $newentry->receiver = $receiver;
  3880. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3881. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3882. //T $eventdata = new stdClass();
  3883. //T $eventdata->component = 'mod_iassign'; //your component name
  3884. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3885. //T $eventdata->userfrom = $USER;
  3886. //T $eventdata->userto = $touser;
  3887. //T $eventdata->subject = "Teste de Subject";
  3888. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3889. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3890. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3891. //T $eventdata->smallmessage = "Teste de Mensagem";
  3892. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3893. //T // alteracao tulio faria
  3894. //T //message_send($eventdata);
  3895. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3896. // Trigger module viewed event.
  3897. $event = \mod_iassign\event\submission_comment_created::create(array(
  3898. 'objectid' => $this->iassign->id,
  3899. 'context' => $this->context
  3900. ));
  3901. $event->add_record_snapshot('course', $this->course);
  3902. $event->trigger();
  3903. }
  3904. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3905. // if ($this->action=='viewsubmission') {
  3906. // echo $OUTPUT->header();
  3907. // $this->return_last('confirm_add_comment', $link_return);
  3908. // die;
  3909. // }
  3910. return true;
  3911. } // function write_comment_submission()
  3912. /// Writes a new submission
  3913. // The first student answer is under 'function get_answer()'
  3914. function new_submission ($iassignid, $id_user, $receiver) {
  3915. global $USER, $DB, $OUTPUT;
  3916. $newentry = new stdClass();
  3917. $newentry->iassign_statementid = $iassignid;
  3918. $newentry->userid = $id_user;
  3919. $newentry->timecreated = time();
  3920. $newentry->timemodified = time();
  3921. $newentry->answer = 0; // student only submit message
  3922. if ($receiver == 2) // teacher message to student (write id teacher)
  3923. $newentry->teacher = $USER->id;
  3924. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3925. return_home_course('error_insert_submissions');
  3926. else {
  3927. // Trigger module view event
  3928. $event = \mod_iassign\event\submission_created::create(array(
  3929. 'objectid' => $this->iassign->id,
  3930. 'context' => $this->context
  3931. ));
  3932. $event->add_record_snapshot('course', $this->course);
  3933. $event->trigger();
  3934. }
  3935. return $newentry->id;
  3936. }
  3937. /// Return to a specific address of page
  3938. function return_last ($message, $link_return) {
  3939. global $DB, $OUTPUT;
  3940. print $OUTPUT->box_start();
  3941. print '<table width=100% border=0 valign="top">' . "\n";
  3942. print '<tr><td align="left"><strong>' . "\n";
  3943. print_string($message, 'iassign');
  3944. print '</strong></td>' . "\n";
  3945. print '<td width=20% align="right">' . "\n";
  3946. print $link_return;
  3947. print '</td></tr></table>' . "\n";
  3948. print $OUTPUT->box_end();
  3949. print $OUTPUT->footer();
  3950. die();
  3951. } // function return_last($message, $link_return)
  3952. } // class iassign
  3953. /// Class for manage activities
  3954. class activity {
  3955. var $activity;
  3956. /// Constructor of class.
  3957. // @param int $id Id of activity
  3958. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3959. //D public function activity($id) { self::__construct($id); }
  3960. function __construct ($id) {
  3961. global $DB;
  3962. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3963. if (empty($this->activity))
  3964. $this->activity = null;
  3965. }
  3966. /// Get an activity
  3967. // @return NULL
  3968. function get_activity () {
  3969. if ($this->activity != null)
  3970. return $this->activity;
  3971. else
  3972. return null;
  3973. }
  3974. /// Delete interactive activities
  3975. function delete ($return) {
  3976. global $USER, $CFG, $DB, $OUTPUT;
  3977. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3978. $output = $OUTPUT->header();
  3979. $output .= $OUTPUT->box_start();
  3980. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3981. if ($iassign_submission_currents) {
  3982. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3983. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3984. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3985. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3986. $output .= $OUTPUT->box_end();
  3987. $output .= $OUTPUT->footer();
  3988. print $output;
  3989. die();
  3990. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3991. } // if ($iassign_submission_currents)
  3992. else
  3993. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3994. $output .= '<table width=50% border=0>';
  3995. $output .= '<tr valign="top"><td>';
  3996. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3997. $output .= '</td><td>';
  3998. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3999. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4000. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4001. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4002. $output .= "</form>\n";
  4003. $output .= '</td><td>';
  4004. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4005. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4006. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4007. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4008. $output .= "</form>\n";
  4009. $output .= '</td></tr></table>' . "\n";
  4010. $output .= $OUTPUT->box_end();
  4011. $output .= $OUTPUT->footer();
  4012. print $output;
  4013. } // function delete($return)
  4014. /// Function for confirm the delete of activity
  4015. // @param String $return Url of return
  4016. // @param Object $iassign Object content an activity
  4017. function deleteyes ($return, $iassign) {
  4018. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4019. $msg = '';
  4020. if (!empty($this->activity->id)) {
  4021. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4022. if ($iassign_submission_currents) {
  4023. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4024. foreach ($iassign_submission_currents as $iassign_submission)
  4025. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4026. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4027. } // if ($iassign_submission_currents)
  4028. }
  4029. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4030. // Remove all files associated to this activity:
  4031. $fs = get_file_storage();
  4032. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4033. $this->delete_calendar($this->activity->id);
  4034. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4035. iassign::update_grade_iassign($this->activity->iassignid);
  4036. if ($delete_iassign_current) {
  4037. $iassign->return_home_course('confirm_delete_iassign');
  4038. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4039. } else {
  4040. $iassign->return_home_course('error_confirm_delete_iassign');
  4041. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4042. }
  4043. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4044. }
  4045. }
  4046. /// Changes position of activities (between those inside a group of interactive activities)
  4047. // @param $move_action = must be "up" or "down"
  4048. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4049. function move_iassign ($move_action, $target, $return) {
  4050. global $DB, $OUTPUT;
  4051. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4052. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4053. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4054. if ($move_action=="firstdown") {
  4055. $final_position_source = 2;
  4056. $final_position_target = 1;
  4057. }
  4058. else
  4059. if ($move_action=="down") {
  4060. $final_position_target = $this->activity->position;
  4061. $final_position_source = $final_position_target + 1;
  4062. }
  4063. else
  4064. if ($move_action=="up") {
  4065. $final_position_target = $this->activity->position;
  4066. $final_position_source = $final_position_target - 1;
  4067. }
  4068. else { // error:
  4069. print_error('error_update_move_iassign', 'iassign');
  4070. exit;
  4071. }
  4072. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4073. $newentry->id = $this->activity->id; // ID of the "source activity"
  4074. $newentry->position = $final_position_source;
  4075. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4076. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4077. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4078. print_error('error_update_move_iassign', 'iassign');
  4079. }
  4080. else { // first update performed successfully
  4081. $newentry->id = $iassign_target->id;
  4082. $newentry->position = $final_position_target;
  4083. if (!$DB->update_record('iassign_statement', $newentry))
  4084. print_error('error_update_move_iassign', 'iassign');
  4085. }
  4086. redirect($return);
  4087. }
  4088. /// Enable or disable the display of interactive activities
  4089. function visible_iassign ($return) {
  4090. global $DB;
  4091. $newentry = new stdClass();
  4092. $newentry->id = $this->activity->id;
  4093. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4094. if (!$DB->update_record('iassign_statement', $newentry))
  4095. print_error('error_update_visible_iassign', 'iassign');
  4096. redirect($return);
  4097. }
  4098. /// Add news interactive activities (register in table 'iassign_statement')
  4099. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4100. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4101. function new_iassign ($param) {
  4102. global $DB;
  4103. $newentry = new stdClass();
  4104. $newentry->iassignid = $param->iassignid;
  4105. $newentry->name = $param->name;
  4106. $newentry->type_iassign = $param->type_iassign;
  4107. $newentry->store_all_submissions = $param->store_all_submissions;
  4108. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4109. $proposition = $param->proposition;
  4110. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4111. else $proposition_text = $proposition;
  4112. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4113. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4114. //TODO Then get it directly from the form data $_POST!
  4115. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4116. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4117. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4118. $newentry->author_name = $param->author_name;
  4119. $newentry->author_modified_name = $param->author_modified_name;
  4120. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4121. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4122. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4123. $newentry->grade = $param->grade;
  4124. $newentry->timemodified = time();
  4125. $newentry->timecreated = time();
  4126. if ($param->type_iassign == 1) {
  4127. $newentry->timedue = 0;
  4128. $newentry->timeavailable = 0;
  4129. } // if ($param->type_iassign == 1)
  4130. else {
  4131. $newentry->timedue = $param->timedue;
  4132. $newentry->timeavailable = $param->timeavailable;
  4133. }
  4134. $newentry->preventlate = $param->preventlate;
  4135. $newentry->test = $param->test;
  4136. $newentry->special_param1 = $param->special_param1;
  4137. $newentry->visible = $param->visible;
  4138. $newentry->position = $param->position;
  4139. $newentry->max_experiment = $param->max_experiment;
  4140. $newentry->dependency = $param->dependency;
  4141. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4142. $newentry->show_answer = $param->show_answer;
  4143. $id = $DB->insert_record("iassign_statement", $newentry);
  4144. if ($id) {
  4145. $component = 'mod_iassign';
  4146. $filearea = 'exercise';
  4147. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4148. $file = $fs->get_file_by_id($param->file);
  4149. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4150. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4151. //$itemid = $id;
  4152. // File already inserted in other context!
  4153. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4154. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4155. $updateentry = new stdClass();
  4156. $updateentry->id = $id;
  4157. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4158. $updateentry->filesid = $newfile->get_itemid();
  4159. if (!$DB->update_record("iassign_statement", $updateentry))
  4160. print_error('error_add', 'iassign');
  4161. if ($param->type_iassign == 3)
  4162. iassign::update_grade_iassign($param->iassignid);
  4163. //TODO iLM_HTML5 :: //MOOC2014
  4164. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4165. //D if ($iassign_ilm_configs) {
  4166. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4167. //D if ($iassign_ilm_config->param_type != 'static') {
  4168. //D $newentry = new stdClass();
  4169. //D $newentry->iassign_statementid = $id;
  4170. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4171. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4172. //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});
  4173. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4174. //D print_error('error_add_param', 'iassign');
  4175. //D }
  4176. //D }
  4177. //D }
  4178. // log event --------------------------------------------------------------------------------------
  4179. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4180. // log event --------------------------------------------------------------------------------------
  4181. return $id;
  4182. }
  4183. else
  4184. print_error('error_add', 'iassign');
  4185. } // function new_iassign($param)
  4186. /// Add the calendar entries for this iassign
  4187. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4188. // @return bool
  4189. static function add_calendar ($iassignid) {
  4190. global $DB, $CFG;
  4191. require_once($CFG->dirroot . '/calendar/lib.php');
  4192. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4193. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4194. $event = new stdClass();
  4195. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4196. $event->description = $iassign_statement_activity_item->name;
  4197. $event->courseid = $iassign->course;
  4198. $event->groupid = 0;
  4199. $event->userid = 0;
  4200. $event->modulename = 'iassign';
  4201. $event->instance = $iassign->id;
  4202. $event->eventtype = 'due';
  4203. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4204. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4205. calendar_event::create($event);
  4206. }
  4207. /// Update the calendar entries for this iassign
  4208. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4209. // @return bool
  4210. function update_calendar ($iassignid, $olddescription) {
  4211. global $DB, $CFG;
  4212. require_once($CFG->dirroot . '/calendar/lib.php');
  4213. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4214. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4215. $event = new stdClass();
  4216. $event->id = 0;
  4217. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4218. if ($events) {
  4219. foreach ($events as $value) {
  4220. if ($value->description == $olddescription) {
  4221. $event->id = $value->id;
  4222. }
  4223. }
  4224. }
  4225. if ($event->id != 0) {
  4226. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4227. $event->description = $iassign_statement_activity_item->name;
  4228. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4229. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4230. $calendarevent = calendar_event::load($event->id);
  4231. $calendarevent->update($event);
  4232. } else
  4233. $this->add_calendar($iassignid);
  4234. }
  4235. /// Update the calendar entries for this iassign
  4236. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4237. // @return bool
  4238. function delete_calendar ($iassignid) {
  4239. global $DB, $CFG;
  4240. require_once($CFG->dirroot . '/calendar/lib.php');
  4241. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4242. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4243. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4244. if ($events) {
  4245. foreach ($events as $value) {
  4246. if ($value->description == $iassign_statement_activity_item->name) {
  4247. $DB->delete_records('event', array('id' => $value->id));
  4248. }
  4249. }
  4250. }
  4251. }
  4252. /// Update interactive activities
  4253. function update_iassign ($param) {
  4254. global $DB;
  4255. $component = 'mod_iassign';
  4256. $filearea = 'exercise';
  4257. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4258. $file = $fs->get_file_by_id($param->file);
  4259. $fileold = $fs->get_file_by_id($param->fileold);
  4260. if ($param->file != $param->fileold) {
  4261. if ($fileold) {
  4262. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4263. foreach ($fileoldarea as $value) {
  4264. $value->delete();
  4265. }
  4266. }
  4267. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4268. $itemid = $file->get_itemid() + $param->iassign_id;
  4269. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4270. $param->file = $newfile->get_itemid();
  4271. } else
  4272. $param->file = $file->get_itemid();
  4273. } else {
  4274. $param->file = $file->get_itemid();
  4275. }
  4276. $newentry = new stdClass();
  4277. $newentry->id = $param->iassign_id;
  4278. $newentry->name = $param->name;
  4279. $newentry->type_iassign = $param->type_iassign;
  4280. $newentry->store_all_submissions = $param->store_all_submissions;
  4281. //2019 $newentry->proposition = $param->proposition;
  4282. $proposition = $param->proposition;
  4283. if (is_array($proposition))
  4284. $proposition_text = $proposition['text'];
  4285. else
  4286. $proposition_text = $proposition;
  4287. $newentry->proposition = $proposition_text;
  4288. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4289. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4290. $newentry->grade = $param->grade;
  4291. $newentry->author_modified_name = $param->author_modified_name;
  4292. $newentry->timemodified = time();
  4293. if ($param->type_iassign == 1) {
  4294. $newentry->timedue = 0;
  4295. $newentry->timeavailable = 0;
  4296. } // if ($param->type_iassign == 1)
  4297. else {
  4298. $newentry->timedue = $param->timedue;
  4299. $newentry->timeavailable = $param->timeavailable;
  4300. }
  4301. $newentry->preventlate = $param->preventlate;
  4302. $newentry->test = $param->test;
  4303. if (isset($param->special_param1))
  4304. $newentry->special_param1 = $param->special_param1;
  4305. else
  4306. $newentry->special_param1 = NULL;
  4307. $newentry->visible = $param->visible;
  4308. $newentry->max_experiment = $param->max_experiment;
  4309. $newentry->dependency = $param->dependency;
  4310. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4311. $newentry->show_answer = $param->show_answer;
  4312. if (!$DB->update_record("iassign_statement", $newentry))
  4313. print_error('error_update', 'iassign');
  4314. if ($param->type_iassign == 3) {
  4315. iassign::update_grade_iassign($param->iassignid);
  4316. }
  4317. //$id = $newentry->id; // MOOC 2016 --- inicio
  4318. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4319. //if ($iassign_activity_item_configs) {
  4320. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4321. // $newentry = new stdClass();
  4322. // $newentry->id = $iassign_activity_item_config->id;
  4323. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4324. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4325. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4326. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4327. // print_error('error_edit_param', 'iassign');
  4328. // }
  4329. // } // MOOC 2016 --- final
  4330. // log event --------------------------------------------------------------------------------------
  4331. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4332. // log event --------------------------------------------------------------------------------------
  4333. return $newentry->id;
  4334. // if ($param->type_iassign==3)
  4335. // $this->update_grade_iassign($param->iassignid);
  4336. } // function update_iassign($param)
  4337. /// Show information of activity
  4338. function show_info_iassign () {
  4339. global $DB, $OUTPUT;
  4340. $output = '';
  4341. if ($this->activity->type_iassign == 3) {
  4342. if ($this->activity->dependency == 0) {
  4343. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4344. } else {
  4345. $dependencys = explode(';', $this->activity->dependency);
  4346. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4347. foreach ($dependencys as $dependency) {
  4348. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4349. if ($dependencyiassign)
  4350. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4351. } // foreach ($dependencys as $dependency)
  4352. } // if ($iassign_statement_activity_item->dependency == 0)
  4353. if ($this->activity->max_experiment == 0)
  4354. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4355. else
  4356. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4357. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4358. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4359. $output .= '<script>
  4360. function toLeft () {
  4361. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4362. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4363. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4364. document.getElementById("columnsbutton").style.color = "#1da075";
  4365. }
  4366. function toDefault () {
  4367. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4368. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4369. document.getElementById("fullscreen").style.marginTop = "0";
  4370. document.getElementById("columnsbutton").style.color = "#343a40";
  4371. }
  4372. var activate = false;
  4373. function toggleColumns () {
  4374. if (activate) {
  4375. activate = false;
  4376. toDefault();
  4377. } else {
  4378. activate = true;
  4379. toLeft();
  4380. }
  4381. }
  4382. </script>';
  4383. $output .= '<span style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4384. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4385. print $OUTPUT->box($output);
  4386. } // function show_info_iassign()
  4387. /// Shows date of opening and closing activities
  4388. function view_dates () {
  4389. global $USER, $CFG, $DB, $OUTPUT;
  4390. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4391. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4392. $status_iassign = "";
  4393. $status_iassign1 = "";
  4394. $status_iassign2 = "";
  4395. if ($this->activity->type_iassign == 1) // activity of type example
  4396. $type_iassign = get_string('example_iassign', 'iassign');
  4397. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4398. $type_iassign = get_string('test_iassign', 'iassign');
  4399. if ($this->activity->timeavailable > time()) {
  4400. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4401. } elseif ($this->activity->timedue < time()) {
  4402. $status_iassign = get_string('last_timedue', 'iassign');
  4403. }
  4404. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4405. $type_iassign = get_string('exercise_iassign', 'iassign');
  4406. if ($this->activity->timeavailable > time()) {
  4407. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4408. } elseif ($this->activity->timedue < time()) { // after delivery
  4409. $status_iassign = get_string('last_timedue', 'iassign');
  4410. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4411. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4412. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4413. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4414. if ($this->activity->test == 1) // allowed to test after of deadline
  4415. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4416. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4417. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4418. } // elseif ($iassign_statement_activity_item->test == 0)
  4419. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4420. } // elseif ($iassign_statement_activity_item->timedue < time())
  4421. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4422. $output = '<table width=100% >' . "\n";
  4423. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4424. $output .= '<tr>' . "\n";
  4425. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4426. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4427. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4428. // leo $output .= '<td width=80%>' . $type_iassign;
  4429. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4430. // $output .= '</td>' . "\n";
  4431. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4432. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4433. $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>";
  4434. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4435. } else {
  4436. $link_next = "";
  4437. $link_previous = "";
  4438. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4439. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4440. // previous_activity
  4441. if ($iassign_previous) {
  4442. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4443. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4444. } // next_activity
  4445. if ($iassign_next) {
  4446. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4447. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4448. }
  4449. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4450. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4451. $output .= '</tr></table>' . "\n";
  4452. $output .= '<table width=100% >' . "\n";
  4453. if ($this->activity->type_iassign > 1) {
  4454. if ($this->activity->timeavailable)
  4455. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4456. if ($this->activity->timedue)
  4457. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4458. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4459. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4460. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4461. $output .= '</table>' . "\n";
  4462. print $OUTPUT->box($output);
  4463. } // function view_dates()
  4464. } // class activity
  4465. /// Class to manage Interactive Learning Module (iLM)
  4466. class ilm {
  4467. var $ilm;
  4468. /// Constructor of class
  4469. // @param int $id Id of iLM
  4470. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4471. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4472. function __construct ($id) {
  4473. global $DB;
  4474. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4475. if (empty($this->ilm))
  4476. $this->ilm = null;
  4477. }
  4478. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4479. // @calledby view_iassign_current()
  4480. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4481. global $USER, $CFG, $DB;
  4482. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4483. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4484. $typec = strtolower($iassign_ilm->type);
  4485. require_once 'ilm_handlers/' . $typec . '.php';
  4486. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4487. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4488. return $retorno;
  4489. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4490. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4491. // @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);
  4492. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4493. // @param Object $file File in use in activity
  4494. // @return int Return the id of log
  4495. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4496. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4497. $newentry = new stdClass();
  4498. $newentry->iassign_statementid = $iassign_activity_itemid;
  4499. $newentry->userid = $USER->id;
  4500. $newentry->filesid = $content_or_id_from_ilm_security;
  4501. $newentry->timecreated = time();
  4502. $newentry->view = 1;
  4503. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4504. if (!$id_iLM_security) {
  4505. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4506. } // from (!$DB->insert_record("iassign_security", $newentry))
  4507. return $id_iLM_security;
  4508. }
  4509. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4510. // @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);
  4511. // @param int $userid
  4512. // @param int $iassign_activity_itemid Id of iassign statement
  4513. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4514. global $DB;
  4515. // 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")
  4516. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4517. }
  4518. } // class ilm
  4519. /// Class to manage settings of iLM.
  4520. class ilm_settings {
  4521. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4522. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4523. // @param int $ilm_id Id of iLM
  4524. // @param array $options An array with options for create dynamic tag html APPLET
  4525. // @return string Return with a tag html APPLET created
  4526. static function build_ilm_tags ($ilm_id, $options = array()) {
  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::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4533. return $retorno;
  4534. } // static function build_ilm_tags($ilm_id, $options = array())
  4535. /// Function for get modified date of iLM file
  4536. // @param string $file_jar String with Ids of iLM files
  4537. // @return string Return with the filenames and modified date
  4538. static function applet_filetime ($file_jar) {
  4539. $filetime = "";
  4540. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4541. $files_jar = explode(",", $file_jar);
  4542. foreach ($files_jar as $one_file) {
  4543. $file = $fs->get_file_by_id($one_file);
  4544. if ($file)
  4545. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4546. }
  4547. return $filetime;
  4548. }
  4549. /// Function for verify an default applet
  4550. // @param String $file_jar String containing an list de ids of applet files
  4551. // @return boolean Return true or fale if applet is default
  4552. static function applet_default ($file_jar) {
  4553. $is_default = true;
  4554. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4555. $files_jar = explode(",", $file_jar);
  4556. foreach ($files_jar as $one_file) {
  4557. $file = $fs->get_file_by_id($one_file);
  4558. if ($file)
  4559. $is_default &= ($file->get_itemid() == 0);
  4560. }
  4561. return $is_default;
  4562. }
  4563. /// Function for get form variables for add, edit, or copy iLM
  4564. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4565. // @see settings_form.php
  4566. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4567. // @param int $ilm_id Id of iLM
  4568. // @param string $action String with the action
  4569. // @return object Return an object with forms variables
  4570. static function add_edit_copy_ilm ($ilm_id, $action) {
  4571. global $USER, $DB, $CFG;
  4572. require_once('settings_form.php'); // put the form
  4573. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4574. $param = new stdClass();
  4575. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4576. $param->action = $action;
  4577. $param->ilm_id = $ilm_id;
  4578. $CFG->action_ilm = $action;
  4579. $CFG->ilm_id = $ilm_id;
  4580. if ($action == 'add') {
  4581. $param->title = get_string('add_ilm', 'iassign');
  4582. $param->name = "";
  4583. $param->version = "";
  4584. $param->url = "";
  4585. $param->description = "";
  4586. $param->extension = "";
  4587. $param->author = $USER->id;
  4588. $param->file_jar = "";
  4589. $param->file_jar_static = "";
  4590. $param->file_class = "";
  4591. $param->width = 800;
  4592. $param->height = 600;
  4593. $param->enable = 0; // 0 - hide / 1 - show
  4594. $param->timecreated = time();
  4595. $param->timemodified = time();
  4596. $param->evaluate = 0;
  4597. $param->parent = 0;
  4598. }
  4599. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4600. if ($iassign_ilm) {
  4601. $description = json_decode($iassign_ilm->description);
  4602. $param->title = get_string('edit_ilm', 'iassign');
  4603. $param->id = $iassign_ilm->id;
  4604. $param->name_ilm = $iassign_ilm->name;
  4605. $param->name = $iassign_ilm->name;
  4606. $param->version = $iassign_ilm->version;
  4607. $param->ilm_type = $iassign_ilm->type;
  4608. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4609. $param->url = $iassign_ilm->url; // iLM official URL
  4610. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4611. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4612. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4613. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4614. if (!isset($description->{current_language()})) {
  4615. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4616. else
  4617. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4618. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4619. }
  4620. else
  4621. $param->description = $description->{current_language()};
  4622. $param->description_lang = $iassign_ilm->description;
  4623. $param->extension = $iassign_ilm->extension;
  4624. $param->author = $iassign_ilm->author;
  4625. $param->file_jar = $iassign_ilm->file_jar;
  4626. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4627. $param->file_class = $iassign_ilm->file_class;
  4628. $param->width = $iassign_ilm->width;
  4629. $param->height = $iassign_ilm->height;
  4630. $param->enable = $iassign_ilm->enable;
  4631. $param->timecreated = $iassign_ilm->timecreated;
  4632. $param->timemodified = time();
  4633. $param->evaluate = $iassign_ilm->evaluate;
  4634. $param->parent = $iassign_ilm->parent;
  4635. }
  4636. }
  4637. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4638. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4639. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4640. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4641. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4642. // echo "Sem dados<br/>"; exit;
  4643. return;
  4644. }
  4645. $description = json_decode($iassign_ilm->description);
  4646. if ($iassign_ilm) {
  4647. if ($iassign_ilm->parent == 0)
  4648. $iassign_ilm->parent = $ilm_id;
  4649. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4650. $param->title = get_string('new_version_ilm', 'iassign');
  4651. $param->name_ilm = $iassign_ilm->name;
  4652. $param->name = $iassign_ilm->name;
  4653. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4654. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4655. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4656. $param->ilm_type = $iassign_ilm->type;
  4657. $param->url = $iassign_ilm->url;
  4658. $param->description = $description->{current_language()};
  4659. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4660. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4661. $param->extension = $iassign_ilm->extension;
  4662. $param->author = $USER->id;
  4663. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4664. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4665. $param->file_jar_static = '';
  4666. $param->file_class = $iassign_ilm->file_class;
  4667. $param->width = $iassign_ilm->width;
  4668. $param->height = $iassign_ilm->height;
  4669. $param->enable = 0;
  4670. $param->timecreated = time();
  4671. $param->timemodified = time();
  4672. $param->evaluate = $iassign_ilm->evaluate;
  4673. $param->parent = $iassign_ilm->parent;
  4674. }
  4675. }
  4676. elseif ($action == 'copy') {
  4677. $description = json_decode($iassign_ilm->description);
  4678. if ($iassign_ilm) {
  4679. if ($iassign_ilm->parent == 0)
  4680. $iassign_ilm->parent = $ilm_id;
  4681. $param->title = get_string('copy_ilm', 'iassign');
  4682. $param->id = $iassign_ilm->id;
  4683. $param->name_ilm = $iassign_ilm->name;
  4684. $param->name = $iassign_ilm->name;
  4685. $param->version = "";
  4686. $param->ilm_type = $iassign_ilm->type;
  4687. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4688. $param->url = $iassign_ilm->url;
  4689. $param->description = $description->{current_language()};
  4690. $param->description_lang = $iassign_ilm->description;
  4691. $param->extension = $iassign_ilm->extension;
  4692. $param->author = $USER->id;
  4693. $param->file_jar = '';
  4694. $param->file_jar_static = '';
  4695. $param->file_class = $iassign_ilm->file_class;
  4696. $param->width = $iassign_ilm->width;
  4697. $param->height = $iassign_ilm->height;
  4698. $param->enable = 0;
  4699. $param->timecreated = time();
  4700. $param->timemodified = time();
  4701. $param->evaluate = $iassign_ilm->evaluate;
  4702. $param->parent = $iassign_ilm->parent;
  4703. }
  4704. }
  4705. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4706. //D var_dump(debug_backtrace());
  4707. //D print_r(debug_backtrace());
  4708. return $param;
  4709. } // static function add_edit_copy_ilm($ilm_id, $action)
  4710. /// Function for save iLM file in moodledata
  4711. // @param int $itemid Itemid of file save in draft (upload file)
  4712. // @param int $ilm_id Id of iLM
  4713. // @return string Return an string with ids of iLM files
  4714. static function new_file_ilm ($itemid, $iassign_ilm) {
  4715. global $CFG, $USER, $DB;
  4716. $return = null;
  4717. $file_jar = array();
  4718. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4719. $contextuser = context_user::instance($USER->id);
  4720. $contextsystem = context_system::instance();
  4721. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4722. if ($files_ilm) {
  4723. foreach ($files_ilm as $value) {
  4724. // CHECK IF file is HTML type
  4725. if ($iassign_ilm->type == 1) {
  4726. // Check if the file extension is ZIP
  4727. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4728. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4729. if ((strtolower($ext) == 'zip')) {
  4730. // Coping...:
  4731. $destination = 'ilm_debug/' . $value->get_filename();
  4732. $value->copy_content_to($destination);
  4733. // Extracting content...:
  4734. $zip = new ZipArchive();
  4735. $extracted = './ilm';
  4736. $dir = "";
  4737. if ($zip->open($destination) === TRUE) {
  4738. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4739. if (is_dir($dir)) {
  4740. $i = 1;
  4741. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4742. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4743. $i ++;
  4744. }
  4745. $name = $previous . "_" . $i;
  4746. $dir = './ilm/' . $name . "/";
  4747. $j = 0;
  4748. while ($item_name = $zip->getNameIndex($j)) {
  4749. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4750. $j++;
  4751. }
  4752. $zip->close();
  4753. }
  4754. $zip->open($destination);
  4755. $zip->extractTo($extracted);
  4756. $zip->close();
  4757. // After the extraction, remove it from DEBUG
  4758. unlink($destination);
  4759. } else { // Error trying to open destination...
  4760. // After the extraction error, also remove it from DEBUG
  4761. unlink($destination);
  4762. print_error('error_add_ilm_zip', 'iassign');
  4763. }
  4764. return $dir;
  4765. }
  4766. } // if ($iassign_ilm->type == 1)
  4767. if ($value->get_filename() != '.') {
  4768. $file_ilm = array(
  4769. 'userid' => $USER->id,
  4770. 'contextid' => $contextsystem->id,
  4771. 'component' => 'mod_iassign',
  4772. 'filearea' => 'ilm',
  4773. 'itemid' => rand(1, 999999999),
  4774. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4775. 'filename' => $value->get_filename());
  4776. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4777. array_push($file_jar, $file_ilm->get_id());
  4778. }
  4779. }
  4780. if (!empty($file_jar)) {
  4781. $return = implode(",", $file_jar);
  4782. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4783. foreach ($old_file_jar as $value) {
  4784. $file = $fs->get_file_by_id($value);
  4785. if ($file)
  4786. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4787. }
  4788. }
  4789. }
  4790. else // if ($files_ilm)
  4791. $return = $iassign_ilm->file_jar;
  4792. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4793. return $return;
  4794. } // static function new_file_ilm($itemid, $iassign_ilm)
  4795. /// Function for save in database an new iLM
  4796. // @param object $param An object with iLM params
  4797. static function new_ilm ($itemid) {
  4798. global $CFG, $USER, $OUTPUT;
  4799. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4800. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4801. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4802. }
  4803. $pathtemp = $CFG->dataroot . '/temp/';
  4804. $contextuser = context_user::instance($USER->id);
  4805. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4806. $zip = new zip_packer();
  4807. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4808. foreach ($files as $file) {
  4809. if (!$file->is_directory())
  4810. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4811. }
  4812. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4813. // Verifica se o pacote possui o XML
  4814. if (!$application_xml) {
  4815. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4816. return;
  4817. } else {
  4818. $missing = "";
  4819. if (!isset($application_xml->name)) {
  4820. $missing .= "name";
  4821. }
  4822. if (!isset($application_xml->version)) {
  4823. $missing .= ", version";
  4824. }
  4825. if (!isset($application_xml->type)) {
  4826. $missing .= ", type";
  4827. }
  4828. if (!isset($application_xml->extension)) {
  4829. $missing .= ", extension";
  4830. }
  4831. if (!isset($application_xml->file_jar)) {
  4832. $missing .= ", file_jar";
  4833. }
  4834. if (!isset($application_xml->file_class)) {
  4835. $missing .= ", file_class";
  4836. }
  4837. if (!isset($application_xml->width)) {
  4838. $missing .= ", width";
  4839. }
  4840. if (!isset($application_xml->height)) {
  4841. $missing .= ", height";
  4842. }
  4843. if (!isset($application_xml->evaluate)) {
  4844. $missing .= ", evaluate";
  4845. }
  4846. if (strlen($missing) > 2) {
  4847. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4848. return;
  4849. }
  4850. }
  4851. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4852. $typec = strtolower($application_xml->type);
  4853. require_once 'ilm_handlers/' . $typec . '.php';
  4854. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4855. return $retorno;
  4856. } // static function new_ilm($itemid)
  4857. /// Function for save in database an iLM edit
  4858. // @param object $param An object with iLM params
  4859. static function edit_ilm ($param, $itemid) {
  4860. // Descobrir o tipo de iLM:
  4861. global $DB, $USER, $CFG;
  4862. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4863. $pathtemp = $CFG->dataroot . '/temp/';
  4864. $contextuser = context_user::instance($USER->id);
  4865. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4866. $zip = new zip_packer();
  4867. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4868. $files_extract = null;
  4869. foreach ($files as $file) {
  4870. if (!$file->is_directory())
  4871. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4872. }
  4873. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4874. $typec = strtolower($iassign_t->type);
  4875. require_once 'ilm_handlers/' . $typec . '.php';
  4876. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4877. }
  4878. /// Function for register the new iLM (in database and in the directory)
  4879. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4880. // @param object $param An object with iLM params
  4881. static function copy_new_version_ilm ($param) {
  4882. global $DB, $CFG, $USER;
  4883. $itemid = $param->file;
  4884. $pathtemp = $CFG->dataroot . '/temp/';
  4885. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4886. //D echo "pathtemp=$pathtemp<br/>";
  4887. $contextuser = context_user::instance($USER->id);
  4888. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4889. $zip = new zip_packer();
  4890. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4891. $files_extract = null;
  4892. foreach ($files as $file) {
  4893. if (!$file->is_directory())
  4894. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4895. }
  4896. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4897. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4898. $typec = strtolower($iassign_t->type);
  4899. require_once 'ilm_handlers/' . $typec . '.php';
  4900. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4901. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4902. } // static function copy_new_version_ilm($param)
  4903. //VER::
  4904. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4905. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4906. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4907. /// Function for change visibility of iLM
  4908. // @param int $ilm_id Id of iLM
  4909. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4910. static function visible_ilm ($ilm_id, $status) {
  4911. global $DB;
  4912. if ($status == 0)
  4913. $visible = 1;
  4914. else
  4915. $visible = 0;
  4916. $newentry = new stdClass();
  4917. $newentry->id = $ilm_id;
  4918. $newentry->enable = $visible;
  4919. if (!$DB->update_record("iassign_ilm", $newentry))
  4920. error(get_string('error_edit_ilm', 'iassign'));
  4921. }
  4922. /// Function for confirm change default iLM
  4923. // @param int $ilm_id Id of iLM
  4924. // @param int $ilm_parent Id of parent iLM
  4925. // @return string Return with an string for create default page confirmation
  4926. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4927. global $OUTPUT, $DB;
  4928. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4929. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4930. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4931. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4932. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4933. return $return;
  4934. }
  4935. /// Function for change the default iLM
  4936. // @see settings_ilm.php
  4937. // @param int $ilm_id Id of iLM
  4938. // @return int Return Id of default iLM
  4939. static function default_ilm ($ilm_id) {
  4940. global $DB;
  4941. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4942. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4943. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4944. $iassign_ilm_default->id = $iassign_ilm->id;
  4945. $iassign_ilm_default->parent = 0;
  4946. $iassign_ilm->parent = $iassign_ilm_default->id;
  4947. $iassign_ilm->id = 0;
  4948. $iassign_ilm_default->enable = 1;
  4949. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4950. print_error('error_edit_ilm', 'iassign');
  4951. }
  4952. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4953. if (!$inserted) {
  4954. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4955. print_error($msg_error);
  4956. //xx print_error('error_add_ilm', 'iassign');
  4957. }
  4958. return $iassign_ilm_default->id;
  4959. } // static function default_ilm ($ilm_id)
  4960. /// Function for confirm delete iLM
  4961. // @param int $ilm_id Id of iLM
  4962. // @param int $ilm_parent Id of parent iLM
  4963. // @return string Return with an string for create delete page confirmation
  4964. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4965. global $OUTPUT, $DB;
  4966. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4967. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4968. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4969. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4970. }
  4971. /// Function for delete directory where the iLM is allocated.
  4972. // @param string $dirPath
  4973. // @throws InvalidArgumentException
  4974. public static function delete_dir ($dirPath) {
  4975. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4976. $dirPath .= '/';
  4977. }
  4978. $files = glob($dirPath . '*', GLOB_MARK);
  4979. foreach ($files as $file) {
  4980. if (is_dir($file)) {
  4981. ilm_settings::delete_dir($file);
  4982. } else {
  4983. unlink($file);
  4984. }
  4985. }
  4986. rmdir($dirPath);
  4987. }
  4988. /// Function for delete iLM
  4989. // @param int $ilm_id Id of iLM
  4990. // @return int Return Id of parent iLM
  4991. static function delete_ilm ($ilm_id) {
  4992. global $DB;
  4993. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4994. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4995. $typec = strtolower($iassign_ilm->type);
  4996. require_once 'ilm_handlers/' . $typec . '.php';
  4997. $retorno = $typec::delete_ilm($ilm_id);
  4998. return $retorno;
  4999. }
  5000. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5001. // @param int $ilm_id Id of iLM
  5002. static function export_ilm ($ilm_id) {
  5003. global $DB;
  5004. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5005. if (!$iassign_ilm) return; // security debug...
  5006. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5007. $typec = strtolower($iassign_ilm->type);
  5008. if (!$typec) $typec = "html5"; // security debug...
  5009. require_once 'ilm_handlers/' . $typec . '.php';
  5010. $typec::export_ilm($ilm_id);
  5011. } // static function export_ilm($ilm_id)
  5012. //TODO iLM_HTML5 :: //MOOC 2016
  5013. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5014. // @param int $ilm_id Id of iLM
  5015. static function export_update_ilm ($ilm_id) {
  5016. global $DB, $CFG;
  5017. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5018. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5019. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5020. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5021. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5022. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5023. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5024. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5025. $upgrade_descriptor .= '</upgrade>' . "\n";
  5026. file_put_contents($xml_filename, $upgrade_descriptor);
  5027. header("Pragma: public");
  5028. header("Expires: 0");
  5029. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5030. header("Cache-Control: private", false);
  5031. header('Content-Type: application/xml; charset=utf-8');
  5032. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5033. header("Content-Length: " . @filesize($xml_filename));
  5034. set_time_limit(0);
  5035. @readfile("$xml_filename") || die("File not found.");
  5036. unlink($xml_filename);
  5037. exit;
  5038. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5039. /// Function for save iLM from XML descriptor
  5040. // @param array $application_xml Data of XML descriptor
  5041. // @param array $files_extract Filenames of extract files
  5042. // @return array Return an array content id of JAR files
  5043. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5044. global $CFG, $USER;
  5045. // Tratamento diferenciado se for do tipo HTML5:
  5046. $source = "";
  5047. $diretorio = "";
  5048. if (strtolower($application_xml->type) == 'html5') {
  5049. $i = 0;
  5050. foreach ($files_extract as $key => $value) {
  5051. $file = $CFG->dataroot . '/temp/' . $key;
  5052. // Verifica se já existe a pasta no diretório dos iLM:
  5053. if ($i == 0) {
  5054. $source = $file;
  5055. if (file_exists("ilm/" . basename($file))) {
  5056. $j = 1;
  5057. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5058. $j ++;
  5059. }
  5060. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5061. // mkdir($diretorio, 0777, true);
  5062. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5063. }
  5064. else {
  5065. $diretorio = 'ilm/' . basename($file);
  5066. // mkdir($diretorio, 0777, true);
  5067. mkdir($diretorio, 0755, true);
  5068. }
  5069. break;
  5070. }
  5071. $i ++;
  5072. }
  5073. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5074. if ($item->isDir()) {
  5075. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5076. }
  5077. else {
  5078. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5079. }
  5080. }
  5081. ilm_settings::delete_dir($source);
  5082. return "./" . $diretorio;
  5083. }
  5084. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5085. $file_jar = array();
  5086. $files_ilm = explode(",", $application_xml->file_jar);
  5087. $contextsystem = context_system::instance();
  5088. foreach ($files_ilm as $value) {
  5089. $file_ilm = array(
  5090. 'userid' => $USER->id,
  5091. 'contextid' => $contextsystem->id,
  5092. 'component' => 'mod_iassign',
  5093. 'filearea' => 'ilm',
  5094. 'itemid' => rand(1, 999999999),
  5095. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5096. 'filename' => $value);
  5097. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5098. array_push($file_jar, $file_ilm->get_id());
  5099. }
  5100. foreach ($files_extract as $key => $value) {
  5101. $file = $CFG->dataroot . '/temp/' . $key;
  5102. if (file_exists($file))
  5103. unlink($file);
  5104. }
  5105. return $file_jar;
  5106. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5107. /// Function for import the iLM from an package
  5108. // @param int $itemid Itemid of zip file
  5109. static function import_ilm ($itemid) {
  5110. global $CFG, $USER, $OUTPUT;
  5111. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5112. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5113. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5114. }
  5115. $pathtemp = $CFG->dataroot . '/temp/';
  5116. $contextuser = context_user::instance($USER->id);
  5117. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5118. $zip = new zip_packer();
  5119. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5120. foreach ($files as $file) {
  5121. if (!$file->is_directory())
  5122. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5123. }
  5124. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5125. // Verifica se o pacote possui o XML
  5126. if (!$application_xml) {
  5127. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5128. return;
  5129. } else {
  5130. $missing = "";
  5131. if (!isset($application_xml->name)) {
  5132. $missing .= "name";
  5133. }
  5134. if (!isset($application_xml->version)) {
  5135. $missing .= ", version";
  5136. }
  5137. if (!isset($application_xml->type)) {
  5138. $missing .= ", type";
  5139. }
  5140. if (!isset($application_xml->extension)) {
  5141. $missing .= ", extension";
  5142. }
  5143. if (!isset($application_xml->file_jar)) {
  5144. $missing .= ", file_jar";
  5145. }
  5146. if (!isset($application_xml->file_class)) {
  5147. $missing .= ", file_class";
  5148. }
  5149. if (!isset($application_xml->width)) {
  5150. $missing .= ", width";
  5151. }
  5152. if (!isset($application_xml->height)) {
  5153. $missing .= ", height";
  5154. }
  5155. if (!isset($application_xml->evaluate)) {
  5156. $missing .= ", evaluate";
  5157. }
  5158. if (strlen($missing) > 2) {
  5159. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5160. return;
  5161. }
  5162. }
  5163. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5164. $typec = strtolower($application_xml->type);
  5165. require_once 'ilm_handlers/' . $typec . '.php';
  5166. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5167. } // static function import_ilm($itemid)
  5168. /// Function for list iLM defaults
  5169. // @return string Return an string with a table of iLM
  5170. static function list_ilm () {
  5171. global $DB, $OUTPUT;
  5172. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5173. $str = '';
  5174. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5175. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5176. if ($iassign_ilm) {
  5177. foreach ($iassign_ilm as $ilm) {
  5178. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5179. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5180. $str .= '<tr><td>';
  5181. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5182. $str .= '<tr>';
  5183. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5184. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5185. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5186. $str .= '</tr>';
  5187. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5188. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5189. $str .= '</table>';
  5190. $str .= '</td></tr>';
  5191. }
  5192. }
  5193. $str .= '</table>';
  5194. return $str;
  5195. }
  5196. /// Function for download and install an upgrade of an iLM
  5197. // @param int $ilm_id Id of iLM
  5198. static function upgrade_ilm ($ilm_id) {
  5199. global $DB, $CFG, $USER;
  5200. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5201. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5202. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5203. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5204. if (!$result)
  5205. print_error('error_upgrade_ilm', 'iassign');
  5206. else {
  5207. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5208. $extension = explode(".", $zip_filename);
  5209. if ($extension[count($extension) - 1] != 'ipz') {
  5210. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5211. die;
  5212. }
  5213. $zip = new zip_packer();
  5214. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5215. $contextuser = context_user::instance($USER->id);
  5216. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5217. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5218. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5219. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5220. if (file_exists($zip_filename))
  5221. unlink($zip_filename);
  5222. if (empty($file_jar)) {
  5223. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5224. print_error($msg_error);
  5225. //xx print_error('error_add_ilm', 'iassign');
  5226. }
  5227. else {
  5228. $newentry = new stdClass();
  5229. $newentry->name = (String) $application_xml->name;
  5230. $newentry->version = (String) $application_xml->version;
  5231. $newentry->url = (String) $application_xml->url;
  5232. $newentry->description = $description_str;
  5233. $newentry->extension = strtolower((String) $application_xml->extension);
  5234. $newentry->file_jar = implode(",", $file_jar);
  5235. $newentry->file_class = (String) $application_xml->file_class;
  5236. $newentry->width = (String) $application_xml->width;
  5237. $newentry->height = (String) $application_xml->height;
  5238. $newentry->enable = 0;
  5239. $newentry->timemodified = time();
  5240. $newentry->author = $USER->id;
  5241. $newentry->timecreated = time();
  5242. $newentry->evaluate = (String) $application_xml->evaluate;
  5243. $newentry->parent = $ilm_id;
  5244. }
  5245. }
  5246. return $iassign_ilm->id;
  5247. } // static function upgrade_ilm($ilm_id)
  5248. //MOOC2014 -- inicio
  5249. //TODO: REVIEW
  5250. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5251. // static function move_iassign($ilm_id)
  5252. //MOOC2014 -- final
  5253. /// Function for list iLM versions with all informations
  5254. // @return string Return an string with a table of iLM
  5255. static function view_ilm ($ilmid, $from) {
  5256. global $DB;
  5257. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5258. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5259. $typec = strtolower($iassign_ilm->type);
  5260. require_once 'ilm_handlers/' . $typec . '.php';
  5261. $retorno = $typec::view_ilm($ilmid, $from);
  5262. return $retorno;
  5263. }
  5264. /// Function for get form variables for add, edit, or copy iLM params
  5265. // @param int $ilm_param_id Id of iLM param
  5266. // @param string $action String with the action
  5267. // @return object Return an object with forms variables
  5268. static function add_edit_copy_param ($ilm_param_id, $action) {
  5269. global $DB;
  5270. require_once('params_form.php');
  5271. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5272. $param = new stdClass();
  5273. $param->action = $action;
  5274. $param->ilm_param_id = $ilm_param_id;
  5275. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5276. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5277. $type = $iassign_ilm_config->param_type;
  5278. if ($action == 'add') {
  5279. $param->title = get_string('add_ilm', 'iassign');
  5280. $param->iassign_ilmid = $ilm_param_id;
  5281. $param->param_name = "";
  5282. $param->param_value = "";
  5283. $param->description = "";
  5284. $param->visible = 1;
  5285. }
  5286. elseif ($action == 'edit') {
  5287. if ($iassign_ilm_config) {
  5288. $param->title = get_string('edit_ilm', 'iassign');
  5289. $param->id = $iassign_ilm_config->id;
  5290. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5291. $param->param_type = $type; //MOOC2014
  5292. $param->param_name = $iassign_ilm_config->param_name;
  5293. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5294. $param->param_value = $iassign_ilm_config->param_value;
  5295. else //MOOC2014
  5296. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5297. $param->param_value = $iassign_ilm_config->param_value;
  5298. $param->description = $iassign_ilm_config->description;
  5299. $param->visible = $iassign_ilm_config->visible;
  5300. }
  5301. }
  5302. elseif ($action == 'copy') {
  5303. if ($iassign_ilm_config) {
  5304. $param->title = get_string('copy_ilm', 'iassign');
  5305. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5306. $param->param_type = $type; //MOOC2014
  5307. $param->param_name = $iassign_ilm_config->param_name;
  5308. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5309. $param->param_value = $iassign_ilm_config->param_value;
  5310. else //MOOC2014
  5311. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5312. $param->description = $iassign_ilm_config->description;
  5313. $param->visible = $iassign_ilm_config->visible;
  5314. }
  5315. }
  5316. return $param;
  5317. } // static function add_edit_copy_param($ilm_param_id, $action)
  5318. /// Function for change visibility of iLM param
  5319. // @param int $ilm_param_id Id of iLM param
  5320. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5321. static function visible_param ($ilm_param_id, $status) {
  5322. global $DB, $CFG;
  5323. if ($status == 0)
  5324. $visible = 1;
  5325. else
  5326. $visible = 0;
  5327. $newentry = new stdClass();
  5328. $newentry->id = $ilm_param_id;
  5329. $newentry->visible = $visible;
  5330. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5331. error(get_string('error_edit_param', 'iassign'));
  5332. }
  5333. /// Function for save in database an new iLM param
  5334. // @param object $param An object with iLM params
  5335. static function add_param ($param) {
  5336. global $DB;
  5337. $newentry = new stdClass();
  5338. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5339. //MOOC2014 $newentry->param_name = $param->param_name;
  5340. $newentry->param_type = $param->param_type; //MOOC2014
  5341. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5342. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5343. $newentry->param_value = $param->param_value;
  5344. else //MOOC2014
  5345. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5346. $newentry->description = $param->description;
  5347. $newentry->visible = $param->visible;
  5348. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5349. if (!$newentry->id) {
  5350. print_error('error_add_param', 'iassign');
  5351. }
  5352. }
  5353. /// Function for save in database a iLM param edit
  5354. // @param object $param An object with iLM params
  5355. static function edit_param ($param) {
  5356. global $DB;
  5357. $updentry = new stdClass();
  5358. $updentry->id = $param->id;
  5359. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5360. $updentry->param_type = $param->param_type; //MOOC2014
  5361. // $updentry->param_name = $param->param_name;
  5362. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5363. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5364. $updentry->param_value = $param->param_value;
  5365. else //MOOC2014
  5366. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5367. $updentry->description = $param->description;
  5368. $updentry->visible = $param->visible;
  5369. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5370. error(get_string('error_edit_param', 'iassign'));
  5371. }
  5372. }
  5373. /// Function for save in database a iLM param copy
  5374. // @param object $param An object with iLM params
  5375. static function copy_param ($param) {
  5376. global $DB;
  5377. $newentry = new stdClass();
  5378. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5379. //$newentry->param_name = $param->param_name;
  5380. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5381. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5382. $newentry->param_value = $param->param_value;
  5383. else //MOOC2014
  5384. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5385. $newentry->description = $param->description;
  5386. $newentry->visible = $param->visible;
  5387. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5388. if (!$newentry->id) {
  5389. print_error('error_add_param', 'iassign');
  5390. }
  5391. }
  5392. /// Function for delete iLM param of database
  5393. // @param int $param_id Id of iLM param
  5394. static function delete_param ($param_id) {
  5395. global $DB;
  5396. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5397. print_error('error_delete_param', 'iassign');
  5398. }
  5399. }
  5400. } // class ilm_settings
  5401. /// Class for manage iLM files (editor).
  5402. class ilm_manager {
  5403. var $id; // course id
  5404. var $url;
  5405. var $from;
  5406. /// Constructor for the base ilm_manager class
  5407. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5408. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5409. function __construct ($id, $url, $from) {
  5410. $this->id = $id; // course id
  5411. $this->url = $url;
  5412. $this->from = $from;
  5413. }
  5414. /// Function to get iAssign content file in Moodle data (exercise)
  5415. // @calledby x function preview_ilm($iassign_ilm) :
  5416. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5417. function get_file_ilm () {
  5418. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5419. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5420. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5421. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5422. $md_file = $fs->get_file_by_id($fileid);
  5423. $ilm_content_file = $md_file->get_content();
  5424. return $ilm_content_file;
  5425. }
  5426. /// Function for creating a new file from the iLM online editor
  5427. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5428. function ilm_editor_new () {
  5429. global $CFG, $DB, $OUTPUT, $PAGE;
  5430. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5431. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5432. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5433. $context = context_course::instance($this->id);
  5434. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5435. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5436. if (!$iassign) {
  5437. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5438. die();
  5439. }
  5440. $temp = explode(",", $iassign->extension);
  5441. $extension = $temp[0]; // default extension for this iLM
  5442. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5443. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5444. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5445. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5446. if ($stringArchiveContent != NULL) {
  5447. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5448. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5449. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5450. $filename = optional_param('filename', NULL, PARAM_RAW);
  5451. //Leo $filename = iassign_utils::format_filename($filename); //
  5452. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5453. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5454. //2019/02 $arrayfilename = explode(".", $filename);
  5455. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5456. //2019/02 $count_dots = count($arrayfilename);
  5457. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5458. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5459. //2019/02 if ($last_name != $extension)
  5460. //2019/02 $filename = $filename . '.' . $extension;
  5461. //2019/02 }
  5462. //2019/02 else { // no extension...
  5463. //2019/02 $filename = $filename . '.' . $extension;
  5464. //2019/02 }
  5465. // Store the name of recent created file
  5466. $_SESSION['file_name'] = $filename;
  5467. //$this->write_file_iassign($string, $filename);
  5468. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5469. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5470. die();
  5471. }
  5472. else { // if ($stringArchiveContent != NULL)
  5473. // iLM On-line editor
  5474. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5475. $str_get_iLM = "window.frames.iLM";
  5476. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5477. }
  5478. else { // otherwise it is JAR named 'iLM'
  5479. $str_get_iLM = "document.iLM";
  5480. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5481. }
  5482. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5483. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5484. $files_array = '';
  5485. foreach ($files as $value) {
  5486. if ($value->get_filename() != ".")
  5487. $files_array .= "'" . $value->get_filename() . "',";
  5488. }
  5489. $files_array .= "''";
  5490. $file = null;
  5491. $ia_content = "";
  5492. $filename = "";
  5493. $error_files_exists = get_string('error_file_exists', 'iassign');
  5494. $output = "<script type='text/javascript'>
  5495. //<![CDATA[
  5496. //D alert('locallib.php: ilm_editor_new');
  5497. function submit_iLM_Answer () {
  5498. var docFormOnLineEditor = document.formEnvio;
  5499. var resposta_exerc = new Array(3);
  5500. var valor_resposta = new Array(3);
  5501. var sessao = new Array(3);
  5502. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5503. resposta_exerc[0] = doc_iLM.getAnswer();
  5504. valor_resposta[0] = doc_iLM.getEvaluation();
  5505. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5506. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5507. var files = new Array(" . $files_array . ");
  5508. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5509. if (docFormOnLineEditor.filename.value=='') {
  5510. // ERROR: the file name is empty
  5511. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5512. return false;
  5513. }
  5514. // }
  5515. for (i=0; i<files.length; i++) {
  5516. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5517. alert('" . $error_files_exists . "');
  5518. return false;
  5519. }
  5520. }
  5521. docFormOnLineEditor.submit();
  5522. return true;
  5523. }
  5524. //]]>
  5525. </script>\n";
  5526. $output .= "
  5527. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5528. $output .= $OUTPUT->box_start();
  5529. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5530. $output .= "
  5531. <table width='100%' cellpadding='20'>
  5532. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5533. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5534. </tr>
  5535. </table>\n";
  5536. $output .= $OUTPUT->box_end();
  5537. $output .= "<center>\n";
  5538. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5539. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5540. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5541. $output .= $output_ilm;
  5542. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5543. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5544. </center>
  5545. </form>\n";
  5546. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5547. $PAGE->navbar->add($title);
  5548. $PAGE->set_title($title);
  5549. $PAGE->set_heading($title); // insert title above the navigation bar
  5550. print $OUTPUT->header();
  5551. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5552. print $output;
  5553. print $OUTPUT->footer();
  5554. }
  5555. die();
  5556. } // function ilm_editor_new()
  5557. /// Function for editing an file in online editor
  5558. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5559. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5560. global $CFG, $DB, $OUTPUT, $PAGE;
  5561. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5562. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5563. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5564. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5565. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5566. // If iLM is not registered, error!
  5567. if (!$iassign) {
  5568. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5569. die;
  5570. }
  5571. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5572. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5573. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5574. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5575. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5576. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5577. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5578. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5579. if ($stringArchiveContent != NULL) {
  5580. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5581. die();
  5582. } else { // if ($stringArchiveContent != NULL)
  5583. $end_file = '';
  5584. if ($content_file) {
  5585. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5586. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5587. }
  5588. $temp = explode(",", $iassign->extension);
  5589. $extension = $temp[0]; // default extension for this iLM
  5590. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5591. $str_get_iLM = "window.frames.iLM";
  5592. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5593. } else { // otherwise it is JAR named 'iLM'
  5594. $str_get_iLM = "document.iLM";
  5595. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5596. }
  5597. $output = "<script type='text/javascript'>
  5598. //<![CDATA[
  5599. function submit_iLM_Answer () {
  5600. var docFormEditor = document.formEnvio;
  5601. var activityAnswer; // to get activity answer (text)
  5602. var activityValue; // to get activity answer value (float)
  5603. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5604. //activityAnswer = doc_iLM.getAnswer();
  5605. //activityValue = doc_iLM.getEvaluation();
  5606. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5607. activityValue = " . $str_get_iLM . ".getEvaluation();
  5608. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5609. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5610. docFormEditor.submit();
  5611. return true;
  5612. }
  5613. //]]>
  5614. </script>\n";
  5615. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5616. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5617. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5618. // return true;
  5619. // }
  5620. $output .= "
  5621. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5622. $output .= $OUTPUT->box_start();
  5623. $output .= "
  5624. <table width='100%' cellpadding='20'>
  5625. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5626. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5627. <input type='hidden' name='filename' value='$filename'/></td>
  5628. <td>
  5629. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5630. </tr>
  5631. </table>\n";
  5632. $output .= $OUTPUT->box_end();
  5633. $output .= " <center>\n";
  5634. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5635. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5636. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5637. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5638. </center>
  5639. </form>\n";
  5640. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5641. $PAGE->navbar->add($title);
  5642. $PAGE->set_title($title);
  5643. $PAGE->set_heading($title); // insert title above the navigation bar
  5644. print $OUTPUT->header();
  5645. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5646. print $output;
  5647. print $OUTPUT->footer();
  5648. } // else if ($stringArchiveContent != NULL)
  5649. die();
  5650. } // function ilm_editor_update()
  5651. /// Function for write iAssign file in Moodle data (exercise)
  5652. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5653. // @param string $stringArchiveContent Content of iassign file
  5654. // @param string $filename Filename of iassign file
  5655. function write_file_iassign ($stringArchiveContent, $filename) {
  5656. global $USER;
  5657. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5658. $context = context_course::instance($this->id);
  5659. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5660. $dirid = $this->get_dir_ilm('dirid');
  5661. $dir = $fs->get_file_by_id($dirid);
  5662. $fileinfo = array('contextid' => $context->id, // ID of course
  5663. 'component' => 'mod_iassign', // usually = table name
  5664. 'filearea' => 'activity', // usually = table name
  5665. 'itemid' => 0, // usually = ID of row in table
  5666. 'filepath' => '/', // any path beginning and ending whith '/'
  5667. 'userid' => $USER->id,
  5668. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5669. 'filename' => $filename); // any filename
  5670. // Create file containing text. '$stringArchiveContent'
  5671. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5672. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5673. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5674. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5675. // 'Activité interactive enregistrée avec succès sous le nom:';
  5676. // 'Atividade interativa gravada com sucesso sob o nome:'
  5677. $output = "
  5678. <script type='text/javascript'>
  5679. //<![CDATA[
  5680. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5681. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5682. //]]>
  5683. </script>";
  5684. print $output;
  5685. die();
  5686. }
  5687. /// Function for write iAssign file in Moodle data (exercise)
  5688. // @param string $stringArchiveContent Content of iassign file
  5689. // @param string $filename Filename of iassign file
  5690. // @param int $itemid Itemid of iassign file
  5691. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5692. global $OUTPUT, $USER;
  5693. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5694. $context = context_course::instance($this->id);
  5695. $dirid = $this->get_dir_ilm('dirid');
  5696. if ($stringArchiveContent != (-1)) {
  5697. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5698. $file = $fs->get_file_by_id($fileid);
  5699. if (!$file) {
  5700. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5701. die;
  5702. }
  5703. $fileinfo = array('contextid' => $context->id, // ID of context
  5704. 'component' => 'mod_iassign', // usually = table name
  5705. 'filearea' => 'activity', // usually = table name
  5706. 'itemid' => 0, // usually = ID of row in table
  5707. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5708. 'userid' => $USER->id,
  5709. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5710. 'license' => 'allrightsreserved', // allrightsreserved
  5711. 'timecreated' => $file->get_timecreated(),
  5712. 'filename' => $file->get_filename()); // any filename
  5713. $file->delete();
  5714. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5715. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5716. }
  5717. $output = "<script type='text/javascript'>
  5718. //<![CDATA[
  5719. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5720. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5721. //]]>
  5722. </script>";
  5723. print $output;
  5724. die();
  5725. }
  5726. /// Function for create an tag for iAssign filter
  5727. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5728. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5729. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5730. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5731. // @param int $fileid Id of file
  5732. // @return string Return an string with an tag of iassign filter
  5733. function tag_ilm ($fileid) {
  5734. global $DB;
  5735. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5736. $width = '600';
  5737. $height = '400';
  5738. $file = $fs->get_file_by_id($fileid);
  5739. $filetype = explode(".", $file->get_filename());
  5740. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5741. foreach ($iassign_ilm as $value) {
  5742. $extensions = explode(",", $value->extension);
  5743. if (in_array($filetype[1], $extensions)) {
  5744. $width = $value->width;
  5745. $height = $value->height;
  5746. }
  5747. }
  5748. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5749. }
  5750. /// Function for delete iAssign file in Moodle data (exercise)
  5751. function delete_file_ilm () {
  5752. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5753. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5754. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5755. $file = $fs->get_file_by_id($fileid);
  5756. if ($file)
  5757. $file->delete();
  5758. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5759. die();
  5760. }
  5761. /// Function for delete selected iAssign file in Moodle data (exercise)
  5762. function delete_selected_ilm () {
  5763. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5764. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5765. $context = context_course::instance($this->id);
  5766. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5767. $dirid = $this->get_dir_ilm('dirid');
  5768. foreach ($files_id as $file_id) {
  5769. $file = $fs->get_file_by_id($file_id);
  5770. if ($file) {
  5771. if (!$file->is_directory())
  5772. $file->delete();
  5773. else {
  5774. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5775. foreach ($files_delete as $value)
  5776. $value->delete();
  5777. $file->delete();
  5778. }
  5779. }
  5780. }
  5781. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5782. die();
  5783. }
  5784. /// Function for duplicate iAssign file from "online" edition
  5785. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5786. function duplicate_file_ilm () {
  5787. global $USER, $COURSE;
  5788. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5789. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5790. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5791. $filename = optional_param('filename', NULL, PARAM_RAW);
  5792. $file = $fs->get_file_by_id($fileid);
  5793. $context = context_course::instance($this->id);
  5794. $fileinfo = array(
  5795. 'contextid' => $context->id, // ID of context
  5796. 'component' => 'mod_iassign', // usually = table name
  5797. 'filearea' => 'activity', // usually = table name
  5798. 'itemid' => 0, // usually = ID of row in table
  5799. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5800. 'userid' => $USER->id,
  5801. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5802. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5803. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5804. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5805. die();
  5806. }
  5807. /// Function for rename iAssign file
  5808. function rename_file_ilm () {
  5809. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5810. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5811. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5812. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5813. $file = $fs->get_file_by_id($fileid);
  5814. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5815. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5816. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5817. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5818. die();
  5819. }
  5820. /// Function for get iassign file for iassign form
  5821. function add_ilm () {
  5822. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5823. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5824. $output = "
  5825. <script type='text/javascript'>
  5826. //<![CDATA[
  5827. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5828. iassign_file_link.innerHTML = '$filename';
  5829. window.opener.document.forms['mform1'].file.value='$fileid';
  5830. window.opener.document.forms['mform1'].filename.value='$filename';
  5831. window.close();
  5832. //]]>
  5833. </script>";
  5834. print $output;
  5835. die();
  5836. }
  5837. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5838. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5839. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5840. function preview_ilm ($courseid, $iassign_ilm) {
  5841. global $OUTPUT, $CFG, $USER;
  5842. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5843. $title = get_string('modulename', 'iassign'); // iAssign
  5844. print $OUTPUT->header();
  5845. print $OUTPUT->box_start();
  5846. $javascript = "
  5847. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5848. <script type='text/javascript'>
  5849. //<![CDATA[
  5850. function submit_close () {
  5851. window.opener.location.reload();
  5852. window.close();
  5853. }
  5854. //]]>
  5855. </script>\n";
  5856. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5857. // to the complete "applet" tag
  5858. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5859. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5860. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5861. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5862. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5863. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5864. if ($ilm_name != "ivprog") {
  5865. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5866. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5867. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5868. } else {
  5869. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5870. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5871. $timecreated = time();
  5872. $token = md5($timecreated);
  5873. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5874. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5875. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5876. $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)
  5877. }
  5878. $html = "
  5879. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5880. <table border='1'>
  5881. <tr><td>
  5882. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5883. <!-- iLM calls : end -->
  5884. </td></tr>
  5885. </table>
  5886. <table>
  5887. <tr>
  5888. <td align='center'>
  5889. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5890. </td></tr>
  5891. </table>
  5892. </form>\n";
  5893. print $javascript . $html;
  5894. print $OUTPUT->box_end();
  5895. //NAO echo format_string($html); // Moodle 3.X
  5896. die();
  5897. } // function preview_ilm($courseid, $iassign_ilm)
  5898. //r_ function preview_ilm ($iassign_ilm)
  5899. //r_ /// Function for preview iassign file from iassign filter.
  5900. //r_ function preview_ilm() {
  5901. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5902. //r_ $tag_filter = $this->tag_ilm($fileid);
  5903. //r_ $javascript = "<script type='text/javascript'>
  5904. //r_ //<![CDATA[
  5905. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5906. //r_ //]]>
  5907. //r_ </script>";
  5908. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5909. //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>
  5910. //r_ </table></form></body></html>";
  5911. //r_ echo $javascript . format_text($html);
  5912. //r_ die;
  5913. //r_ }
  5914. /// Function for export an package (zip) of iassign files
  5915. function export_files_ilm () {
  5916. global $CFG;
  5917. $context = context_course::instance($this->id);
  5918. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5919. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5920. $zip = new zip_archive();
  5921. $zip->open($zip_filename);
  5922. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5923. foreach ($files_id as $file_id) {
  5924. $file = $fs->get_file_by_id($file_id);
  5925. if (!$file->is_directory())
  5926. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5927. else {
  5928. $zip->add_directory($file->get_filepath());
  5929. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5930. foreach ($files_zip as $value) {
  5931. if (!$value->is_directory())
  5932. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5933. else
  5934. $zip->add_directory($value->get_filepath());
  5935. }
  5936. }
  5937. }
  5938. $zip->close();
  5939. header("Pragma: public");
  5940. header("Expires: 0");
  5941. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5942. header("Cache-Control: private", false);
  5943. header("Content-Type: application/zip");
  5944. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5945. header("Content-Transfer-Encoding: binary");
  5946. header("Content-Length: " . @filesize($zip_filename));
  5947. set_time_limit(0);
  5948. @readfile("$zip_filename") || die("File not found.");
  5949. unlink($zip_filename);
  5950. exit;
  5951. }
  5952. /// Function of execute a command in button editor tinymce
  5953. // @param int $fileid Id of file
  5954. function tinymce_ilm ($fileid) {
  5955. $tag_filter = $this->tag_ilm($fileid);
  5956. $output = "<script type='text/javascript'>
  5957. //<![CDATA[
  5958. var tag_filter = '$tag_filter';
  5959. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5960. // all right, insert it
  5961. } else {
  5962. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5963. }
  5964. // window.close();
  5965. //]]>
  5966. </script>\n";
  5967. print $output;
  5968. die();
  5969. }
  5970. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5971. /// Function to add content to the Editor Window
  5972. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5973. // @param int $fileid Id of file
  5974. function editor_ilm ($fileid, $editor) {
  5975. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5976. $output1 = "<script type='text/javascript'>
  5977. //<![CDATA[
  5978. var tag_filter = '$tag_filter';\n";
  5979. if ($editor == 'atto') {
  5980. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5981. } elseif ($editor == 'tinyMCE') {
  5982. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5983. } else
  5984. $output2 = "";
  5985. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5986. window.close();
  5987. //]]>
  5988. </script>\n";
  5989. //D var_dump($output);
  5990. print $output1 . $output2 . $output3;
  5991. die();
  5992. }
  5993. /// Function to add content to the Atto Editor Window
  5994. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5995. // @param int $fileid Id of file
  5996. function atto_ilm ($fileid) {
  5997. global $CFG, $DB;
  5998. $tag_filter = $this->tag_ilm($fileid);
  5999. $output = "<script type='text/javascript'>
  6000. //<![CDATA[
  6001. var tag_filter = '$tag_filter';
  6002. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6003. // all right, insert iLM tag to this editor
  6004. } else {
  6005. // error trying to insert
  6006. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6007. }
  6008. //window.close();
  6009. //]]>
  6010. </script>\n";
  6011. print $output;
  6012. die();
  6013. }
  6014. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6015. // @param string $key Key for return information
  6016. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6017. function get_dir_ilm ($key) {
  6018. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6019. $context = context_course::instance($this->id);
  6020. $dirid = optional_param('dirid', 0, PARAM_INT);
  6021. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6022. if ($dirid == 0) {
  6023. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6024. $dirid = $dir->get_id();
  6025. }
  6026. else {
  6027. $dir = $fs->get_file_by_id($dirid);
  6028. $dir_base = $dir->get_filepath();
  6029. }
  6030. $dir_parent = $dir->get_parent_directory();
  6031. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6032. return $data[$key];
  6033. }
  6034. /// Function for create an new dir
  6035. function new_dir_ilm () {
  6036. global $USER;
  6037. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6038. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6039. $dir_base = $this->get_dir_ilm('dir_base');
  6040. $context = context_course::instance($this->id);
  6041. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6042. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6043. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6044. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6045. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6046. }
  6047. /// Function for delete an dir
  6048. function delete_dir_ilm () { //
  6049. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6050. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6051. $context = context_course::instance($this->id);
  6052. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6053. $dir_parent = $this->get_dir_ilm('dir_parent');
  6054. if ($dir) {
  6055. if ($dir->is_directory()) {
  6056. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6057. foreach ($files_delete as $value)
  6058. $value->delete();
  6059. $dir->delete();
  6060. }
  6061. }
  6062. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6063. die();
  6064. }
  6065. /// Function for rename an dir
  6066. function rename_dir_ilm () {
  6067. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6068. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6069. $context = context_course::instance($this->id);
  6070. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6071. $dir_parent = $this->get_dir_ilm('dir_parent');
  6072. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6073. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6074. if ($dir->is_directory()) {
  6075. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6076. foreach ($files_rename_path as $value)
  6077. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6078. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6079. }
  6080. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6081. die();
  6082. }
  6083. /// Function for move an dir and your content for other dir
  6084. function selected_move_ilm () {
  6085. global $PAGE, $OUTPUT, $CFG;
  6086. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6087. $context = context_course::instance($this->id);
  6088. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6089. $dirid = $this->get_dir_ilm('dirid');
  6090. $dir_base = $this->get_dir_ilm('dir_base');
  6091. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6092. $code_javascript_ilm = "
  6093. <script type='text/javascript'>
  6094. //<![CDATA[
  6095. function getRadiobutton () {
  6096. var radioButtons = document.getElementsByTagName('input');
  6097. var param = '';
  6098. for (var counter=0; counter < radioButtons.length; counter++) {
  6099. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6100. param = radioButtons[counter].value;
  6101. }
  6102. return param;
  6103. }
  6104. function move_selected_ilm () {
  6105. var msgAnswer;
  6106. if (getRadiobutton() != '') {
  6107. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6108. if (msgAnswer)
  6109. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6110. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6111. }
  6112. else
  6113. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6114. }
  6115. function cancel_selected_ilm () {
  6116. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6117. }
  6118. //]]>
  6119. </script>\n";
  6120. $title = get_string('move_files', 'iassign');
  6121. $PAGE->set_title($title);
  6122. $PAGE->set_pagelayout('base');
  6123. print $OUTPUT->header();
  6124. print $OUTPUT->heading($title);
  6125. $dir_paths = array();
  6126. print $OUTPUT->box_start();
  6127. print "<center>";
  6128. foreach ($files_id as $file_id) {
  6129. $file = $fs->get_file_by_id($file_id);
  6130. if ($file) {
  6131. if (!$file->is_directory())
  6132. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6133. else {
  6134. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6135. array_push($dir_paths, $file->get_filepath());
  6136. }
  6137. }
  6138. }
  6139. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6140. if ($dir_base != '/') {
  6141. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6142. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6143. }
  6144. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6145. foreach ($files_tree as $file) {
  6146. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6147. $is_parent = false;
  6148. foreach ($dir_paths as $dir) {
  6149. $path = explode("/", $dir);
  6150. array_pop($path);
  6151. $path[count($path) - 1] = '';
  6152. $path = implode("/", $path);
  6153. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6154. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6155. }
  6156. if ($is_parent == false) {
  6157. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6158. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6159. }
  6160. }
  6161. }
  6162. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6163. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6164. print "</center>";
  6165. print $OUTPUT->box_end();
  6166. print $OUTPUT->footer();
  6167. print $code_javascript_ilm;
  6168. die;
  6169. }
  6170. /// Function for move files for an dir
  6171. function move_files_ilm () {
  6172. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6173. $context = context_course::instance($this->id);
  6174. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6175. $dirid = $this->get_dir_ilm('dirid');
  6176. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6177. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6178. foreach ($files_id as $file_id) {
  6179. $file = $fs->get_file_by_id($file_id);
  6180. if ($file) {
  6181. if ($file->is_directory()) {
  6182. $pathname = explode("/", $file->get_filepath());
  6183. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6184. foreach ($files_move_path as $value) {
  6185. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6186. $value->rename($path_move, $value->get_filename());
  6187. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6188. }
  6189. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6190. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6191. $file->rename($path_move, $file->get_filename());
  6192. } else {
  6193. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6194. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6195. }
  6196. }
  6197. }
  6198. //die;
  6199. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6200. die();
  6201. } // function move_files_ilm()
  6202. /// Function for recover files in use on all activities of a course
  6203. function recover_files_ilm () {
  6204. global $DB, $USER;
  6205. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6206. $courseid = optional_param('id', NULL, PARAM_INT);
  6207. $dirid = $this->get_dir_ilm('dirid');
  6208. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6209. $contextfile = context_course::instance($this->id);
  6210. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6211. foreach ($iassigns as $iassign) {
  6212. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6213. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6214. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6215. $context = context_module::instance($cm->id);
  6216. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6217. if ($files) {
  6218. foreach ($files as $value) {
  6219. $extension = explode(".", $value->get_filename());
  6220. if (!$value->is_directory()) {
  6221. $fileinfo = array('contextid' => $contextfile->id,
  6222. 'component' => 'mod_iassign',
  6223. 'filearea' => 'activity',
  6224. 'itemid' => 0,
  6225. 'filepath' => $this->get_dir_ilm('dir_base'),
  6226. 'userid' => $USER->id,
  6227. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6228. 'license' => 'allrightsreserved',
  6229. 'timecreated' => time(),
  6230. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6231. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6232. }
  6233. }
  6234. } // if ($files)
  6235. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6236. } // foreach ($iassigns as $iassign)
  6237. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6238. die();
  6239. } // function recover_files_ilm()
  6240. /// Auxiliary function the get all files in a given context
  6241. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6242. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6243. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6244. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6245. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6246. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6247. // (NAO s_iassign_statement.file = s_files.id)
  6248. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6249. $dir_base = $this->get_dir_ilm('dir_base');
  6250. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6251. $countf = 0;
  6252. $array_files_id = array(); // all files from this context
  6253. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6254. //$filename = $item_fc->get_filename();
  6255. //$filepath = $item_fc->get_filepath();
  6256. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6257. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6258. // $array_files_aux[] = $item_fc;
  6259. $itemid = $item_fc->get_id();
  6260. if (!in_array($itemid, $array_files_id)) {
  6261. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6262. if ($fileuserid == $userid)
  6263. $filesfrommine[] = $item_fc;
  6264. else
  6265. $filesfromothers[] = $item_fc;
  6266. $array_files_id[] = $itemid;
  6267. $countf++;
  6268. }
  6269. }
  6270. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6271. return $countf;
  6272. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6273. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6274. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6275. function get_all_ilm_files_by_fileid ($fileid) {
  6276. global $DB, $USER;
  6277. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6278. //TODO Criar coluna 'authorid'
  6279. $str_query = "SELECT * FROM {iassign_statement} " .
  6280. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6281. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6282. return $array_iassign_ilm;
  6283. }
  6284. //NN
  6285. //NN
  6286. // Build string with JavaScript code with function to edit/remove/double iLM files
  6287. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6288. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6289. global $CFG;
  6290. $error_files_exists = get_string('error_file_exists', 'iassign');
  6291. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6292. $code_javascript_ilm = "
  6293. <script type='text/javascript'>
  6294. //<![CDATA[
  6295. function preview_ilm (fileid, ilmid) { //JavaScript function
  6296. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6297. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6298. }
  6299. function update_ilm (ilmid, fileid) { //JavaScript function
  6300. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6301. }
  6302. function delete_ilm (ilmid, fileid) { //JavaScript function
  6303. var msgAnswer;
  6304. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6305. if (msgAnswer) {
  6306. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6307. }
  6308. }
  6309. function delete_selected_ilm () { //JavaScript function
  6310. var msgAnswer;
  6311. var param = getCheckbox();
  6312. if (param.join() != '') {
  6313. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6314. if (msgAnswer)
  6315. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6316. }
  6317. else
  6318. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6319. }
  6320. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6321. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6322. }
  6323. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6324. var filenamecopy;
  6325. var i;
  6326. var files = new Array(" . $files_array . ");
  6327. do {
  6328. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6329. } while (filenamecopy == '');
  6330. if (filenamecopy == null)
  6331. return false;\n
  6332. else {
  6333. for (i=0;i<files.length;i++) {
  6334. if (files[i]==filenamecopy) {
  6335. alert('" . $error_files_exists . "');
  6336. return false;\n
  6337. }
  6338. }\n" .
  6339. // @see: function 'duplicate_file_ilm()' above
  6340. "
  6341. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6342. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6343. } // else
  6344. }
  6345. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6346. var filenamecopy;
  6347. var i;
  6348. var files = new Array($files_array);
  6349. do {
  6350. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6351. } while (filenamecopy == '');
  6352. if (filenamecopy == null)
  6353. return false;
  6354. else {
  6355. for (i=0;i<files.length;i++) {
  6356. if (files[i]==filenamecopy) {
  6357. alert('" . $error_files_exists . "');
  6358. return false;
  6359. }
  6360. }
  6361. 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;
  6362. }
  6363. }
  6364. function export_files_ilm () { //JavaScript function
  6365. var param = getCheckbox();
  6366. if (param.join() != '')
  6367. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6368. else
  6369. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6370. }
  6371. function select_all_ilm () { //JavaScript function
  6372. var checkBoxes = document.getElementsByTagName('input');
  6373. var selectAll = document.getElementById('select_all');
  6374. for (var counter=0; counter < checkBoxes.length; counter++) {
  6375. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6376. checkBoxes[counter].checked = selectAll.checked;
  6377. }
  6378. }
  6379. function getCheckbox () { //JavaScript function
  6380. var checkBoxes = document.getElementsByTagName('input');
  6381. var param = new Array();
  6382. for (var counter=0; counter < checkBoxes.length; counter++) {
  6383. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6384. param.push(checkBoxes[counter].value);
  6385. }
  6386. return param;
  6387. }
  6388. function new_dir_ilm () { //JavaScript function
  6389. var dirname = '';
  6390. var i;
  6391. var dirs = new Array(" . $dirs_array . ");
  6392. do {
  6393. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6394. } while (dirname == '');
  6395. if (dirname == null)
  6396. return false;\n
  6397. else {
  6398. for (i=0;i<dirs.length;i++) {
  6399. if (dirs[i]==dirname) {
  6400. alert('" . $error_dir_exists . "');
  6401. return false;\n
  6402. }
  6403. }
  6404. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6405. }
  6406. }
  6407. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6408. var msgAnswer;
  6409. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6410. if (msgAnswer) {
  6411. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6412. }
  6413. }
  6414. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6415. var dirnamecopy;
  6416. var i;
  6417. var dirs = new Array($dirs_array);
  6418. do {
  6419. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6420. } while (dirnamecopy == '');
  6421. if (dirnamecopy == null)
  6422. return false;\n
  6423. else {
  6424. for (i=0;i<dirs.length;i++) {
  6425. if (dirs[i]==dirnamecopy) {
  6426. alert('" . $error_dir_exists . "');
  6427. return false;\n
  6428. }
  6429. }
  6430. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6431. }
  6432. }
  6433. function move_selected_ilm (ilmid) { //JavaScript function
  6434. var param = getCheckbox();
  6435. if (param.join() != '')
  6436. 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();
  6437. else
  6438. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6439. }
  6440. function recover_files_ilm () { //JavaScript function
  6441. var msgAnswer;
  6442. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6443. if (msgAnswer) {
  6444. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6445. }
  6446. }
  6447. window.onload = function() { //JavaScript function
  6448. var xPosition = 0;
  6449. var yPosition = 0;
  6450. element=document.getElementById('new_file');
  6451. while(element) {
  6452. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6453. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6454. element = element.offsetParent;
  6455. }
  6456. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6457. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6458. location.hash = '#new_file';
  6459. };
  6460. //]]>
  6461. </script>\n"; // end of $code_javascript_ilm
  6462. return $code_javascript_ilm;
  6463. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6464. /// List iassign files from course directory
  6465. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6466. function view_files_ilm ($iassign_ilm_class, $extension) {
  6467. global $CFG, $DB, $USER, $OUTPUT;
  6468. $fs = get_file_storage();
  6469. $context = context_course::instance($this->id);
  6470. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6471. $dirid = $this->get_dir_ilm('dirid');
  6472. $dir_base = $this->get_dir_ilm('dir_base');
  6473. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6474. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6475. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6476. $files_array = '';
  6477. foreach ($files_course as $value) {
  6478. if (!$value->is_directory())
  6479. $files_array .= "'" . $value->get_filename() . "',";
  6480. }
  6481. $files_array .= "''";
  6482. $error_files_exists = get_string('error_file_exists', 'iassign');
  6483. $dirs_array = '';
  6484. foreach ($files_course as $value) {
  6485. if ($value->is_directory()) {
  6486. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6487. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6488. }
  6489. }
  6490. $dirs_array .= "''";
  6491. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6492. // TODO Rever o preview pois só deixar ver uma vez.
  6493. $code_javascript_ilm = "
  6494. <script type='text/javascript'>
  6495. //<![CDATA[
  6496. function preview_ilm (fileid, ilmid) {
  6497. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6498. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6499. }
  6500. function update_ilm (ilmid, fileid) {
  6501. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6502. }
  6503. function delete_ilm (ilmid, fileid) {
  6504. var msgAnswer;
  6505. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6506. if (msgAnswer) {
  6507. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6508. }
  6509. }
  6510. function delete_selected_ilm () {
  6511. var msgAnswer;
  6512. var param = getCheckbox();
  6513. if (param.join() != '') {
  6514. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6515. if (msgAnswer)
  6516. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6517. }
  6518. else
  6519. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6520. }
  6521. function add_ilm_iassign (ilmid, filename, fileid) {
  6522. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6523. }
  6524. function duplicate_ilm (ilmid, filename, fileid) {
  6525. var filenamecopy;
  6526. var i;
  6527. var files = new Array($files_array);
  6528. do {
  6529. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6530. } while (filenamecopy == '');
  6531. if (filenamecopy == null)
  6532. return false;\n
  6533. else {
  6534. for (i=0;i<files.length;i++) {
  6535. if (files[i]==filenamecopy) {
  6536. alert('$error_files_exists');
  6537. return false;\n
  6538. }
  6539. }\n" .
  6540. // @see: function 'duplicate_file_ilm()' above
  6541. "
  6542. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6543. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6544. } // else
  6545. }
  6546. function rename_ilm (ilmid, filename, fileid) {
  6547. var filenamecopy;
  6548. var i;
  6549. var files = new Array($files_array);
  6550. do {
  6551. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6552. } while (filenamecopy == '');
  6553. if (filenamecopy == null)
  6554. return false;
  6555. else {
  6556. for (i=0;i<files.length;i++) {
  6557. if (files[i]==filenamecopy) {
  6558. alert('$error_files_exists');
  6559. return false;
  6560. }
  6561. }
  6562. 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;
  6563. }
  6564. }
  6565. function export_files_ilm () {
  6566. var param = getCheckbox();
  6567. if (param.join() != '')
  6568. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6569. else
  6570. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6571. }
  6572. function select_all_ilm () {
  6573. var checkBoxes = document.getElementsByTagName('input');
  6574. var selectAll = document.getElementById('select_all');
  6575. for (var counter=0; counter < checkBoxes.length; counter++) {
  6576. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6577. checkBoxes[counter].checked = selectAll.checked;
  6578. }
  6579. }
  6580. function getCheckbox () {
  6581. var checkBoxes = document.getElementsByTagName('input');
  6582. var param = new Array();
  6583. for (var counter=0; counter < checkBoxes.length; counter++) {
  6584. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6585. param.push(checkBoxes[counter].value);
  6586. }
  6587. return param;
  6588. }
  6589. function new_dir_ilm () {
  6590. var dirname = '';
  6591. var i;
  6592. var dirs = new Array($dirs_array);
  6593. do {
  6594. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6595. } while (dirname == '');
  6596. if (dirname == null)
  6597. return false;\n
  6598. else {
  6599. for (i=0;i<dirs.length;i++) {
  6600. if (dirs[i]==dirname) {
  6601. alert('$error_dir_exists');
  6602. return false;\n
  6603. }
  6604. }
  6605. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6606. }
  6607. }
  6608. function delete_dir_ilm (ilmid, dirid) {
  6609. var msgAnswer;
  6610. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6611. if (msgAnswer) {
  6612. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6613. }
  6614. }
  6615. function rename_dir_ilm (ilmid, dirname, dirid) {
  6616. var dirnamecopy;
  6617. var i;
  6618. var dirs = new Array($dirs_array);
  6619. do {
  6620. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6621. } while (dirnamecopy == '');
  6622. if (dirnamecopy == null)
  6623. return false;\n
  6624. else {
  6625. for (i=0;i<dirs.length;i++) {
  6626. if (dirs[i]==dirnamecopy) {
  6627. alert('$error_dir_exists');
  6628. return false;\n
  6629. }
  6630. }
  6631. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6632. }
  6633. }
  6634. function move_selected_ilm (ilmid) {
  6635. var param = getCheckbox();
  6636. if (param.join() != '')
  6637. 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();
  6638. else
  6639. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6640. }
  6641. function recover_files_ilm () {
  6642. var msgAnswer;
  6643. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6644. if (msgAnswer) {
  6645. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6646. }
  6647. }
  6648. window.onload = function() {
  6649. var xPosition = 0;
  6650. var yPosition = 0;
  6651. element=document.getElementById('new_file');
  6652. while(element) {
  6653. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6654. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6655. element = element.offsetParent;
  6656. }
  6657. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6658. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6659. location.hash = '#new_file';
  6660. };
  6661. //]]>
  6662. </script>\n";
  6663. $output = "";
  6664. $select_all = "";
  6665. $count_files = 0;
  6666. $extensions_allow = array();
  6667. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6668. foreach ($iassign_ilm as $item_iassign_ilm)
  6669. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6670. foreach ($files_course as $value) {
  6671. $filename = $value->get_filename();
  6672. $filepath = $value->get_filepath();
  6673. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6674. $pathname = $pathname[count($pathname) - 1];
  6675. $fileid = $value->get_id();
  6676. $tmp = explode(".", $filename);
  6677. if (count($tmp)>1) // avoid error if the file has no extension
  6678. $filetype = $tmp[1];
  6679. else // probably error...
  6680. $filetype = '';
  6681. $author = $value->get_author();
  6682. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6683. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6684. $extensions = explode(",", $extension);
  6685. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6686. $count_files ++;
  6687. // buscar fileid nas tabelas do iassign
  6688. $list_filein_use = "";
  6689. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6690. if ($iassign_statement_activity_list) {
  6691. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6692. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6693. }
  6694. }
  6695. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6696. if (!$iassign_ilm) {
  6697. $iassign_ilm = new stdClass();
  6698. $iassign_ilm->id = $ilmid;
  6699. }
  6700. // Do not use $var inside "..." - problem with some "unusual" operational system
  6701. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6702. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6703. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6704. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6705. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6706. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6707. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6708. $check_select = "";
  6709. $link_rename = "";
  6710. $link_delete = "";
  6711. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6712. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6713. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6714. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6715. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6716. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6717. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6718. if ($value->get_userid() == $USER->id) {
  6719. if ($iassign_statement_activity_list) {
  6720. $check_select = "";
  6721. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6722. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6723. $link_rename = "";
  6724. } else {
  6725. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6726. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6727. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6728. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6729. }
  6730. }
  6731. if (!in_array($filetype, $extensions_allow)) {
  6732. $link_edit = "";
  6733. $link_add_ilm_iassign = "";
  6734. $link_add_ilm_tinymce = "";
  6735. $link_add_ilm_atto = "";
  6736. $link_filter = "";
  6737. }
  6738. if ($value->is_directory()) {
  6739. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6740. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6741. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6742. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6743. <td><center>$author</center></td>
  6744. <td><center>$timecreated</center></td>
  6745. <td><center>$timemodified</center></td></tr>\n";
  6746. }
  6747. else if ($this->from == 'iassign') {
  6748. $new_id = "";
  6749. $new_class = "";
  6750. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6751. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6752. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6753. }
  6754. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6755. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6756. <td><center>$author</center></td>
  6757. <td><center>$timecreated</center></td>
  6758. <td><center>$timemodified</center></td></tr>\n";
  6759. }
  6760. else if ($this->from == 'block') {
  6761. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6762. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6763. <td><center>$author</center></td>
  6764. <td><center>$timecreated</center></td>
  6765. <td><center>$timemodified</center></td></tr>\n";
  6766. }
  6767. else if ($this->from == 'tinymce') {
  6768. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6769. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6770. <td><center>$author</center></td>
  6771. <td><center>$timecreated</center></td>
  6772. <td><center>$timemodified</center></td></tr>\n";
  6773. }
  6774. else if ($this->from == 'atto') {
  6775. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6776. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6777. <td><center>$author</center></td>
  6778. <td><center>$timecreated</center></td>
  6779. <td><center>$timemodified</center></td></tr>\n";
  6780. }
  6781. }
  6782. }
  6783. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6784. $dir_base = "";
  6785. $header = "";
  6786. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6787. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6788. foreach ($basename as $value) {
  6789. $dir_base .= $value . "/";
  6790. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6791. if ($dir_id) {
  6792. if ($value == "") {
  6793. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6794. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6795. } else {
  6796. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6797. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6798. }
  6799. }
  6800. } // foreach ($basename as $value)
  6801. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6802. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6803. $html .= "
  6804. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6805. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6806. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6807. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6808. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6809. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6810. </table>\n";
  6811. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6812. $html .= "<table width='100%'><tr>\n";
  6813. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6814. if ($count_files != 0) {
  6815. $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";
  6816. $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";
  6817. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6818. }
  6819. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6820. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6821. $html .= "</form>\n";
  6822. print $code_javascript_ilm;
  6823. print $html;
  6824. } // function view_files_ilm($extension)
  6825. } // class ilm_manager
  6826. /// Class to insert of icons
  6827. class iassign_icons {
  6828. static function insert ($icon) {
  6829. global $CFG;
  6830. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6831. return $string;
  6832. }
  6833. }
  6834. /// Class with util functions for plugin manage
  6835. class iassign_utils {
  6836. /// Function to return the filename extension
  6837. // @param string The $filename as an string
  6838. // @return string Return an string (last group after '.')
  6839. static function filename_extension ($filename) {
  6840. if ($filename == null || $filename == '') {
  6841. return null;
  6842. }
  6843. $itens = explode('.', $filename);
  6844. $num = count($itens);
  6845. if ($num < 2) {
  6846. return null;
  6847. }
  6848. return $itens[$num - 1];
  6849. }
  6850. /// Use the PHP class/package ZipArchive to create a Zip file
  6851. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6852. // 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
  6853. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6854. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6855. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6856. $zip = new zip_archive(); //2
  6857. $res = $zip->open($full_path_zip_filename);
  6858. $total_vet = count($vet_student_filename);
  6859. for ($ii=0; $ii<$total_vet; $ii++) {
  6860. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6861. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6862. }
  6863. $ret = $zip->close();
  6864. iassign_utils::download_file($full_path_zip_filename);
  6865. $filenameZip = $zip->filename;
  6866. return array($ret, $zip);
  6867. }
  6868. static function download_file ($zip_filename) {
  6869. header("Pragma: public");
  6870. header("Expires: 0");
  6871. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6872. header("Cache-Control: private", false);
  6873. header("Content-Type: application/zip");
  6874. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6875. header("Content-Transfer-Encoding: binary");
  6876. header("Content-Length: " . @filesize($zip_filename));
  6877. set_time_limit(0);
  6878. @readfile("$zip_filename") || die("File not found.");
  6879. unlink($zip_filename);
  6880. }
  6881. /// Function for format filename remove special caracters
  6882. // @param string $text String for clean
  6883. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6884. // @return string Return an string in clean format
  6885. static function format_filename ($text) {
  6886. if ($text != '.') {
  6887. //D $text = htmlspecialchars(urldecode($text));
  6888. //D echo "locallib.php: format_filename: $text<br/>";
  6889. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6890. $text = json_decode($text)->{current_language()};
  6891. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6892. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  6893. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6894. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6895. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  6896. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6897. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6898. // E.g. text = "exerc_midpoint.course.geo"
  6899. // 0123456789012345678901234
  6900. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6901. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6902. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6903. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6904. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6905. //$ext = strrpos($text, ".");
  6906. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6907. //$text = str_replace($array1, $array2, $text);
  6908. }
  6909. return $text;
  6910. }
  6911. /// Function to filter characters to the file name to iLM content
  6912. // @param string $text String for clean
  6913. // @param string $ext String ot the extension of the iLM
  6914. // @return string Return an string in clean format
  6915. static function filter_filename_extension ($filename, $ext) {
  6916. if ($filename != '.') {
  6917. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6918. $arrTo = array("_","","","","","","","","","","","","");
  6919. $filename = str_replace($arrFrom, $arrTo, $filename);
  6920. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6921. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6922. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6923. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6924. $index_lastposition = strlen($filenameF);
  6925. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6926. $text = str_replace(".", "_", $text); // erase all other "."
  6927. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6928. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6929. }
  6930. else
  6931. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6932. return $filenameF;
  6933. }
  6934. /// Function for format pathname remove special caracters
  6935. // @param string $text String for clean
  6936. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6937. // @return string Return an string in clean format
  6938. static function format_pathname ($text, $is_lowercase = true) {
  6939. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6940. $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", "-", "_", "", "", "");
  6941. $text = str_replace($array1, $array2, $text);
  6942. if ($is_lowercase)
  6943. $text = strtolower($text);
  6944. return $text;
  6945. }
  6946. /// Function for format file name from iLM original name
  6947. // @param string $text String to build the file neam
  6948. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6949. // @return string Return an string in clean format
  6950. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6951. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6952. $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", "-", "_", "", "", "");
  6953. $index_firstposition_blank = strpos($ilm_name, " ");
  6954. if ($index_firstposition_blank) { // truncate the name!
  6955. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6956. }
  6957. $index_firstposition_dots = strpos($ilm_name, ":");
  6958. if ($index_firstposition_dots) { // truncate the name!
  6959. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6960. }
  6961. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6962. if ($is_lowercase)
  6963. $namefiltered = strtolower($namefiltered);
  6964. return $namefiltered;
  6965. }
  6966. /// Function for insert version in the filename
  6967. // @param string $filename Name of file
  6968. // @return string Return the filename with version
  6969. static function version_filename ($filename) {
  6970. $array_filename = explode('.', $filename);
  6971. if (count($array_filename) > 1)
  6972. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6973. else
  6974. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6975. return $filename;
  6976. }
  6977. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6978. static function remove_code_message ($string) {
  6979. $array = explode("&lt;ia_uc&gt;", $string);
  6980. return $array[0];
  6981. }
  6982. }
  6983. // class iassign_utils
  6984. /// Class with language functions for plugin manage
  6985. class iassign_language {
  6986. /// Function for return text in language or get default language (en)
  6987. // @param string $lang Code of language
  6988. // @param string $description JSON text content all languages
  6989. // @return string Return an string in the language selected
  6990. static function get_description_lang ($lang, $descriptions) {
  6991. $description_lang = "";
  6992. $description = json_decode($descriptions);
  6993. if ($description == null) {
  6994. $description_lang = $descriptions;
  6995. }
  6996. else {
  6997. if (isset($description->{$lang}))
  6998. $description_lang = $description->{$lang};
  6999. else
  7000. if (isset($description->en)) //MOOC2014
  7001. $description_lang = $description->en;
  7002. else //MOOC2014
  7003. $description_lang = "en"; //MOOC2014
  7004. }
  7005. return $description_lang;
  7006. }
  7007. /// Function for return all language supported by iLM
  7008. // @param string $descriptions JSON text content all languages
  7009. // @return string Return as string with all languages
  7010. static function get_all_lang ($descriptions) {
  7011. $langs = "";
  7012. $description = json_decode($descriptions);
  7013. if ($description) {
  7014. foreach ($description as $key => $value) {
  7015. $langs .= $key . " ; ";
  7016. }
  7017. $langs = substr($langs, 0, strlen($langs) - 3);
  7018. }
  7019. return $langs;
  7020. }
  7021. /// Function for convert json in xml //MOOC2014
  7022. // @param string $json JSON text
  7023. // @return string Return as string with xml tags
  7024. static function json_to_xml ($json) {
  7025. $xml = "";
  7026. $json = json_decode($json);
  7027. foreach ($json as $key => $value) {
  7028. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7029. }
  7030. return $xml;
  7031. }
  7032. }
  7033. // class iassign_language
  7034. /// Class with log functions for plugin manage.
  7035. class iassign_log {
  7036. /// Function for insert log event
  7037. // @param string $action Code action of event
  7038. // @param string $information Text for describe action of event
  7039. // @param int $cmid Id of context module
  7040. // @param int $ilmid Id of iLM
  7041. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7042. global $COURSE, $CFG, $USER, $DB;
  7043. $newentry = new stdClass();
  7044. $newentry->time = time();
  7045. $newentry->userid = $USER->id;
  7046. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7047. $newentry->course = $COURSE->id;
  7048. $newentry->cmid = $cmid;
  7049. $newentry->ilmid = $ilmid;
  7050. $newentry->action = $action;
  7051. $newentry->info = $information;
  7052. $newentry->language = current_language();
  7053. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7054. if (ini_get("browscap") && function_exists('get_browse')) {
  7055. $browser = get_browse(null, true);
  7056. $newentry->javascript = $browser['javascript'];
  7057. $newentry->java = $browser['javaapplets'];
  7058. }
  7059. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7060. print_error('error_add_log', 'iassign');
  7061. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7062. } // class iassign_log