locallib.php 385 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259
  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 = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  359. $json_obj = new stdclass();
  360. $json_obj->submissions = [];
  361. $csvfields = [];
  362. $csvfields[] = 'submissionid';
  363. $csvfields[] = 'file';
  364. $csvfields[] = 'filesize';
  365. $csvfields[] = 'timestamp';
  366. $csvfields[] = 'humandate';
  367. $csvfields[] = 'grade';
  368. $csvfields[] = 'userid';
  369. $csvfields[] = 'exerciseid';
  370. $json_obj->submissions[] = $csvfields;
  371. $exercise_dir = [];
  372. $exercises_list = [];
  373. foreach ($list as $item) {
  374. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  375. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  376. $exercises_list[] = $temp;
  377. $exercise_dir[] = $temp->id;
  378. }
  379. }
  380. $student_dir = [];
  381. $students_list = [];
  382. foreach ($list as $item) {
  383. if (!in_array($item->userid, $student_dir)) {
  384. $temp = $DB->get_record("user", array("id" => $item->userid));
  385. $students_list[] = $temp;
  386. $student_dir[] = $temp->id;
  387. }
  388. }
  389. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  391. $zip = new zip_archive(); // create ZIP
  392. $zip->open($zip_filename);
  393. foreach ($exercises_list as $exercise) {
  394. $dir_ex = iassign_utils::format_filename($exercise->name);
  395. $zip->add_directory($dir_ex);
  396. $extension_ilm = '';
  397. foreach ($ilm_list as $ilm) {
  398. if ($exercise->iassign_ilmid == $ilm->id) {
  399. $extension_ilm = $ilm->extension;
  400. break;
  401. }
  402. }
  403. foreach ($students_list as $student) {
  404. $individual_dir =
  405. $dir_ex . DIRECTORY_SEPARATOR .
  406. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  407. $zip->add_directory($individual_dir);
  408. $i = 1;
  409. foreach($list as $item) {
  410. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  411. $date = new DateTime();
  412. $date->setTimestamp($item->timecreated);
  413. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s') . '.' . $extension_ilm);
  414. $zip->add_file_from_string($new_file, $item->answer);
  415. $temp_json = [];
  416. $temp_json[] = intval($item->id);
  417. $temp_json[] = $new_file;
  418. $temp_json[] = strlen($new_file);
  419. $temp_json[] = intval($item->timecreated);
  420. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  421. $temp_json[] = doubleval($item->grade);
  422. $temp_json[] = intval($item->userid);
  423. $temp_json[] = intval($exercise->id);
  424. $json_obj->submissions[] = $temp_json;
  425. }
  426. }
  427. }
  428. }
  429. $csv_str = "";
  430. foreach($json_obj->submissions as $sub) {
  431. $csv_str .= $this->csvstr($sub) . "\n";
  432. }
  433. $zip->add_file_from_string('index.csv', $csv_str);
  434. $zip->close();
  435. iassign_utils::download_file($zip_filename);
  436. exit;
  437. }
  438. function csvstr(array $fields) : string {
  439. $f = fopen('php://memory', 'r+');
  440. if (fputcsv($f, $fields) === false) {
  441. return false;
  442. }
  443. rewind($f);
  444. $csv_line = stream_get_contents($f);
  445. return rtrim($csv_line);
  446. }
  447. /// Download submissions from table iassign_allsubmissions
  448. function download_submissions () {
  449. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  450. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  451. exit;
  452. $type = optional_param('type', NULL, PARAM_TEXT);
  453. $item = optional_param('item', NULL, PARAM_TEXT);
  454. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  455. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  456. $sub_list = [];
  457. if ($type == 'individual') {
  458. $sub_list[] = $DB->get_record(
  459. 'iassign_allsubmissions', array('id' => $item));
  460. } elseif ($type == 'student') {
  461. $sub_list = $DB->get_records(
  462. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  463. } elseif ($type == 'exercise') {
  464. $sub_list = $DB->get_records(
  465. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  466. } elseif ($type == 'block') {
  467. $exercises_in_block = $DB->get_records(
  468. 'iassign_statement', array('iassignid' => $iassign_id));
  469. foreach ($exercises_in_block as $exercise) {
  470. $temp = $DB->get_records(
  471. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  472. $sub_list = array_merge($sub_list, $temp);
  473. }
  474. }
  475. $this->download_submissions_help($sub_list);
  476. }
  477. /// Delete submissions in table iassign_allsubmissions
  478. function delete_submissions () {
  479. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  480. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  481. exit;
  482. $type = optional_param('type', NULL, PARAM_TEXT);
  483. $item = optional_param('item', NULL, PARAM_TEXT);
  484. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  485. if ($type == 'individual') {
  486. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  487. } elseif ($type == 'student') {
  488. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  489. } elseif ($type == 'exercise') {
  490. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  491. }
  492. }
  493. function get_individual_submission () {
  494. global $DB, $USER;
  495. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  496. exit;
  497. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  498. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  499. print $submission->answer;
  500. }
  501. /// Open individual submission
  502. function open_individual_submission () {
  503. global $DB, $USER, $CFG;
  504. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  505. exit;
  506. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  507. $id = $this->cm->id;
  508. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  509. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  510. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  511. //print_r($atual_submission);
  512. $all_submissions = $DB->get_records('iassign_allsubmissions',
  513. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  514. $previous = null;
  515. $next = null;
  516. $i = 0;
  517. $found = false;
  518. foreach($all_submissions as $individual) {
  519. if (!$found && $individual->id != $submissionid) {
  520. $previous = $individual;
  521. }
  522. if ($found) {
  523. $next = $individual;
  524. break;
  525. }
  526. if ($individual->id === $submissionid) {
  527. $found = true;
  528. }
  529. $i ++;
  530. }
  531. print '<center style="padding-top: 2rem;">';
  532. if ($previous) {
  533. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  534. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  535. } else {
  536. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  537. }
  538. print ' (' . $i . '/' . count($all_submissions) . ')';
  539. if ($next) {
  540. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  541. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  542. } else {
  543. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  544. }
  545. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  546. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "view", 'Proposition' => $url]);
  547. print '</center>';
  548. }
  549. /// Manage all submissions in exercises to table iassign_allsubmissions
  550. function all_submissions () {
  551. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  552. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  553. exit;
  554. print $OUTPUT->header();
  555. $id = $this->cm->id;
  556. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  557. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  558. print '
  559. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  560. <div class="modal-dialog modal-dialog-centered" role="document">
  561. <div class="modal-content">
  562. <div class="modal-header">
  563. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  564. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  565. <span aria-hidden="true">&times;</span>
  566. </button>
  567. </div>
  568. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  569. <div class="modal-footer">
  570. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  571. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  572. </div>
  573. </div>
  574. </div>
  575. </div>'; // "
  576. print '
  577. <script>
  578. var sub_type;
  579. var sub_item;
  580. var sub_el;
  581. var sub_exercise;
  582. function delete_submission (type, item, el, exercise = 0) {
  583. sub_type = type;
  584. sub_item = item;
  585. sub_exercise = exercise;
  586. sub_el = el.closest("tr");
  587. if (!sub_el) sub_el = el.closest("a");
  588. $("#modalConfirm").modal();
  589. }
  590. function confirm_delete () {
  591. var url = "'.$enderecoPOST.'&action=delete_submissions";
  592. var xhttp = new XMLHttpRequest();
  593. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  594. xhttp.send();
  595. $("#modalConfirm").modal("hide");
  596. if ($(sub_el).attr("href"))
  597. $($(sub_el).attr("href")).remove();
  598. if (sub_el) sub_el.remove();
  599. }
  600. function download_submission(type, item, exercise = 0, iassign = 0) {
  601. var url = "'.$enderecoPOST.'&action=download_submissions";
  602. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  603. document.location = url;
  604. }
  605. function open_submission(item) {
  606. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  607. var poupup = window.open(url, "popup", "width=900,height=900");
  608. }
  609. </script>' . chr(13); // '
  610. // Get list of exercises in the instance:
  611. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  612. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  613. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  614. 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>';
  615. // Get list of enrolled students:
  616. $params = array('shortname' => 'student');
  617. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  618. $context = context_course::instance($this->course->id);
  619. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  620. $students_list = $DB->get_records_sql(
  621. "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);
  622. print '<div>';
  623. foreach ($exercises_list as $exercise) {
  624. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  625. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  626. print '
  627. <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> '
  628. . $exercise->name
  629. . ' - ' . $iassign_ilm->name
  630. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  631. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  632. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  633. . $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> '
  634. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  635. . '</a>';
  636. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  637. foreach ($students_list as $student) {
  638. $total = 0;
  639. $student_submissions = [];
  640. foreach ($submissions_list as $submission) {
  641. if ($submission->userid == $student->userid) {
  642. $student_submissions[] = $submission;
  643. $total ++;
  644. }
  645. }
  646. 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");\'>
  647. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  648. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  649. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  650. . '<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> '
  651. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  652. . ' </a>';
  653. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  654. print '<table class="table table-striped table-hover"><thead>
  655. <tr>
  656. <th scope="col">#</th>
  657. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  658. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  659. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  660. </tr>
  661. </thead><tbody>'; // "
  662. $i = 1;
  663. foreach ($student_submissions as $individual) {
  664. $date = new DateTime();
  665. $date->setTimestamp($individual->timecreated);
  666. print '<tr>';
  667. print '<td>'.$i++.'</td>';
  668. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  669. print '<td>'.$individual->grade.'</td>';
  670. print '<td>
  671. <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>
  672. <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>
  673. <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>';
  674. print " </tr>\n";
  675. }
  676. print '</tbody></table>';
  677. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  678. print '</div>';
  679. }
  680. print '</div>';
  681. }
  682. print '</div>';
  683. print $OUTPUT->footer();
  684. } // function all_submissions()
  685. /// This method runs activities auto evaluation in teacher area
  686. function auto_evaluate () {
  687. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  688. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  689. exit;
  690. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  691. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  692. // Get list of exercises in the instance:
  693. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  694. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  695. // Get list of enrolled students:
  696. $params = array('shortname' => 'student');
  697. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  698. $context = context_course::instance($this->course->id);
  699. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  700. $students_list = $DB->get_records_sql(
  701. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  702. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  703. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  704. print $OUTPUT->header();
  705. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  706. print '<ul style="list-style-type: none; margin: 1em;">';
  707. foreach ($exercises_list as $exercise) {
  708. $matches = [];
  709. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  710. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  711. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  712. if ($matches[0][0]) {
  713. 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>';
  714. } else {
  715. 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>';
  716. }
  717. } else {
  718. if ($matches[0][0]) {
  719. 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>';
  720. } else {
  721. 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>';
  722. }
  723. }
  724. }
  725. print '</ul>
  726. <center>
  727. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  728. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  729. <div id="evaluate_message" style="color: red"></div>
  730. <div id="evaluate_alerts"></div>
  731. <div>
  732. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  733. <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>
  734. </div>
  735. </center>'; // close "
  736. print ' </div>' + "\n";
  737. print ' <script>';
  738. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  739. print ' var submissions = [';
  740. // Get list of student id have submit for each exercise:
  741. foreach ($exercises_list as $exercise) {
  742. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  743. print '
  744. {
  745. "exerciseid": "' . $exercise->id . '",
  746. "grade": ' . $exercise->grade . ',
  747. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  748. "submited": ['; // "
  749. $params = array('iassign_statementid' => $exercise->id);
  750. $submited = $DB->get_records_sql( // Get userid and his grade
  751. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  752. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  753. foreach ($submited as $ss) {
  754. print($ss->userid . ',');
  755. }
  756. print '],';
  757. print '"allgrades": [';
  758. foreach ($submited as $ss) {
  759. print( $ss->grade . ',');
  760. }
  761. print ']
  762. },'; // close "
  763. } // foreach ($exercises_list as $exercise)
  764. print " ];\n";
  765. print '
  766. var total_submissions = 0;
  767. var selected_exercises;
  768. var count_steps;
  769. var value_by_step;
  770. var stoped = false;
  771. var time_interval = 5000;
  772. var var_interval;
  773. function add_hover_th (id_th, id_li) { //AJAX
  774. $("#" + id_th).hover(function() {
  775. $("#" + id_li).css("background-color", "#d9d8d8");
  776. $(this).css("background-color", "#d9d8d8");
  777. }, function() {
  778. $("#" + id_li).css("background-color", "");
  779. $(this).css("background-color", "");
  780. });
  781. }
  782. function start_evaluation () {
  783. stoped = false;
  784. //AJAX
  785. $("#progress_bar").css("display", "none");
  786. $("#evaluate_message").text("");
  787. $("#evaluate_alerts").text("");
  788. $(".added-col").remove();
  789. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  790. selected_exercises = [];
  791. var c = 0;
  792. for (var i = 0; i < exercises.length; i++) {
  793. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  794. selected_exercises[c++] = exercises[i];
  795. }
  796. }
  797. if (selected_exercises.length == 0) {
  798. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  799. return;
  800. } else {
  801. $("input:checkbox").attr("disabled", true); //AJAX
  802. for (var i = 0; i < selected_exercises.length; i++) {
  803. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  804. //AJAX
  805. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  806. $("#table-results tbody tr").each(function(e) {
  807. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  808. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  809. });
  810. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  811. }
  812. //AJAX
  813. $("#button_start").prop("disabled", true);
  814. $("#button_stop").prop("disabled", false);
  815. $("#progress_bar").css("display", "block");
  816. }
  817. total_submissions = selected_exercises.length * students.length;
  818. count_steps = 0;
  819. value_by_step = 100/total_submissions;
  820. actual_exercise = 0;
  821. actual_student = 0;
  822. actual_submission = 0;
  823. get_original_propositions();
  824. var_interval = setInterval(verifyBreak, time_interval);
  825. } // function start_evaluation()
  826. var actual_exercise;
  827. var actual_student;
  828. var actual_submission;
  829. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  830. function run_individual_evaluation () {
  831. if (stoped) return;
  832. // Verify if student really sent his answer
  833. var found = false;
  834. for (var j = 0; j < submissions.length; j++) {
  835. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  836. for (var k = 0; k < submissions[j].submited.length; k++) {
  837. if (students[actual_student] == submissions[j].submited[k]) {
  838. found = true;
  839. break;
  840. }
  841. }
  842. break;
  843. }
  844. }
  845. if (found == false) {
  846. postResultAutoEval();
  847. } else {
  848. // If it was sent, search it...
  849. var final_url = "";
  850. 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];
  851. for (var j = 0; j < submissions.length; j++) {
  852. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  853. final_url = submissions[j].ilm;
  854. break;
  855. }
  856. }
  857. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  858. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  859. window.frames["ifrm"].location=final_url;
  860. }
  861. } // function run_individual_evaluation()
  862. var break_student = -1;
  863. var break_exercise = -1;
  864. function verifyBreak () {
  865. if (actual_student == break_student && actual_exercise == break_exercise) {
  866. postResultAutoEval(-6);
  867. break_student = -1;
  868. break_exercise = -1;
  869. return;
  870. } else {
  871. break_student = actual_student;
  872. break_exercise = actual_exercise;
  873. }
  874. }
  875. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  876. function getStudentAnswerURL () {
  877. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  878. }
  879. // This function is called by the iLM!!!
  880. function getAutoEvalOriginalData () {
  881. return original_propositions[actual_exercise];
  882. }
  883. function updateProgressBar () {
  884. if (stoped) return;
  885. var temp = (count_steps * value_by_step)|0;
  886. count_steps ++;
  887. temp = temp > 100 ? 100 : temp;
  888. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  889. if (temp >= 100) {
  890. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  891. $("#button_start").prop("disabled", false);
  892. $("#button_stop").prop("disabled", true);
  893. $("input:checkbox").attr("disabled", false);
  894. clearInterval(var_interval);
  895. }
  896. }
  897. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  898. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  899. function postResultAutoEval (grade = null) {
  900. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  901. if (grade == null) {
  902. $("#"+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>\');
  903. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  904. } else {
  905. // Verify if the re-evaluation grade is the of that one registered:
  906. var actual_value = 0;
  907. var actual_student_grade = 0;
  908. for (var k = 0; k < submissions.length; k++) {
  909. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  910. actual_value = submissions[k].grade;
  911. for (var h = 0; h < submissions[k].submited.length; h++) {
  912. if (submissions[k].submited[h] == students[actual_student]) {
  913. actual_student_grade = submissions[k].allgrades[h];
  914. break;
  915. }
  916. }
  917. break;
  918. }
  919. }
  920. // @FeedbackConvention
  921. if (grade < 0) {
  922. switch (grade) {
  923. case -1:
  924. // Test-cases are empty:
  925. $("#"+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>\');
  926. var mm = actual_exercise;
  927. $("#"+id_t).find(".details-button").click(function(e) {
  928. $(".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>\');
  929. });
  930. break;
  931. case -2:
  932. // Test-cases were manually altered by the student (fraud!):
  933. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  934. var mm = actual_exercise;
  935. $("#"+id_t).find(".details-button").click(function(e) {
  936. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  937. });
  938. //AJAX
  939. $.ajax({
  940. dataType: "html",
  941. 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",
  942. success: function(d) {} });
  943. break;
  944. case -5:
  945. // Execution failed:
  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_fail', 'iassign').'"></i></i>\');
  947. var mm = actual_exercise;
  948. //AJAX
  949. $("#"+id_t).find(".details-button").click(function(e) {
  950. $(".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>\');
  951. });
  952. break;
  953. case -6: // iLM not answering was detected in "verifyBreak()"
  954. // The iLM are not answering:
  955. //AJAX
  956. $("#"+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>\');
  957. $("#"+id_t).find(".details-button").click(function(e) {
  958. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  959. });
  960. break;
  961. }
  962. //AJAX
  963. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  964. } else {
  965. console.log((grade), (actual_student_grade));
  966. if ((grade) == (actual_student_grade)) {
  967. $("#"+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>\');
  968. } else { // Notas diferem:
  969. $("#"+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>\');
  970. var mm = actual_exercise;
  971. //AJAX
  972. $("#"+id_t).find(".details-button").click(function(e) {
  973. $(".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>\');
  974. });
  975. //AJAX
  976. // Send to the endpoint the post_auto_eval_result to verify:
  977. $.ajax({
  978. dataType: "html",
  979. 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),
  980. success: function(d) {}
  981. });
  982. }
  983. //AJAX
  984. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  985. }
  986. }
  987. updateProgressBar();
  988. // Does it must continue in the same exercise or stop?
  989. if (actual_student < students.length) {
  990. actual_student ++;
  991. run_individual_evaluation();
  992. } else {
  993. actual_student = 0;
  994. // Does it go to next exercise or is it finished?
  995. if (actual_exercise < selected_exercises.length) {
  996. actual_exercise++;
  997. run_individual_evaluation();
  998. } else {
  999. //AJAX
  1000. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1001. }
  1002. }
  1003. }
  1004. var original_propositions;
  1005. function get_original_propositions () {
  1006. original_propositions = [];
  1007. var count = 0;
  1008. for (var i = 0; i < exercises.length; i++) {
  1009. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1010. //AJAX
  1011. $.ajax({
  1012. dataType: "html",
  1013. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1014. success: function(d) { // variable "d" has the iLM content
  1015. original_propositions[count] = d; // exercise original content
  1016. count ++;
  1017. if (count == selected_exercises.length) {
  1018. run_individual_evaluation();
  1019. }
  1020. }
  1021. });
  1022. }
  1023. }
  1024. }
  1025. function stop_evaluation () {
  1026. stoped = true;
  1027. //AJAX
  1028. $("#button_start").prop("disabled", false);
  1029. $("#button_stop").prop("disabled", true);
  1030. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1031. $("input:checkbox").attr("disabled", false);
  1032. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1033. clearInterval(var_interval);
  1034. }
  1035. var exercises = [ '; // '
  1036. foreach ($exercises_list as $exercise) {
  1037. print $exercise->id . ',';
  1038. }
  1039. print ' ];';
  1040. print ' var students = [ ';
  1041. foreach ($students_list as $student) {
  1042. print $student->userid . ',';
  1043. }
  1044. print '];';
  1045. print ' var ilms = [';
  1046. foreach ($exercises_list as $exercise) {
  1047. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1048. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1049. }
  1050. print ']';
  1051. print '</script>';
  1052. print '
  1053. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1054. <div class="modal-dialog modal-dialog-centered" role="document">
  1055. <div class="modal-content">
  1056. <div class="modal-header">
  1057. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1058. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1059. <span aria-hidden="true">&times;</span>
  1060. </button>
  1061. </div>
  1062. <div class="modal-body">
  1063. ...
  1064. </div>
  1065. <div class="modal-footer">
  1066. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1067. </div>
  1068. </div>
  1069. </div>
  1070. </div>'; //
  1071. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1072. print '<table id="table-results" class="table table-hover m-t-1">
  1073. <thead>
  1074. <tr id="cols-exercises">
  1075. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1076. </tr>
  1077. </thead>
  1078. <tbody>'; // "
  1079. foreach ($students_list as $student) {
  1080. $user = $DB->get_record('user', array('id' => $student->userid));
  1081. $avatar = new user_picture($user);
  1082. $avatar->courseid = $COURSE->id;
  1083. $avatar->link = true;
  1084. print ' <tr data-student="' . $student->userid . '">
  1085. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1086. </tr>' . "\n";
  1087. }
  1088. print " </tbody>
  1089. </table>\n";
  1090. print $OUTPUT->footer();
  1091. } // function auto_evaluate()
  1092. /// This method moves an iAssign activity
  1093. function move_activity () {
  1094. global $USER, $CFG, $DB, $COURSE;
  1095. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1096. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1097. $update_entry_new_iassign = new stdClass();
  1098. $update_entry_new_iassign->id = $iassign_id;
  1099. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1100. // Update the iassign_statement
  1101. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1102. // Update file context
  1103. $c_i = context_module::instance($this->cm->id);
  1104. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1105. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1106. $path_module = context_course::instance($COURSE->id);
  1107. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1108. if ($context_file) {
  1109. $id_context = $context_file->id;
  1110. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1111. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1112. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1113. foreach ($files as $value) {
  1114. if ($value->get_filename() != ".") {
  1115. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1116. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1117. $updateentry = new stdClass();
  1118. $updateentry->id = $iassign_id;
  1119. $updateentry->filesid = $newfile->get_itemid();
  1120. $DB->update_record("iassign_statement", $updateentry);
  1121. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1122. break;
  1123. }
  1124. }
  1125. }
  1126. $this->return_home_course('moved_activity');
  1127. exit;
  1128. }
  1129. /// This method duplicates an iAssign activity
  1130. function duplicate_activity () {
  1131. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1132. $id = $this->cm->id;
  1133. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1134. $context = context_module::instance($this->cm->id);
  1135. $contextuser = context_user::instance($USER->id);
  1136. // Get the the iAssign acitivity to be duplicated
  1137. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1138. // Remove the current id of activity
  1139. $iassign_statement->id=0;
  1140. // Get the information about current author, and add this information in author_modified field
  1141. $author = $DB->get_record("user", array('id' => $USER->id));
  1142. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1143. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1144. // Store the activity in the table
  1145. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1146. // Duplicate activity file
  1147. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1148. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1149. foreach ($files as $value) {
  1150. if ($value->get_filename() != ".") {
  1151. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1152. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1153. $updateentry = new stdClass();
  1154. $updateentry->id = $id_;
  1155. $updateentry->filesid = $newfile->get_itemid();
  1156. // Update the duplicated iLM iAssign with new file id
  1157. $DB->update_record("iassign_statement", $updateentry);
  1158. }
  1159. }
  1160. }
  1161. // log event --------------------------------------------------------------------------------------
  1162. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1163. $this->return_home_course('duplicated_activity');
  1164. exit;
  1165. }
  1166. // / This method gets the content from comment and register it
  1167. function add_comment () {
  1168. global $USER, $DB;
  1169. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1170. $comment = false;
  1171. if ($submission_comment)
  1172. $comment = $this->write_comment_submission();
  1173. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1174. if (!$id_submission) {
  1175. $iassign_submission =
  1176. $DB->get_record("iassign_submission",
  1177. array(
  1178. "iassign_statementid" => $this->activity->get_activity()->id,
  1179. "userid" => $USER->id
  1180. )
  1181. );
  1182. if ($iassign_submission) {
  1183. $id_submission = $iassign_submission->id;
  1184. }
  1185. }
  1186. echo $this->search_comment_submission($id_submission);
  1187. }
  1188. /// This method gets the content from the iLM and register it
  1189. // It could be the "exercise template" (teacher) or an answer (student)
  1190. function get_answer () {
  1191. global $USER, $CFG, $DB, $OUTPUT;
  1192. $id = $this->cm->id;
  1193. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1194. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1195. if ($submission_ajax == 1) ob_start();
  1196. $comment = false;
  1197. if ($submission_comment)
  1198. $comment = $this->write_comment_submission();
  1199. // receives data of iLM using the current activity
  1200. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1201. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1202. // receives data of submission of current activity
  1203. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1204. // receives post and get
  1205. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1206. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1207. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1208. $iLM_PARAM_ArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // answer file (ATTENTION: do not change format, use RAW in order to ensure the correct content)
  1209. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1210. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1211. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1212. $msg = '';
  1213. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1214. $newentry = new stdClass();
  1215. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1216. $newentry->userid = $this->userid_iassign;
  1217. $newentry->timecreated = time();
  1218. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1219. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1220. $DB->insert_record("iassign_allsubmissions", $newentry);
  1221. }
  1222. // Feedback
  1223. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1224. $str_action = "view"; // repeat
  1225. if (strtolower($iassign_ilm->name) == "igeom") {
  1226. }
  1227. $title = get_string('evaluate_iassign', 'iassign');
  1228. print $OUTPUT->header();
  1229. print $OUTPUT->box_start();
  1230. // Action = { view ; repeat ; viewsubmission }
  1231. // * 'view' => it is impossible to re-send answer (this is correct with iGeom because its model to ensure security - do not allow the learner's access to the "answer model")
  1232. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1233. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1234. $return = $CFG->wwwroot . "/mod/iassign/view.php?action=view&id=" . $id . "&iassign_submission_current=" . $this->iassign_submission_current . "&userid_iassign=" . $this->userid_iassign . "&iassign_current=" . $this->activity->get_activity()->id;
  1235. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1236. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1237. print '<table width=100% >';
  1238. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1239. //TODO alterar aqui???
  1240. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1241. // empty_answer_post = No solution was posted.
  1242. if ($comment)
  1243. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1244. else
  1245. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1246. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1247. } else {
  1248. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1249. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1250. // Correct answer!!
  1251. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1252. $this->write_solution = 1; //
  1253. $status = 3;
  1254. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1255. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1256. // log record
  1257. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_correct', 'iassign') . "&nbsp;-&nbsp;" . get_string('grade_iassign', 'iassign') . ":" . $grade_student;
  1258. // Trigger module viewed event.
  1259. $event = \mod_iassign\event\submission_created::create(array(
  1260. 'objectid' => $this->iassign->id,
  1261. 'context' => $this->context,
  1262. 'other' => $info
  1263. ));
  1264. $event->add_record_snapshot('course', $this->course);
  1265. $event->trigger();
  1266. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1267. // Wrong answer...: get_answer_incorrect
  1268. $status = 2;
  1269. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1270. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1271. // log record
  1272. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1273. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1274. // Trigger module viewed event.
  1275. $event = \mod_iassign\event\submission_created::create(array(
  1276. 'objectid' => $this->iassign->id,
  1277. 'context' => $this->context,
  1278. 'other' => $info
  1279. ));
  1280. $event->add_record_snapshot('course', $this->course);
  1281. $event->trigger();
  1282. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1283. // Presents to the learner the result of the automatic evaluate?
  1284. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1285. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1286. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1287. print '<tr>';
  1288. // log record
  1289. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1290. // Trigger module viewed event.
  1291. $event = \mod_iassign\event\submission_created::create(array(
  1292. 'objectid' => $this->iassign->id,
  1293. 'context' => $this->context,
  1294. 'other' => $info
  1295. ));
  1296. $event->add_record_snapshot('course', $this->course);
  1297. $event->trigger();
  1298. } else { // yes!!!
  1299. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1300. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1301. print '<tr>';
  1302. print $msg;
  1303. }
  1304. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1305. $status = 1;
  1306. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1307. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1308. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1309. print '<tr>';
  1310. // log record
  1311. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1312. $event = \mod_iassign\event\submission_created::create(array(
  1313. 'objectid' => $this->iassign->id,
  1314. 'context' => $this->context,
  1315. 'other' => $info
  1316. ));
  1317. $event->add_record_snapshot('course', $this->course);
  1318. $event->trigger();
  1319. } // if ($iassign_ilm->evaluate == 1)
  1320. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1321. print '</tr></table>';
  1322. print $OUTPUT->box_end();
  1323. // add or update evaluate
  1324. if ($this->write_solution == 1) {
  1325. $timenow = time();
  1326. // new record
  1327. if (!$iassign_submission) {
  1328. $newentry = new stdClass();
  1329. $newentry->userid = $this->userid_iassign;
  1330. // $newentry->userid = $USER->id;
  1331. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1332. $newentry->timecreated = $timenow;
  1333. $newentry->timemodified = $timenow;
  1334. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1335. $newentry->grade = round($grade_student, 2);
  1336. $newentry->status = $status;
  1337. $newentry->experiment = 1;
  1338. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1339. print_error('error_insert', 'iassign');
  1340. } else {
  1341. // Trigger module viewed event.
  1342. $event = \mod_iassign\event\submission_created::create(array(
  1343. 'objectid' => $this->iassign->id,
  1344. 'context' => $this->context
  1345. ));
  1346. $event->add_record_snapshot('course', $this->course);
  1347. $event->trigger();
  1348. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1349. }
  1350. } elseif ($iassign_submission->status != 3) {
  1351. $newentry = new stdClass();
  1352. $newentry->id = $iassign_submission->id;
  1353. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1354. $newentry->userid = $iassign_submission->userid;
  1355. $newentry->timecreated = $iassign_submission->timecreated;
  1356. $newentry->timemodified = $timenow;
  1357. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1358. $newentry->grade = round($grade_student, 2);
  1359. $newentry->status = $status;
  1360. $newentry->experiment = $iassign_submission->experiment + 1;
  1361. if (!$DB->update_record("iassign_submission", $newentry)) {
  1362. print_error('error_update', 'iassign');
  1363. //D depurar...
  1364. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1365. //D $fp = fopen("teste1.txt","w");
  1366. //D fwrite($fp,$stringAux);
  1367. } else {
  1368. // Trigger module viewed event.
  1369. $event = \mod_iassign\event\submission_updated::create(array(
  1370. 'objectid' => $this->iassign->id,
  1371. 'context' => $this->context
  1372. ));
  1373. $event->add_record_snapshot('course', $this->course);
  1374. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1375. }
  1376. } else {
  1377. if ($return_get_answer == 1) {
  1378. $newentry = new stdClass();
  1379. $newentry->id = $iassign_submission->id;
  1380. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1381. $newentry->userid = $iassign_submission->userid;
  1382. $newentry->timecreated = $iassign_submission->timecreated;
  1383. $newentry->timemodified = $timenow;
  1384. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1385. $newentry->grade = round($grade_student, 2);
  1386. $newentry->status = $status;
  1387. $newentry->experiment = $iassign_submission->experiment + 1;
  1388. if (!$DB->update_record("iassign_submission", $newentry))
  1389. print_error('error_update', 'iassign');
  1390. else {
  1391. $event = \mod_iassign\event\submission_updated::create(array(
  1392. 'objectid' => $this->iassign->id,
  1393. 'context' => $this->context
  1394. ));
  1395. $event->add_record_snapshot('course', $this->course);
  1396. $event->trigger();
  1397. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1398. print $OUTPUT->box_start();
  1399. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1400. print $OUTPUT->box_end();
  1401. }
  1402. } elseif ($return_get_answer == 2) {
  1403. print $OUTPUT->box_start();
  1404. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1405. print $OUTPUT->box_end();
  1406. } else {
  1407. print $OUTPUT->box_start();
  1408. print "
  1409. <script type='text/javascript'>
  1410. //<![CDATA[
  1411. function overwrite () {
  1412. document.formEnvio.return_get_answer.value = 1;
  1413. document.formEnvio.submit();
  1414. }
  1415. function nooverwrite () {
  1416. document.formEnvio.return_get_answer.value = 2;
  1417. document.formEnvio.submit();
  1418. }
  1419. //]]>
  1420. </script>";
  1421. $param_aux = "action=overwrite&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1422. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1423. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1424. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1425. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1426. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1427. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1428. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1429. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1430. <input type='hidden' name='return_get_answer'/> ";
  1431. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1432. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1433. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1434. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1435. print " </form>";
  1436. print $OUTPUT->box_end();
  1437. }
  1438. }
  1439. } // if ($this->write_solution == 1)
  1440. print $OUTPUT->footer();
  1441. if ($submission_ajax == 1) {
  1442. ob_end_clean();
  1443. print 'OK';
  1444. }
  1445. die();
  1446. } // function get_answer()
  1447. /// Export in file the answer of student.
  1448. function export_file_answer () {
  1449. global $DB;
  1450. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1451. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1452. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1453. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1454. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1455. $extensions = explode(",", $iassign_ilm->extension);
  1456. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1457. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1458. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1459. header("Pragma: public");
  1460. header("Expires: 0");
  1461. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1462. header("Cache-Control: private", false);
  1463. header("Content-Type: document/unknown");
  1464. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1465. set_time_limit(0);
  1466. print($iassign_submission->answer);
  1467. exit;
  1468. } // function export_file_answer()
  1469. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1470. // @calledby $this->export_package_answer()
  1471. //TODO Precisa terminar! //TODO_HTML
  1472. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1473. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1474. <head>
  1475. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1476. $str_html .= " </head>
  1477. <body>\n";
  1478. $tam = sizeof($array_iassign_name);
  1479. for ($ii=0; $ii<$tam; $ii++) {
  1480. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1481. }
  1482. $str_html .= "
  1483. </body>\n</html>";
  1484. return $str_html;
  1485. }
  1486. /// Export an package (zip) with all answer of students
  1487. // @calledby $this->action()
  1488. function export_package_answer () {
  1489. global $DB, $CFG, $OUTPUT;
  1490. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1491. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1492. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1493. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1494. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1495. $userid = optional_param('userid', NULL, PARAM_INT);
  1496. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1497. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1498. //TODO_HTML echo "username=$username<br/>"; exit;
  1499. $current_date = date('Y_m_d_H');
  1500. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1501. // If temporary directory under Moodle data does not exists => create it
  1502. if (!is_dir($diretorio)) {
  1503. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1504. // created directory with permissions to be seen by everyone
  1505. }
  1506. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1507. if (!is_writable($diretorio)) { // send a highlighted message!
  1508. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1509. exit; // just in case
  1510. }
  1511. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1512. $zip = new zip_archive(); // create ZIP
  1513. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1514. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1515. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1516. $vet_student_filename = array();
  1517. $vet_student_content = array();
  1518. foreach ($iassign_statements as $iassign_statement) {
  1519. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1520. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1521. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1522. $extensions = explode(",", $iassign_ilm->extension);
  1523. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1524. if ($iassign_submission) {
  1525. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1526. $student_content = $iassign_submission->answer;
  1527. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1528. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1529. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1530. if ($resp) {
  1531. $vet_student_filename[] = $student_filename;
  1532. $vet_student_content[] = $student_content;
  1533. }
  1534. else { // send a highlighted message!
  1535. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1536. exit; // just in case
  1537. }
  1538. }
  1539. }
  1540. $zip->close(); // close the ZIP file
  1541. if (count($vet_student_filename)>0) {
  1542. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1543. $result_tf = $vet_result[0];
  1544. $filenameZip = $vet_result[1]->filename;
  1545. }
  1546. iassign_utils::download_file($zip_filename); // download the ZIP file
  1547. exit;
  1548. } // function export_package_answer()
  1549. /// Editing status of interactive activities
  1550. function edit_status () {
  1551. global $USER, $DB, $OUTPUT;
  1552. $newentry = new stdClass();
  1553. $newentry->id = $this->iassign_submission_current;
  1554. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1555. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1556. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1557. $newentry->status = $iassign_submission->status;
  1558. $newentry->teacher = $USER->id;
  1559. if (!$DB->update_record('iassign_submission', $newentry))
  1560. print_error('error_update', 'iassign');
  1561. else {
  1562. // Trigger module viewed event.
  1563. $event = \mod_iassign\event\submission_updated::create(array(
  1564. 'objectid' => $this->iassign->id,
  1565. 'context' => $this->context
  1566. ));
  1567. $event->add_record_snapshot('course', $this->course);
  1568. $event->trigger();
  1569. $this->action = 'viewsubmission';
  1570. $this->view_iassign_current();
  1571. } // if (!$DB->update_record('iassign_submission', $newentry))
  1572. } // function edit_status()
  1573. /// Editing grade of interactive activities
  1574. function edit_grade () {
  1575. global $USER, $DB, $OUTPUT;
  1576. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1577. if ($newgrade && $newgrade >= 0) {
  1578. $newentry = new stdClass();
  1579. $newentry->id = $this->iassign_submission_current;
  1580. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1581. $newentry->teacher = $USER->id;
  1582. if (!$DB->update_record('iassign_submission', $newentry))
  1583. print_error('error_update', 'iassign');
  1584. else {
  1585. // Trigger module viewed event.
  1586. $event = \mod_iassign\event\submission_updated::create(array(
  1587. 'objectid' => $this->iassign->id,
  1588. 'context' => $this->context
  1589. ));
  1590. $event->add_record_snapshot('course', $this->course);
  1591. $event->trigger();
  1592. }
  1593. } // if ($newgrade >= 0)
  1594. $this->action = 'viewsubmission';
  1595. $this->view_iassign_current();
  1596. }
  1597. /// Add or Edit interactive activities
  1598. // @calledby $this->action()
  1599. function add_edit_iassign () {
  1600. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1601. require_once('iassign_form.php');
  1602. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1603. $iassignid = $this->iassign->id;
  1604. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1605. $param->action = $this->action; // hidden
  1606. $param->id = $id; // hidden
  1607. $COURSE->cm = $id;
  1608. $COURSE->iassignid = $iassignid;
  1609. $COURSE->iassign_file_id = NULL;
  1610. // echo "<br/><br/><br/>locallib.php: add_edit_iassign(): id=$id, iassignid=$iassignid, action=" . $this->action . "<br/>\n";
  1611. // locallib.php: add_edit_iassign(): id=18612, iassignid=1355, action=edit
  1612. $context = context_module::instance($this->cm->id);
  1613. $contextuser = context_user::instance($USER->id);
  1614. $component = 'mod_iassign';
  1615. $filearea = 'exercise';
  1616. if (!empty($this->iassign_current))
  1617. $COURSE->iassign_id = $this->iassign_current;
  1618. else
  1619. $COURSE->iassign_id = 0;
  1620. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1621. if ($this->action == 'add') {
  1622. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1623. $params = array('iassignid' => $iassignid);
  1624. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1625. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1626. $total_of_activities = count($iassign_statement);
  1627. $param->iassignid = $iassignid;
  1628. $param->name = "";
  1629. $param->oldname = "";
  1630. $param->type_iassign = 3;
  1631. $param->proposition = "";
  1632. $author = $DB->get_record("user", array("id" => $USER->id));
  1633. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1634. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1635. $param->author = $param->author_name;
  1636. $param->author_modified = $param->author_modified_name;
  1637. $COURSE->iassign_list = array();
  1638. $param->iassign_list = array();
  1639. if ($iassign_statement) {
  1640. foreach ($iassign_statement as $iassign) {
  1641. $iassignid = $iassign->id;
  1642. $param->iassign_list[$iassignid] = 0;
  1643. $COURSE->iassign_list[$iassignid] = new stdClass();
  1644. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1645. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1646. $COURSE->iassign_list[$iassignid]->enable = 1;
  1647. } // foreach ($iassign_statement as $iassign)
  1648. }
  1649. $param->iassign_ilmid = 0;
  1650. $param->file = 0;
  1651. $param->fileold = 0;
  1652. $param->filename = "";
  1653. $param->grade = $iassign_data->grade;
  1654. $param->timemodified = time();
  1655. $param->timecreated = time();
  1656. $param->timeavailable = $iassign_data->timeavailable;
  1657. $param->timedue = $iassign_data->timedue;
  1658. $param->preventlate = $iassign_data->preventlate;
  1659. $param->test = $iassign_data->test;
  1660. $param->special_param1 = 0;
  1661. $param->visible = 1;
  1662. $param->max_experiment = $iassign_data->max_experiment;
  1663. $param->dependency = 0;
  1664. $param->automatic_evaluate = 1;
  1665. $param->show_answer = 1;
  1666. } // if ($this->action == 'add')
  1667. elseif ($this->action == 'edit') {
  1668. $COURSE->iassign_list = array();
  1669. $this_activity = $this->activity->get_activity();
  1670. if ($this_activity != null) {
  1671. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1672. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1673. $param->iassign_id = $iassign_statement_current->id; // oculto
  1674. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1675. $param->name = $iassign_statement_current->name;
  1676. $param->oldname = $iassign_statement_current->name;
  1677. $param->type_iassign = $iassign_statement_current->type_iassign;
  1678. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1679. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1680. //2019 $param->proposition = $iassign_statement_current->proposition;
  1681. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1682. $param->author_name = $iassign_statement_current->author_name; // oculto
  1683. $param->author = $iassign_statement_current->author_name;
  1684. $author = $DB->get_record("user", array('id' => $USER->id));
  1685. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1686. $param->author_modified = $param->author_modified_name;
  1687. $dependency = explode(';', $iassign_statement_current->dependency);
  1688. $param->iassign_list = array();
  1689. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1690. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1691. $array_dependency = array();
  1692. $subdependency = "";
  1693. $sub_subdependency = "";
  1694. // Dependents on this exercise
  1695. if ($iassign_statement_dependency) {
  1696. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1697. // to whom this exercise depends
  1698. foreach ($inter as $tmp)
  1699. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1700. $list_dependency = $subdependency . $sub_subdependency;
  1701. $array_dependency = explode(";", $list_dependency);
  1702. }
  1703. // Get all activities in the same iAssigment block:
  1704. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1705. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1706. //echo "<br/><br/><br/>1. all_others_iassign_statement="; print_r($all_others_iassign_statement); echo "<br/>";
  1707. // [5426] => stdClass Object ( [id] => 5426 [name] => 1. iHanói: com 3 discos )
  1708. // [5428] => stdClass Object ( [id] => 5428 [name] => 1. iFrações: trator 1, fase 1 )
  1709. // [5427] => stdClass Object ( [id] => 5427 [name] => 1. iFrações: trator 1, fase 2 )
  1710. // [5429] => stdClass Object ( [id] => 5429 [name] => 1. iVProg. Ler e imprimir inteiro. ) )
  1711. $total_of_activities = count($all_others_iassign_statement) + 1;
  1712. $inter = array();
  1713. if ($all_others_iassign_statement) {
  1714. foreach ($all_others_iassign_statement as $iassign)
  1715. if (in_array($iassign->id, $dependency))
  1716. $inter[] = $iassign->id;
  1717. }
  1718. if ($all_others_iassign_statement) {
  1719. foreach ($all_others_iassign_statement as $iassign) {
  1720. $iassignid = $iassign->id;
  1721. $COURSE->iassign_list[$iassignid] = new stdClass();
  1722. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1723. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1724. if (in_array($iassignid, $dependency))
  1725. $param->iassign_list[$iassignid] = 1;
  1726. else
  1727. $param->iassign_list[$iassignid] = 0;
  1728. if (in_array($iassignid, $array_dependency))
  1729. $COURSE->iassign_list[$iassignid]->enable = 0;
  1730. else
  1731. $COURSE->iassign_list[$iassignid]->enable = 1;
  1732. } // foreach ($all_others_iassign_statement as $iassign)
  1733. }
  1734. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1735. $param->fileold = 0;
  1736. $param->filesid = 0;
  1737. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1738. $param->filename = '';
  1739. $param->grade = $iassign_statement_current->grade;
  1740. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1741. $param->timeavailable = $iassign_statement_current->timeavailable;
  1742. $param->timedue = $iassign_statement_current->timedue;
  1743. $param->preventlate = $iassign_statement_current->preventlate;
  1744. $param->test = $iassign_statement_current->test;
  1745. $param->special_param1 = $iassign_statement_current->special_param1;
  1746. $param->position = $iassign_statement_current->position; // oculto
  1747. $param->visible = $iassign_statement_current->visible;
  1748. $param->max_experiment = $iassign_statement_current->max_experiment;
  1749. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1750. $param->show_answer = $iassign_statement_current->show_answer;
  1751. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1752. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  1753. if ($files) {
  1754. foreach ($files as $file) {
  1755. if ($file->get_filename() != '.') {
  1756. $param->filename = $file->get_filename();
  1757. $param->file = $file->get_id();
  1758. $param->fileold = $file->get_id();
  1759. $COURSE->iassign_file_id = $file->get_id();
  1760. }
  1761. }
  1762. }
  1763. //TODO //MOOC2014 -- inicio
  1764. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1765. //D if ($iassign_ilm_configs) {
  1766. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1767. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1768. //D } //MOOC2014 -- fim
  1769. } // if ($this_activity != null)
  1770. } // elseif ($this->action == 'edit')
  1771. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1772. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1773. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1774. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1775. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1776. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1777. $param->position = $total_of_activities;
  1778. // Create form and associate its data
  1779. // $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1780. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1781. $mform->set_data($param);
  1782. if ($mform->is_cancelled()) {
  1783. $this->return_home_course('iassign_cancel');
  1784. exit;
  1785. }
  1786. else { // else if ($mform->is_cancelled())
  1787. $result = $mform->get_data();
  1788. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1789. if ($result) {
  1790. $result->context = $context;
  1791. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1792. $result->grade = 0;
  1793. if ($result->type_iassign == 1) {
  1794. $result->automatic_evaluate = 0;
  1795. $result->show_answer = 0;
  1796. }
  1797. elseif ($result->automatic_evaluate == 0)
  1798. $result->show_answer = 0;
  1799. // $_POST['iassign_list']
  1800. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1801. if ($result->iassign_list) {
  1802. foreach ($result->iassign_list as $key => $value)
  1803. $result->dependency .= $key . ';';
  1804. }
  1805. else
  1806. $result->dependency = 0;
  1807. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1808. //TODO Then get it directly from the form data $_POST!
  1809. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1810. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1811. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1812. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1813. if ($this->action == 'add') {
  1814. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1815. if ($iassign_statement_name) {
  1816. $this->return_home_course('error_iassign_name');
  1817. die();
  1818. }
  1819. // Really insert the new iActivity in table '*_iassign_statement'
  1820. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1821. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1822. // Trigger module viewed event.
  1823. $event = \mod_iassign\event\iassign_created::create(array(
  1824. 'objectid' => $iassignid,
  1825. 'context' => $context
  1826. ));
  1827. $event->add_record_snapshot('course', $this->course);
  1828. $event->trigger();
  1829. $this->return_home_course('iassign_add');
  1830. } // if ($this->action == 'add')
  1831. elseif ($this->action == 'edit') {
  1832. $iassignid = $this->activity->update_iassign($result);
  1833. $this->activity->update_calendar($iassignid, $result->oldname);
  1834. // Trigger module viewed event.
  1835. $event = \mod_iassign\event\iassign_updated::create(array(
  1836. 'objectid' => $iassignid,
  1837. 'context' => $context
  1838. ));
  1839. $event->add_record_snapshot('course', $this->course);
  1840. $event->trigger();
  1841. $this->return_home_course('iassign_update');
  1842. } // elseif ($this->action == 'edit')
  1843. die();
  1844. } // if ($result)
  1845. } // else if ($mform->is_cancelled())
  1846. print $OUTPUT->header();
  1847. $mform->display();
  1848. print $OUTPUT->footer();
  1849. die();
  1850. } // function add_edit_iassign()
  1851. /// Search for dependencies
  1852. function search_dependency ($search_iassing_id, $iassign_statement) {
  1853. global $DB, $OUTPUT;
  1854. $dependency = "";
  1855. if ($iassign_statement)
  1856. foreach ($iassign_statement as $iassign) {
  1857. $inter_dependency = explode(';', $iassign->dependency);
  1858. if (in_array($search_iassing_id, $inter_dependency)) {
  1859. $dependency .= $iassign->id . ";";
  1860. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1861. } // if (in_array($search_iassing_id, $inter_dependency))
  1862. } // foreach ($iassign_statement as $iassign)
  1863. return $dependency;
  1864. }
  1865. /// Search for "sub"dependency
  1866. function search_sub_dependency ($search_iassing_id) {
  1867. global $DB, $OUTPUT;
  1868. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1869. $dependency = "";
  1870. if ($iassign_statement) {
  1871. $inter_dependency = explode(';', $iassign_statement->dependency);
  1872. foreach ($inter_dependency as $tmp) {
  1873. if ($tmp != 0)
  1874. $dependency .= $tmp . ";";
  1875. $dependency .= $this->search_sub_dependency($tmp);
  1876. } // foreach ($inter_dependency as $tmp)
  1877. } // if ($iassign_statement)
  1878. return $dependency;
  1879. }
  1880. // Warning message
  1881. static function warning_message_iassign ($strcode) {
  1882. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1883. }
  1884. /// Update grade of iAssign
  1885. // Called always any iAssign activity is created
  1886. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1887. static function update_grade_iassign ($iassignid) {
  1888. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1889. require_once($CFG->libdir . '/gradelib.php');
  1890. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1891. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1892. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1893. // Each iAssign item is associated with one item on the "gradebook"
  1894. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1895. //$sum_grade = 0;
  1896. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1897. //foreach($grade as $tmp) {
  1898. // $sum_grade += $tmp->grade;
  1899. // }
  1900. //1 Solution 1
  1901. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1902. //1 $sum_grade = 0; //1
  1903. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1904. //2 Solution 2
  1905. $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
  1906. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1907. if (key($array_sum_grade))
  1908. $sum_grade = key($array_sum_grade); //2
  1909. else
  1910. $sum_grade = 0; //2
  1911. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1912. $grades = NULL;
  1913. $params = array('itemname' => $grade_iassign->name);
  1914. $params['iteminstance'] = $iassignid;
  1915. $params['gradetype'] = GRADE_TYPE_VALUE;
  1916. //2016 if ($sum_grade != 0) {
  1917. $params['grademax'] = $sum_grade;
  1918. $params['rawgrademax'] = $sum_grade;
  1919. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1920. $params['grademin'] = 0;
  1921. // @calls /lib/gradelib.php: call to grade_item->insert()
  1922. //TODO: is there any error here in Moodle version 3.0?
  1923. //TODO: Incorrect property 'grademax' found when inserting grade object
  1924. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1925. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1926. }
  1927. /// Update grade of student
  1928. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1929. global $CFG, $DB, $OUTPUT;
  1930. require_once($CFG->libdir . '/gradelib.php');
  1931. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1932. // Review all the student submission for this iAssign activity
  1933. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1934. $total_grade = 0;
  1935. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1936. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1937. if ($iassign_submission)
  1938. $total_grade += $iassign_submission->grade;
  1939. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1940. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1941. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1942. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1943. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1944. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1945. $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
  1946. if (key($array_sum_grade))
  1947. $sum_grade = key($array_sum_grade); //2
  1948. else
  1949. $sum_grade = 0; //2
  1950. $grades['userid'] = $userid;
  1951. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1952. $params = array('itemname' => $grade_iassign->name);
  1953. $params['iteminstance'] = $iassignid;
  1954. $params['gradetype'] = GRADE_TYPE_VALUE;
  1955. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1956. $params['grademax'] = $sum_grade;
  1957. $params['rawgrademax'] = $sum_grade;
  1958. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1959. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1960. }
  1961. /// Display caption of icons
  1962. function view_legend_icons () {
  1963. global $USER, $CFG, $DB, $OUTPUT;
  1964. $id = $this->cm->id;
  1965. if ($this->action == 'print')
  1966. print '<table border=1 width=100%><tr>';
  1967. else
  1968. print '<table width=100%><tr>';
  1969. print '<td >';
  1970. if ($this->action != 'print')
  1971. print $OUTPUT->help_icon('legend', 'iassign');
  1972. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1973. // $imagetext = '');
  1974. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1975. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1976. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1977. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1978. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1979. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1980. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1981. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1982. print '</td>' . "\n";
  1983. if ($this->action != 'print') {
  1984. $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>";
  1985. $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>";
  1986. $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>";
  1987. $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>";
  1988. $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>";
  1989. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1990. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1991. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1992. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1993. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1994. } // if ($this->action != 'print')
  1995. print '</tr></table>' . "\n";
  1996. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1997. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1998. $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>";
  1999. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  2000. print '</tr></table>' . "\n";
  2001. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2002. else
  2003. print '</td></tr></table>' . "\n";
  2004. } // function view_legend_icons()
  2005. /// Display activity current
  2006. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2007. function view_iassign_current () {
  2008. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2009. $id = $this->cm->id;
  2010. $iassignid = $this->iassign->id;
  2011. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2012. $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
  2013. // 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 ...
  2014. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2015. if (!$iassign_statement_activity_item) {
  2016. print $OUTPUT->header();
  2017. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2018. print $OUTPUT->footer();
  2019. exit;
  2020. }
  2021. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2022. $ilm_name = '';
  2023. if ($ilm->ilm)
  2024. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2025. // 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
  2026. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2027. // log record
  2028. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2029. //Trigger module viewed event.
  2030. $event = \mod_iassign\event\submission_viewed::create(array(
  2031. 'objectid' => $iassign->id,
  2032. 'context' => $this->context,
  2033. 'other' => $info
  2034. ));
  2035. $event->add_record_snapshot('course', $this->course);
  2036. $event->trigger();
  2037. // Search of iLM data used in the current activity
  2038. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2039. // Add actual activity to navbar:
  2040. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2041. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2042. print $OUTPUT->header();
  2043. if ($this->action == 'viewsubmission') {
  2044. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2045. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2046. else
  2047. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2048. } else {
  2049. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2050. }
  2051. if ($iassign_submission)
  2052. $this->update_comment($iassign_submission->id);
  2053. $file = $iassign_statement_activity_item->filesid;
  2054. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2055. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2056. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2057. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2058. $this->bottonPost = 0; // hide submit button
  2059. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2060. $this->view_iassign = false; // disable visualization of activity
  2061. $repeat = "";
  2062. $last_iassign = "";
  2063. $student_answer = "";
  2064. $comment = "";
  2065. // *** Teacher access (view learner's submission)
  2066. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2067. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2068. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2069. // ---> access teacher for test
  2070. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2071. $this->bottonPost = 1;
  2072. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2073. $this->activity->view_dates();
  2074. $USER->iassignEdit = $this->bottonPost;
  2075. $this->activity->show_info_iassign();
  2076. if ($iassign_submission) {
  2077. //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;
  2078. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2079. } else {
  2080. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2081. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2082. }
  2083. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2084. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2085. // Prepare tags to present the iLM
  2086. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2087. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2088. // *** (end) Teacher access (view the activity)
  2089. // *** Teacher access (view learner's submission to the activity)
  2090. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2091. // It is teacher or 'nonediting teacher' that can evaluate
  2092. // ----> area teacher evaluate
  2093. $row = optional_param('row', 0, PARAM_INT);
  2094. $column = optional_param('column', 0, PARAM_INT);
  2095. $link_next = iassign_icons::insert('right_disable');
  2096. $link_previous = iassign_icons::insert('left_disable');
  2097. $link_up = iassign_icons::insert('up_disable');
  2098. $link_down = iassign_icons::insert('down_disable');
  2099. // next_activity
  2100. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2101. $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);
  2102. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2103. }
  2104. // previous_activity
  2105. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2106. $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);
  2107. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2108. }
  2109. // previous_student
  2110. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2111. $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);
  2112. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2113. }
  2114. // next_student
  2115. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2116. $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);
  2117. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2118. }
  2119. if ($iassign_submission) {
  2120. $student_answer = $iassign_submission->answer;
  2121. }
  2122. $last_iassign = get_string('last_iassign', 'iassign');
  2123. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2124. // Messages related to due date (and user role)
  2125. $this->activity->view_dates();
  2126. print $OUTPUT->box_start();
  2127. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2128. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2129. print $OUTPUT->user_picture($user_data);
  2130. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2131. print '</td>' . "\n";
  2132. print '<td width=20% align=right>' . "\n";
  2133. print '<table width=50 cellpadding="0">';
  2134. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2135. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2136. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2137. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2138. print '</table>' . "\n";
  2139. print '</td></tr></table>' . "\n";
  2140. print $OUTPUT->box_end();
  2141. print $OUTPUT->box_start();
  2142. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2143. print '<td width=60% valign="top">' . "\n";
  2144. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2145. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2146. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2147. $resp = get_string('yes');
  2148. else
  2149. $resp = get_string('no');
  2150. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2151. if ($iassign_statement_activity_item->show_answer == 1)
  2152. $resp = get_string('yes');
  2153. else
  2154. $resp = get_string('no');
  2155. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2156. print '</td>';
  2157. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2158. print '<td width=40% valign="top" align="left">';
  2159. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2160. // check status of solution sent by the student
  2161. if ($iassign_submission) {
  2162. switch ($iassign_submission->status) {
  2163. case 3 :
  2164. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2165. break;
  2166. case 2 :
  2167. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2168. break;
  2169. case 1 :
  2170. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2171. break;
  2172. default :
  2173. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2174. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2175. } // switch ($iassign_submission->status)
  2176. }
  2177. else { // if ($iassign_submission)
  2178. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2179. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2180. }
  2181. // update_status
  2182. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2183. $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);
  2184. print " <script type='text/javascript'>
  2185. //<![CDATA[
  2186. function overwriteStatus (newstatus) {
  2187. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2188. document.formEditStatus.return_status.value=newstatus;
  2189. document.formEditStatus.submit();
  2190. }
  2191. else
  2192. document.formEditStatus.return_status.value=-1;
  2193. }
  2194. //]]>
  2195. </script>";
  2196. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2197. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2198. 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";
  2199. print " <input type='hidden' name='return_status'>\n";
  2200. print "</form>\n";
  2201. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2202. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2203. $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);
  2204. print "
  2205. <script type='text/javascript'>
  2206. //<![CDATA[
  2207. function overwriteGrade (newgrade,maxgrade) {
  2208. if (newgrade<0 || newgrade>maxgrade) {
  2209. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2210. document.formEditGrade.return_grade.value=-1;
  2211. document.formEditGrade.submit();
  2212. }
  2213. else {
  2214. document.formEditGrade.return_grade.value=newgrade;
  2215. document.formEditGrade.submit();
  2216. }
  2217. }
  2218. //]]>
  2219. </script>";
  2220. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2221. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2222. print " <input type='text' name='grade' size='6'>";
  2223. print " <input type='hidden' name='return_grade'> ";
  2224. 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";
  2225. print "</form>";
  2226. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2227. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2228. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2229. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2230. if ($teacher)
  2231. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2232. } // if ($iassign_submission->experiment > 0)
  2233. print '</td>';
  2234. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2235. print '</tr></table>';
  2236. print $OUTPUT->box_end();
  2237. $USER->iassignEdit = $this->bottonPost;
  2238. if ($iassign_submission && $allow_resubmission) {
  2239. // Put the iLM to
  2240. print $OUTPUT->box_start();
  2241. print '<p><strong>' . $last_iassign . '</strong></p>';
  2242. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2243. $enderecoPOST = "";
  2244. // Prepare tags to present the iLM
  2245. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2246. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2247. print $OUTPUT->box_end();
  2248. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2249. // ATTENTION: exception used by iGeom (exercise with "script")
  2250. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2251. if (substr($ilm_name, 0, 5)=="igeom") {
  2252. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2253. $loadTeacherActivity = true;
  2254. }
  2255. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2256. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2257. // Prepare tags to present the iLM
  2258. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2259. }
  2260. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2261. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2262. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2263. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2264. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2265. // *** (end) Teacher access (view learner's submission to the activity)
  2266. // *** Student access (view the activity)
  2267. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2268. // It could be the learner (he could send or resend the activity)
  2269. // ---> access student
  2270. $time_now = time();
  2271. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2272. // activity of type example - not submit button for submission
  2273. $this->view_iassign = true;
  2274. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2275. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2276. // activity of type test - iLM automatic evaluator - submit button for submission
  2277. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2278. $this->bottonPost = 1;
  2279. $this->view_iassign = true;
  2280. } else
  2281. $this->view_iassign = false;
  2282. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2283. // activity of type exercise (learner can send his answer, if yet open...)
  2284. $this->view_iassign = true;
  2285. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2286. $this->view_iassign = false;
  2287. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2288. $this->bottonPost = 1; // allow the submit button
  2289. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2290. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2291. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2292. if (!$iassign_submission) {
  2293. $str_iassign_submission_id = '';
  2294. $str_iassign_submission_answer = '';
  2295. }
  2296. else {
  2297. $str_iassign_submission_id = $iassign_submission->id;
  2298. $str_iassign_submission_answer = $iassign_submission->answer;
  2299. }
  2300. if ($this->action != 'repeat') {
  2301. $repeat = "<a href='view.php?action=repeat&id="
  2302. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2303. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2304. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2305. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2306. }
  2307. $this->bottonPost = 1;
  2308. $this->write_solution = 1; // can register his submission
  2309. $student_answer = $str_iassign_submission_answer;
  2310. }
  2311. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2312. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2313. $last_iassign = get_string('last_iassign', 'iassign');
  2314. if ($iassign_submission) {
  2315. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2316. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2317. $student_answer = $iassign_submission->answer;
  2318. } else {
  2319. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2320. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2321. }
  2322. }
  2323. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2324. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2325. $this->bottonPost = 1;
  2326. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2327. } else {
  2328. $last_iassign = get_string('last_iassign', 'iassign');
  2329. if ($iassign_submission) {
  2330. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2331. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2332. $student_answer = $iassign_submission->answer;
  2333. } else {
  2334. // Symbol of "redo activity"
  2335. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2336. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2337. }
  2338. }
  2339. } // elseif ($iassign_statement_activity_item->test == 1)
  2340. elseif ($iassign_statement_activity_item->test == 0)
  2341. $this->view_iassign = false;
  2342. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2343. if ($iassign_submission)
  2344. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2345. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2346. else
  2347. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2348. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2349. $this->activity->view_dates();
  2350. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2351. print $OUTPUT->box_start();
  2352. print '<table width=100% border=0 valign="top">' . "\n";
  2353. print '<tr><td width=60% valign="top">' . "\n";
  2354. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2355. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2356. $flag_dependency = true;
  2357. if ($iassign_statement_activity_item->type_iassign == 3) {
  2358. if ($iassign_statement_activity_item->dependency == 0) {
  2359. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2360. } else {
  2361. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2362. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2363. foreach ($dependencys as $dependency) {
  2364. if ($dependency) {
  2365. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2366. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2367. if ($dependencysubmissions) {
  2368. if ($dependencysubmissions->status == 3)
  2369. $icon = iassign_icons::insert('correct');
  2370. elseif ($dependencysubmissions->status == 2) {
  2371. $icon = iassign_icons::insert('incorrect');
  2372. $flag_dependency = false;
  2373. } elseif ($dependencysubmissions->status == 1) {
  2374. $icon = iassign_icons::insert('post');
  2375. $flag_dependency = false;
  2376. } elseif ($dependencysubmissions->status == 0) {
  2377. $icon = iassign_icons::insert('not_post');
  2378. $flag_dependency = false;
  2379. }
  2380. } else {
  2381. $icon = iassign_icons::insert('not_post');
  2382. $flag_dependency = false;
  2383. } // if ($dependencysubmissions)
  2384. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2385. } // if ($dependency)
  2386. } // foreach ($dependencys as $dependency)
  2387. } // if ($iassign_statement_activity_item->dependency == 0)
  2388. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2389. if ($flag_dependency == false) {
  2390. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2391. $this->view_iassign = false;
  2392. print '</tr></table>' . "\n";
  2393. }
  2394. else {
  2395. $this->view_iassign = true;
  2396. print '</td>' . "\n";
  2397. } // if ($flag_dependency == false)
  2398. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2399. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2400. // receiver=1 - message to teacher
  2401. // receiver=2 - message to student
  2402. if ($iassign_submission) {
  2403. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2404. if ($verify_message)
  2405. $comment = iassign_icons::insert('comment_unread');
  2406. }
  2407. print '<td width=40% valign="top" align="left">';
  2408. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2409. if ($iassign_statement_activity_item->show_answer == 1) {
  2410. // check status of solution sent by the student
  2411. if ($iassign_submission) {
  2412. switch ($iassign_submission->status) {
  2413. case 3 :
  2414. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2415. break;
  2416. case 2 :
  2417. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2418. break;
  2419. case 1 :
  2420. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2421. break;
  2422. default :
  2423. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2424. $repeat = "";
  2425. $last_iassign = "";
  2426. } // switch ($iassign_submission->status)
  2427. } else {
  2428. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2429. $repeat = "";
  2430. $last_iassign = "";
  2431. }
  2432. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2433. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2434. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2435. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2436. if ($iassign_statement_activity_item->max_experiment == 0)
  2437. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2438. else {
  2439. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2440. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2441. $repeat = "";
  2442. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2443. $this->bottonPost = 0;
  2444. $this->write_solution = 0;
  2445. }
  2446. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2447. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2448. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2449. if ($teacher)
  2450. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2451. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2452. } // if ($iassign_statement_activity_item->show_answer==1)
  2453. else {
  2454. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2455. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2456. $repeat = "";
  2457. $last_iassign = "";
  2458. } elseif ($iassign_submission->status == 1) {
  2459. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2460. }
  2461. }
  2462. print '</td>';
  2463. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2464. print '</tr></table>' . "\n";
  2465. // Presents the iLM
  2466. print '<table width=100% border=0 valign="top">' . "\n";
  2467. print '<td width=80% align="left">';
  2468. 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\".
  2469. print '<td width=20% align="rigth">';
  2470. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2471. print $repeat; // symbol of "redo activity"
  2472. print '</td></tr></table>' . "\n";
  2473. //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)'
  2474. $output = '';
  2475. if (!$iassign_ilm) {
  2476. $iassign_ilm = new stdClass();
  2477. $iassign_ilm->file_jar = "";
  2478. }
  2479. $output .= $OUTPUT->box_start();
  2480. $USER->iassignEdit = $this->bottonPost;
  2481. // ---
  2482. // Presents the iLM
  2483. // Prepare tags to present the iLM
  2484. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2485. $student_answer = ""; //?
  2486. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2487. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2488. $student_answer = "";
  2489. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2490. } else {
  2491. // When student is redoing his activity
  2492. // ATTENTION: exception used by iGeom (exercise with "script")
  2493. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2494. if (substr($ilm_name, 0, 5)=="igeom") {
  2495. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2496. $loadTeacherActivity = true;
  2497. }
  2498. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2499. }
  2500. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2501. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2502. //1 $history_comment = '';
  2503. //1 if ($iassign_submission) {
  2504. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2505. //1 }
  2506. //1 if (!empty($history_comment)) {
  2507. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2508. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2509. //1 $output .= $history_comment;
  2510. //1 $output .= "</table>\n";
  2511. //1 }
  2512. //1 $output .= "</form></center>\n";
  2513. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2514. //1 }
  2515. $output .= $OUTPUT->box_end();
  2516. print $output;
  2517. } // if ($this->view_iassign)
  2518. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2519. } // if ($this->view_iassign)
  2520. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2521. else
  2522. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2523. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2524. print '<table width=100% border=0 valign="top">' . "\n";
  2525. print '<tr><td width=60% valign="top">' . "\n";
  2526. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2527. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2528. print '</tr></table>' . "\n";
  2529. $student_answer = "";
  2530. $enderecoPOST = "";
  2531. // Prepare tags to present the iLM
  2532. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2533. print $output;
  2534. }
  2535. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2536. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2537. 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
  2538. // Put a block with area to sent/answer comments
  2539. $output = '';
  2540. $history_comment = '';
  2541. $row = optional_param('row', 0, PARAM_INT);
  2542. $column = optional_param('column', 0, PARAM_INT);
  2543. if ($iassign_submission) {
  2544. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2545. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2546. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2547. }
  2548. else {
  2549. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2550. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2551. }
  2552. $output .= $OUTPUT->box_start();
  2553. //if (!empty($history_comment)) {
  2554. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2555. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2556. $output .= "</table>";
  2557. print " <script type='text/javascript'>
  2558. //<![CDATA[
  2559. function submit_comment(url) {
  2560. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2561. var formData = new FormData();
  2562. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2563. var request = new XMLHttpRequest();
  2564. request.open('POST', url);
  2565. document.getElementById('comments_history').innerHTML = '';
  2566. request.onload = function (e) {
  2567. if (request.readyState === 4) {
  2568. if (request.status === 200) {
  2569. document.getElementById('comments_history').innerHTML = request.responseText;
  2570. document.getElementById('check-message-success').style.visibility = 'visible';
  2571. setTimeout(function(){
  2572. document.getElementById('check-message-success').style.visibility = 'hidden';
  2573. }, 3000);
  2574. }
  2575. }
  2576. };
  2577. document.formEnvioComment.submission_comment.value = '';
  2578. request.send(formData);
  2579. }
  2580. //]]>
  2581. </script>";
  2582. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2583. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2584. $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";
  2585. $output .= "</form> </center>\n";
  2586. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2587. // }
  2588. $output .= $OUTPUT->box_end();
  2589. print $output;
  2590. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2591. // final block 'studant'
  2592. print $OUTPUT->footer();
  2593. die();
  2594. } // function view_iassign_current()
  2595. /// Export the data from performance report into CSV file format
  2596. function export_csv () {
  2597. global $USER, $CFG, $DB, $OUTPUT;
  2598. $str = "";
  2599. $fields = "student_id, student_name";
  2600. // Finding all iassign activities for the iassign:
  2601. $id = $this->cm->id;
  2602. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2603. $c = 1;
  2604. foreach ($iassign_list as $iassign) {
  2605. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2606. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2607. $c ++;
  2608. }
  2609. // Finding enrolled students:
  2610. $params = array('shortname' => 'student');
  2611. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2612. $context = context_course::instance($this->course->id);
  2613. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2614. $students = $DB->get_records_sql(
  2615. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2616. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2617. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2618. foreach ($students as $student) {
  2619. $str .= $student->userid . ',';
  2620. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2621. foreach ($iassign_list as $iassign) {
  2622. $str .= ',' . $iassign->id . ',';
  2623. $str .= '"' . $iassign->name . '",';
  2624. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2625. if ($student_submissions) {
  2626. $str .= $student_submissions->experiment . ',';
  2627. $str .= $student_submissions->grade . ',';
  2628. switch ($student_submissions->status) {
  2629. case 3:
  2630. $str .= '"correct",';
  2631. break;
  2632. case 2:
  2633. $str .= '"incorrect",';
  2634. break;
  2635. case 1:
  2636. $str .= '"post",';
  2637. break;
  2638. case 0:
  2639. $str .= '"not_post",';
  2640. break;
  2641. }
  2642. }
  2643. else {
  2644. $str .= ',,"not_post",';
  2645. }
  2646. $str .= $iassign->iassign_ilmid . ',';
  2647. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2648. $str .= '"' . $ilm_activity->name . '"';
  2649. }
  2650. $str .= "\n";
  2651. }
  2652. $str = $fields . "\n" . $str;
  2653. header("Content-type: text/csv");
  2654. header("Content-disposition: attachment; filename=report.csv");
  2655. header("Pragma: no-cache");
  2656. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2657. header('Content-Length: ' . strlen($str));
  2658. header('Connection: close');
  2659. print $str;
  2660. flush();
  2661. } // function export_csv()
  2662. /// Display report of performance
  2663. function report () {
  2664. global $USER, $CFG, $DB, $OUTPUT;
  2665. $id = $this->cm->id;
  2666. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2667. if ($this->action != 'print') {
  2668. $title = get_string('report', 'iassign');
  2669. print $OUTPUT->header();
  2670. } // if ($this->action != 'print')
  2671. print $OUTPUT->box_start();
  2672. $this->view_legend_icons();
  2673. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2674. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2675. print $OUTPUT->box_end();
  2676. if ($this->action == 'print')
  2677. print '<table border=1 width="100%">' . "\n";
  2678. else
  2679. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped" width="100%">' . "\n";
  2680. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2681. // $num = array();
  2682. $i = 1;
  2683. $num = array();
  2684. $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;";
  2685. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2686. $test_exercise = "";
  2687. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2688. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2689. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2690. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2691. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2692. $num[$i] = new stdClass();
  2693. $num[$i]->name = $iassign->name;
  2694. $num[$i]->id = $i;
  2695. $num[$i]->iassignid = $iassign->id;
  2696. print ' <tr >' . "\n";
  2697. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2698. print "<td class=\"cell c0 actvity\">";
  2699. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2700. print ' </tr>' . "\n";
  2701. $i++;
  2702. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2703. } // foreach ($iassign_list as $iassign)
  2704. $num_exerc = $i; // total of exercises
  2705. print "</table>";
  2706. print "<p></p>";
  2707. if ($this->action == 'print')
  2708. print '<table border=1 width="100%">' . "\n";
  2709. else // ./theme/boost/style/moodle.css: .generaltable
  2710. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2711. $context = context_course::instance($this->course->id);
  2712. if ($num_exerc > 1) {
  2713. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2714. $params = array('shortname' => 'student');
  2715. $role = $DB->get_record_sql(
  2716. "SELECT s.id, s.shortname FROM {role} s " .
  2717. " WHERE s.shortname = :shortname", $params);
  2718. // $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");
  2719. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2720. $students = $DB->get_records_sql(
  2721. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2722. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2723. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2724. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2725. $width = 90/$num_exerc;
  2726. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2727. $sum_iassign_correct[$j] = 0;
  2728. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2729. }
  2730. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2731. $sum_iassign = $j - 1;
  2732. print '</tr>' . "\n";
  2733. $total = 0;
  2734. $sum_student = 0;
  2735. $comment = iassign_icons::insert('comment_read');
  2736. $sum_comment = 0;
  2737. $sum_correct_iassign = array();
  2738. $sum_correct_student = array();
  2739. $USER->matrix_iassign = array();
  2740. if ($students) {
  2741. $w = 0;
  2742. foreach ($students as $tmp) { // count students
  2743. $users_array[$w] = $tmp;
  2744. $w++;
  2745. }
  2746. for ($x=0; $x<$w; $x++) { // for all students
  2747. print '<tr>' . "\n";
  2748. $sum_student ++;
  2749. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2750. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2751. $total_student = 0;
  2752. $tentativas = 0;
  2753. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2754. $sum_comment = $sum_verify_message = 0;
  2755. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2756. if ($student_submissions) {
  2757. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2758. $tentativas = $student_submissions->experiment;
  2759. // Get student comments
  2760. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2761. $params = array('iassign_submissionid' => $student_submissions->id);
  2762. $student_submissions_comment = $DB->get_record_sql(
  2763. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2764. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2765. if ($student_submissions_comment) // student has comment
  2766. foreach ($student_submissions_comment as $tmp)
  2767. $sum_comment = $tmp;
  2768. // informations to previous activities
  2769. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2770. else $iassign_previous = $num[$j - 1]->iassignid;
  2771. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2772. else $user_previous = $users_array[$x - 1]->userid;
  2773. // next
  2774. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2775. else $iassign_next = "-1";
  2776. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2777. else $user_next = "-1";
  2778. $position = "&row= $x&column=$j";
  2779. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2780. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2781. $url .= $position;
  2782. // receiver=1 - message to teacher
  2783. // receiver=2 - message to student
  2784. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2785. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2786. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2787. $verify_message = $DB->get_record_sql(
  2788. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2789. "WHERE iassign_submissionid = :iassign_submissionid " .
  2790. " AND return_status= :return_status " .
  2791. " AND receiver= :receiver", $params);
  2792. if ($verify_message)
  2793. foreach ($verify_message as $tmp)
  2794. $sum_verify_message = $tmp;
  2795. if ($sum_verify_message > 0)
  2796. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2797. else
  2798. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2799. if ($student_submissions->status == 3) {
  2800. $sum_iassign_correct[$j] ++;
  2801. $total_student ++;
  2802. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  2803. }
  2804. elseif ($student_submissions->status == 2) {
  2805. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  2806. }
  2807. elseif ($student_submissions->status == 1) {
  2808. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2809. }
  2810. elseif ($student_submissions->status == 0) {
  2811. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2812. }
  2813. if ($this->action != 'print') {
  2814. if ($tentativas > 0)
  2815. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2816. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2817. . $feedback
  2818. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2819. . $tentativas
  2820. . '</span> </button>'
  2821. . '</a>' . "\n";
  2822. else
  2823. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  2824. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2825. . $feedback
  2826. .'</button>'
  2827. . '</a>' . "\n";
  2828. if ($sum_comment > 0 && $sum_verify_message > 0)
  2829. print '<a href="' . $url . '"> '
  2830. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2831. . $comment
  2832. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2833. . $sum_verify_message . '/' . $sum_comment
  2834. . '</span> </button>'
  2835. . '</a>';
  2836. else if ($sum_comment > 0)
  2837. print '<a href="' . $url . '"> '
  2838. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  2839. . $comment
  2840. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  2841. . $sum_comment
  2842. . '</span> </button>'
  2843. . '</a>';
  2844. print '</td>' . "\n";
  2845. }
  2846. if ($this->action == 'print')
  2847. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2848. } // if ($student_submissions)
  2849. else { // if ($student_submissions)
  2850. // Student does not have any submission
  2851. // informations to browse previous activities
  2852. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  2853. else $iassign_previous = $num[$j - 1]->iassignid;
  2854. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2855. else $user_previous = $users_array[$x - 1]->userid;
  2856. // next
  2857. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2858. else $iassign_next = "-1";
  2859. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2860. else $user_next = "-1";
  2861. $position = "&row= $x&column=$j";
  2862. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2863. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2864. $url .= $position;
  2865. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  2866. if ($this->action == 'print')
  2867. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2868. else {
  2869. print '<td style="text-align: center;"> <a href="' . $url . '">'
  2870. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  2871. . $feedback
  2872. .'</button>'
  2873. . '</a>' . "\n";
  2874. // print '<td> &nbsp;</td>';
  2875. if ($sum_comment > 0)
  2876. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  2877. // else print '<td> &nbsp;</td>';
  2878. print '</td>';
  2879. }
  2880. } // else if ($student_submissions)
  2881. $USER->matrix_iassign[$x][$j] = new stdClass();
  2882. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2883. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2884. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2885. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2886. if ($student_submissions)
  2887. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2888. else
  2889. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2890. //print '</td>' . "\n";
  2891. } // for ($j=1; $j<$num_exerc; $j++)
  2892. $total = $total + $total_student;
  2893. $porcentagem = ($total_student / ($j - 1)) * 100;
  2894. if ($tentativas != 0 && $tentativas != null) {
  2895. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2896. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2897. }
  2898. else {
  2899. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2900. }
  2901. print '</tr>' . "\n";
  2902. $sum_correct_student[$sum_student] = new stdClass();
  2903. $sum_correct_student[$sum_student]->name = $name;
  2904. $sum_correct_student[$sum_student]->sum = $total_student;
  2905. } // for ($x = 0; $x < $w; $x ++)
  2906. for ($i = 1; $i < $j; $i ++) {
  2907. if (is_null($sum_iassign_correct[$i]))
  2908. $sum_iassign_correct[$i] = 0;
  2909. $sum_correct_iassign[$i] = new stdClass();
  2910. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2911. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2912. }
  2913. // print '</tr></table>' . "\n";
  2914. }
  2915. } // if ($i>1)
  2916. else {
  2917. print_string('no_activity', 'iassign');
  2918. }
  2919. print "</table>\n";
  2920. if ($this->action != 'print')
  2921. print $OUTPUT->footer();
  2922. die();
  2923. } // function report()
  2924. /// Display graphics of performance
  2925. function stats () {
  2926. global $USER, $CFG, $DB, $OUTPUT;
  2927. $id = $this->cm->id;
  2928. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2929. if ($this->action != 'printstats')
  2930. $title = get_string('graphic', 'iassign');
  2931. $num = array();
  2932. $sum_correct_iassign = array();
  2933. $sum_correct_student = array();
  2934. $sum_student = 0;
  2935. $i = 1;
  2936. foreach ($iassign_list as $iassign) {
  2937. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2938. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2939. $sum_iassign_correct[$i] = 0;
  2940. $num[$i] = new stdClass();
  2941. $num[$i]->name = $iassign->name;
  2942. $num[$i]->id = $i;
  2943. $num[$i]->iassignid = $iassign->id;
  2944. $i ++;
  2945. } // if ($iassign->type_iassign == 3)
  2946. } // foreach ($iassign_list as $iassign)
  2947. $sum_iassign = $i - 1;
  2948. $context = context_course::instance($this->course->id);
  2949. if ($i > 1) {
  2950. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2951. $params = array('shortname' => 'student');
  2952. $role = $DB->get_record_sql(
  2953. "SELECT s.id, s.shortname FROM {role} s " .
  2954. " WHERE s.shortname = :shortname", $params);
  2955. // $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");
  2956. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2957. $students = $DB->get_records_sql(
  2958. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2959. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2960. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2961. $total = 0;
  2962. $sum_student = 0;
  2963. $j = 0;
  2964. $sum_correct_iassign = array();
  2965. $sum_correct_student = array();
  2966. $sum_experiment = array();
  2967. if ($students) {
  2968. foreach ($students as $users) {
  2969. $sum_student ++;
  2970. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2971. // rows
  2972. $total_student = 0;
  2973. for ($j = 1; $j < $i; $j ++) {
  2974. $total_experiment = 0;
  2975. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2976. if ($student_submissions) {
  2977. if ($student_submissions->status == 3) {
  2978. $sum_iassign_correct[$j] ++;
  2979. $total_student ++;
  2980. } // if ($student_submissions->status == 3)
  2981. $total_experiment += $student_submissions->experiment;
  2982. }
  2983. $sum_experiment[$j] = $total_experiment;
  2984. } // for ($j=1; $j<$i; $j++)
  2985. $total = $total + $total_student;
  2986. $sum_correct_student[$sum_student] = new stdClass();
  2987. $sum_correct_student[$sum_student]->name = $name;
  2988. $sum_correct_student[$sum_student]->sum = $total_student;
  2989. } // foreach ($students as $users)
  2990. }
  2991. for ($i = 1; $i < $j; $i ++) {
  2992. if (is_null($sum_iassign_correct[$i]))
  2993. $sum_iassign_correct[$i] = 0;
  2994. $sum_correct_iassign[$i] = new stdClass();
  2995. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2996. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2997. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2998. } // for ($i = 1; $i < $j; $i++)
  2999. } // if ($i > 1)
  3000. if ($this->action != 'printstats') {
  3001. $title = get_string('graphic', 'iassign');
  3002. print $OUTPUT->header();
  3003. $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>";
  3004. $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>";
  3005. print '<table width=100%><tr>';
  3006. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3007. print '<td width=15% align="right">' . $link_report . '</td>';
  3008. print '</td></tr></table>' . "\n";
  3009. print "<br><br>";
  3010. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3011. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3012. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3013. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3014. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3015. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3016. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3017. print '</tr>' . "\n";
  3018. $sum_correct = 0;
  3019. if ($sum_correct_iassign) {
  3020. foreach ($sum_correct_iassign as $iassign) {
  3021. if (is_null($iassign->experiment))
  3022. $iassign->experiment = 0;
  3023. $bar = "";
  3024. $sum = $iassign->sum;
  3025. $percent = ($sum / $sum_student) * 100;
  3026. $text = number_format($percent, 1) . '%';
  3027. $sum_correct += $sum;
  3028. if ($sum > 0) {
  3029. for ($i = 1; $i < $percent * 2; $i ++)
  3030. $bar .= iassign_icons::insert('hbar_blue');
  3031. $bar .= iassign_icons::insert('hbar_blue_r');
  3032. } // if ($sum > 0)
  3033. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3034. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3035. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3036. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3037. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3038. print '</tr>' . "\n";
  3039. } // foreach ($sum_correct_iassign as $iassign)
  3040. }
  3041. print "</table>";
  3042. print "<br><br>";
  3043. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3044. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3045. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3046. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3047. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3048. print '</tr>' . "\n";
  3049. $sum_correct = 0;
  3050. foreach ($sum_correct_student as $student) {
  3051. $bar = "";
  3052. $sum = $student->sum;
  3053. $percent = ($sum / $sum_iassign) * 100;
  3054. $text = number_format($percent, 1) . '%';
  3055. $sum_correct += $sum;
  3056. if ($sum > 0) {
  3057. for ($i = 1; $i < $percent * 2; $i ++)
  3058. $bar .= iassign_icons::insert('hbar_blue');
  3059. $bar .= iassign_icons::insert('hbar_blue_r');
  3060. } // if ($sum > 0)
  3061. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3062. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3063. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3064. print '</tr>' . "\n";
  3065. } // foreach ($sum_correct_student as $student)
  3066. print "</table>\n";
  3067. print "<br><br>\n";
  3068. $var = 0;
  3069. $cv = 0;
  3070. $dv = 0;
  3071. $avg = 0;
  3072. if ($sum_correct_student) {
  3073. $avg = $sum_correct / $sum_student;
  3074. if ($avg > 0) {
  3075. foreach ($sum_correct_student as $student)
  3076. $var += pow($student->sum - $avg, 2);
  3077. $var = $var / $sum_student;
  3078. $dv = sqrt($var);
  3079. $cv = ($dv / $avg) * 100;
  3080. }
  3081. }
  3082. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3083. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3084. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3085. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3086. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3087. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3088. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3089. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3090. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3091. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3092. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3093. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3094. print "</table>\n";
  3095. print $OUTPUT->footer();
  3096. } else {
  3097. print "<STYLE TYPE='text/css'>
  3098. <!--
  3099. .boldtable {
  3100. font-family:sans-serif;
  3101. font-size:10pt;
  3102. }
  3103. -->
  3104. </STYLE>\n";
  3105. print '<table border=1 width=100%>' . "\n";
  3106. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3107. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3108. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3109. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3110. print '</tr>' . "\n";
  3111. $sum_correct = 0;
  3112. foreach ($sum_correct_iassign as $iassign) {
  3113. $bar = "";
  3114. $sum = $iassign->sum;
  3115. $percent = ($sum / $sum_student) * 100;
  3116. $text = number_format($percent, 1) . '%';
  3117. $sum_correct += $sum;
  3118. if ($sum > 0) {
  3119. for ($i = 1; $i < $percent * 2; $i ++)
  3120. $bar .= iassign_icons::insert('hbar_blue');
  3121. $bar .= iassign_icons::insert('hbar_blue_r');
  3122. } // if ($sum > 0)
  3123. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3124. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3125. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3126. print '</tr>' . "\n";
  3127. } // foreach ($sum_correct_iassign as $iassign)
  3128. print "</table>";
  3129. print "<br><br>";
  3130. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3131. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3132. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3133. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3134. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3135. print '</tr>' . "\n";
  3136. $sum_correct = 0;
  3137. foreach ($sum_correct_student as $student) {
  3138. $bar = "";
  3139. $sum = $student->sum;
  3140. $percent = ($sum / $sum_iassign) * 100;
  3141. $text = number_format($percent, 1) . '%';
  3142. $sum_correct += $sum;
  3143. if ($sum > 0) {
  3144. for ($i = 1; $i < $percent * 2; $i ++)
  3145. $bar .= iassign_icons::insert('hbar_blue');
  3146. $bar .= iassign_icons::insert('hbar_blue_r');
  3147. } // if ($sum > 0)
  3148. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3149. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3150. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3151. print '</tr>' . "\n";
  3152. } // foreach ($sum_correct_student as $student)
  3153. print "</table>\n";
  3154. print "<br/><br/>\n";
  3155. $var = 0;
  3156. $cv = 0;
  3157. $dv = 0;
  3158. $avg = 0;
  3159. if ($sum_correct_student) {
  3160. $avg = $sum_correct / $sum_student;
  3161. if ($avg > 0) {
  3162. foreach ($sum_correct_student as $student)
  3163. $var += pow($student->sum - $avg, 2);
  3164. $var = $var / $sum_student;
  3165. $dv = sqrt($var);
  3166. $cv = ($dv / $avg) * 100;
  3167. }
  3168. }
  3169. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3170. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3171. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3172. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3173. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3174. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3175. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3176. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3177. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3178. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3179. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3180. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3181. print "</table>\n";
  3182. } // if ($this->action != 'printstats')
  3183. die();
  3184. }
  3185. /// Display graphics of performance for students
  3186. function stats_students () {
  3187. global $USER, $CFG, $DB, $OUTPUT;
  3188. $id = $this->cm->id;
  3189. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3190. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3191. $title = get_string('results', 'iassign');
  3192. $sum_correct = 0;
  3193. $sum_incorrect = 0;
  3194. $sum_post = 0;
  3195. $sum_nopost = 0;
  3196. $sum_iassign = count($iassign_statement_list);
  3197. $bar_nopost = "";
  3198. $bar_correct = "";
  3199. $bar_incorrect = "";
  3200. $bar_post = "";
  3201. $text_nopost = "";
  3202. $text_correct = "";
  3203. $text_incorrect = "";
  3204. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3205. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3206. if ($iassign_submission) {
  3207. if ($iassign_submission->status == 3)
  3208. $sum_correct ++;
  3209. elseif ($iassign_submission->status == 2)
  3210. $sum_incorrect ++;
  3211. elseif ($iassign_submission->status == 1)
  3212. $sum_post ++;
  3213. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3214. $sum_nopost ++;
  3215. } // if ($iassign_submission)
  3216. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3217. if ($sum_iassign > 0) {
  3218. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3219. $text_correct = number_format($percent_correct, 1) . '%';
  3220. }
  3221. if ($sum_correct > 0) {
  3222. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3223. $bar_correct .= iassign_icons::insert('hbar_green');
  3224. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3225. } // if ($sum_correct > 0)
  3226. if ($sum_iassign > 0) {
  3227. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3228. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3229. }
  3230. if ($sum_incorrect > 0) {
  3231. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3232. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3233. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3234. } // if ($sum_incorrect > 0)
  3235. if ($sum_iassign > 0) {
  3236. $percent_post = ($sum_post / $sum_iassign) * 100;
  3237. $text_post = number_format($percent_post, 1) . '%';
  3238. }
  3239. if ($sum_post > 0) {
  3240. for ($i = 1; $i < $percent_post * 2; $i ++)
  3241. $bar_post .= iassign_icons::insert('hbar_blue');
  3242. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3243. } // if ($sum_post > 0)
  3244. if ($sum_iassign > 0) {
  3245. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3246. $text_nopost = number_format($percent_nopost, 1) . '%';
  3247. }
  3248. if ($sum_nopost > 0) {
  3249. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3250. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3251. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3252. } // if ($sum_nopost > 0)
  3253. print $OUTPUT->header();
  3254. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3255. print '<table width=100%><tr>';
  3256. print '<td align="right">' . $link_return . '</td>' . "\n";
  3257. print '</td></tr></table>' . "\n";
  3258. print "<br/><br/>\n";
  3259. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3260. print '<tr><th colspan=3 class="header c1">' . "\n";
  3261. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3262. // $imagetext = '');
  3263. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3264. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3265. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3266. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3267. print '</tr>' . "\n";
  3268. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3269. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3270. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3271. print '</tr>' . "\n";
  3272. if ($sum_post) {
  3273. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3274. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3275. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3276. print '</tr>' . "\n";
  3277. } // if ($sum_post)
  3278. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3279. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3280. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3281. print '</tr>' . "\n";
  3282. print "</table>";
  3283. print "<br><br>";
  3284. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3285. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3286. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3287. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3288. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3289. $sum_grade = 0;
  3290. $sum_grade_student = 0;
  3291. $avg = 0;
  3292. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3293. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3294. if (!$iassign_submission) {
  3295. $iassign_submission = new stdClass();
  3296. $iassign_submission->grade = 0;
  3297. }
  3298. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3299. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3300. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3301. print '</tr>' . "\n";
  3302. $sum_grade += $iassign_statement_activity_item->grade;
  3303. $sum_grade_student += $iassign_submission->grade;
  3304. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3305. if ($sum_grade > 0)
  3306. $avg = $sum_grade_student / $sum_grade * 100;
  3307. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3308. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3309. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3310. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3311. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3312. print "</table>";
  3313. print $OUTPUT->footer();
  3314. die();
  3315. } // function stats_students()
  3316. /// Display page of iAssign's activity
  3317. function view_iassigns () {
  3318. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3319. $id = $this->cm->id;
  3320. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3321. $notice = optional_param('notice', '', PARAM_TEXT);
  3322. if (strpos($notice, 'error'))
  3323. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3324. else if ($notice != '')
  3325. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3326. print $OUTPUT->box_start();
  3327. print '<table width=100% border=0><tr>' . "\n";
  3328. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3329. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3330. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3331. $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>";
  3332. $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>";
  3333. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3334. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3335. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3336. // Has capability to see "report": teacher or up
  3337. print '<td width=10% align="left">' . "\n";
  3338. print $link_help;
  3339. print '</td>' . "\n";
  3340. print '<td width=10% align="left">' . "\n";
  3341. print $link_report;
  3342. print '</td>' . "\n";
  3343. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3344. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3345. print '<td width=15% align="left">' . "\n";
  3346. print $link_add;
  3347. print "</td>\n";
  3348. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3349. //print '</tr></table>' . "\n";
  3350. print '<div style="float: right;">';
  3351. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3352. if ($iassign_list) {
  3353. print '<td align="right">' . "\n";
  3354. // $USER->iassignEdit == 0 view 'Turn editing off'
  3355. // $USER->iassignEdit == 1 view 'Turn editing on'
  3356. if (!isset($USER->iassignEdit))
  3357. $USER->iassignEdit = 0;
  3358. if ($USER->iassignEdit == 0) {
  3359. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3360. $botton = 1;
  3361. } // if ($USER->iassignEdit == 0)
  3362. elseif ($USER->iassignEdit == 1) {
  3363. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3364. $botton = 0;
  3365. } // elseif ($USER->iassignEdit == 1)
  3366. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3367. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3368. print " <input type=submit value='$bottonEdit_message'/>\n";
  3369. print "</form>\n";
  3370. print "</td>\n";
  3371. } // if ($iassign_list)
  3372. }
  3373. print '</tr></table>' . "\n";
  3374. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3375. // $this->view_legend_icons();
  3376. print $OUTPUT->box_end();
  3377. $iassign_array_exercise = array();
  3378. $i_exercise = 0;
  3379. $iassign_array_test = array();
  3380. $i_test = 0;
  3381. $iassign_array_example = array();
  3382. $i_example = 0;
  3383. $iassign_array_general = array();
  3384. $i_general = 0;
  3385. if ($iassign_list) {
  3386. if ($this->iassign->activity_group == 0) {
  3387. foreach ($iassign_list as $iassign) {
  3388. $iassign_array_general[$i_general] = $iassign;
  3389. $i_general ++;
  3390. }
  3391. } // if ($this->iassign->activity_group == 0)
  3392. else {
  3393. foreach ($iassign_list as $iassign) {
  3394. if ($iassign->type_iassign == 3) {
  3395. $iassign_array_exercise[$i_exercise] = $iassign;
  3396. $i_exercise ++;
  3397. } // if ($iassign->type_iassign == 3)
  3398. if ($iassign->type_iassign == 2) {
  3399. $iassign_array_test[$i_test] = $iassign;
  3400. $i_test ++;
  3401. } // if ($iassign->type_iassign == 2)
  3402. if ($iassign->type_iassign == 1) {
  3403. $iassign_array_example[$i_example] = $iassign;
  3404. $i_example ++;
  3405. } // if ($iassign->type_iassign == 1)
  3406. }
  3407. }
  3408. if ($iassign_array_exercise) {
  3409. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3410. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3411. }
  3412. if ($iassign_array_test) {
  3413. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3414. $this->show_iassign($title, $iassign_array_test, $i_test);
  3415. }
  3416. if ($iassign_array_example) {
  3417. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3418. $this->show_iassign($title, $iassign_array_example, $i_example);
  3419. }
  3420. if ($iassign_array_general) {
  3421. $title = "";
  3422. $this->show_iassign($title, $iassign_array_general, $i_general);
  3423. }
  3424. } else { // if ($iassign_list)
  3425. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3426. }
  3427. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3428. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3429. print $OUTPUT->box_start();
  3430. print '<table width=100% border=0><tr>' . "\n";
  3431. print '<td width=10% align="left">' . "\n";
  3432. print $link_report;
  3433. print '</td>' . "\n";
  3434. print '</tr></table>' . "\n";
  3435. print $OUTPUT->box_end();
  3436. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3437. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3438. print $OUTPUT->box_start();
  3439. print '<table width=100% border=0><tr>' . "\n";
  3440. print '<td align="left">' . "\n";
  3441. print $link_add;
  3442. print '</td>' . "\n";
  3443. print '</tr></table>' . "\n";
  3444. print $OUTPUT->box_end();
  3445. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3446. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3447. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3448. $this->view_legend_icons();
  3449. } // function view_iassigns()
  3450. /// Display all iAssigns
  3451. function show_iassign ($title, $iassign_array, $i) {
  3452. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3453. $id = $this->cm->id;
  3454. print $OUTPUT->box_start();
  3455. print " <script type='text/javascript'>
  3456. //<![CDATA[
  3457. function validate_move () {
  3458. var radios = document.getElementsByName('iassign_destiny');
  3459. var formValid = false;
  3460. //alert('aqui validate_move()');
  3461. var i = 0;
  3462. while (!formValid && i < radios.length) {
  3463. if (radios[i].checked) formValid = true;
  3464. i++;
  3465. }
  3466. if (!formValid) {
  3467. document.getElementById('move_dest').classList.add('alert-danger');
  3468. }
  3469. return formValid;
  3470. }
  3471. var modal;
  3472. function load_move(id_ias) {
  3473. document.form_move_activity.iassign_current.value = id_ias;
  3474. modal.style.display = 'block';
  3475. var radios = document.getElementsByName('iassign_destiny');
  3476. var i = 0;
  3477. while (i < radios.length) {
  3478. radios[i].checked = false;
  3479. i++;
  3480. }
  3481. document.getElementById('move_dest').classList.remove('alert-danger');
  3482. }
  3483. function load_modal_elements() {
  3484. modal = document.getElementById('myModal');
  3485. var span = document.getElementById('close_modal');
  3486. span.onclick = function() {
  3487. modal.style.display = 'none';
  3488. }
  3489. window.onclick = function(event) {
  3490. if (event.target == modal) {
  3491. modal.style.display = 'none';
  3492. }
  3493. }
  3494. }
  3495. window.onload = load_modal_elements;
  3496. //]]>
  3497. </script>\n";
  3498. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3499. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3500. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3501. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3502. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3503. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3504. <input type='hidden' name='iassign_current' value='' />";
  3505. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3506. $section = $course_sections[0];
  3507. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3508. for ($k = 0; $k < count($ids_sections); $k++) {
  3509. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3510. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3511. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3512. if ($c_cm) {
  3513. if ($ccm->instance == $c_cm->instance) {
  3514. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3515. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3516. }
  3517. else {
  3518. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3519. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3520. }
  3521. }
  3522. }
  3523. $radio_buttons .= "</ul>";
  3524. }
  3525. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3526. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3527. </form>
  3528. </div></div> </div></div>\n";
  3529. print " <style>.modal {
  3530. display: none;
  3531. position: fixed;
  3532. z-index: 1;
  3533. left: 0;
  3534. top: 0;
  3535. width: 100%;
  3536. height: 100%;
  3537. overflow: scroll;
  3538. background-color: rgb(0,0,0);
  3539. background-color: rgba(0,0,0,0.4);
  3540. }
  3541. .modal-content {
  3542. background-color: #fefefe;
  3543. margin: 15% auto;
  3544. padding: 10px 10px;
  3545. border: 1px solid #888;
  3546. width: 50%;
  3547. }
  3548. #close_modal {
  3549. color: #aaa;
  3550. float: right;
  3551. font-size: 28px;
  3552. font-weight: bold;
  3553. margin-top: -15px;
  3554. margin-right: -3px;
  3555. }
  3556. #close_modal:hover,
  3557. #close_modal:focus {
  3558. color: black;
  3559. text-decoration: none;
  3560. cursor: pointer;
  3561. }
  3562. #modal_title {
  3563. min-height: 3rem;
  3564. color: initial;
  3565. background: initial;
  3566. font-size: 1.5rem;
  3567. line-height: 1.5;
  3568. padding: 15px;
  3569. border-bottom: 1px solid #e5e5e5;
  3570. }
  3571. .input_move {
  3572. width: 90%;
  3573. padding: 2px;
  3574. }
  3575. .input_move:hover {
  3576. background: #eff0ef;
  3577. }
  3578. </style>";
  3579. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3580. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3581. for ($j = 0; $j < $i; $j ++) {
  3582. $iassign_current = $iassign_array[$j]->id;
  3583. // receiver=1 - message to teacher
  3584. // receiver=2 - message to student
  3585. $sum_comment = 0;
  3586. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3587. foreach ($iassign_submissions as $iassign_submission) {
  3588. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3589. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3590. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3591. if ($verify_message)
  3592. foreach ($verify_message as $tmp)
  3593. $sum_comment += $tmp;
  3594. } // foreach ($iassign_submissions as $iassign_submission)
  3595. if ($sum_comment == 0)
  3596. $comment_unread = "";
  3597. else {
  3598. $comment_unread_message = get_string('comment_unread', 'iassign');
  3599. if ($sum_comment == 1)
  3600. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3601. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3602. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3603. }
  3604. if ($j == $i - 1)
  3605. $iassign_down = $iassign_array[$j]->id;
  3606. else
  3607. $iassign_down = $iassign_array[$j + 1]->id;
  3608. if ($j > 0)
  3609. $iassign_up = $iassign_array[$j - 1]->id;
  3610. else
  3611. $iassign_up = $iassign_array[$j]->id;
  3612. if ($iassign_array[$j]->visible == 0)
  3613. $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>";
  3614. else
  3615. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3616. $links .= $comment_unread;
  3617. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3618. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3619. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3620. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3621. if ($j==0) // first activity
  3622. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3623. else
  3624. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3625. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3626. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3627. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3628. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3629. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3630. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3631. if (count($iassign_array) > 1) {
  3632. if ($j == 0)
  3633. $links .= $link_down;
  3634. elseif ($j == $i - 1)
  3635. $links .= $link_up;
  3636. else
  3637. $links .= $link_up . $link_down;
  3638. } // if (count($iassign_array) > 1)
  3639. $links .= $link_edit . $link_delete;
  3640. if ($iassign_array[$j]->visible == 0)
  3641. $links .= $link_visible_show;
  3642. else
  3643. $links .= $link_visible_hide;
  3644. $links .= $link_duplicate_activity . $link_move_activity;
  3645. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3646. print '<p>' . $links . '</p>' . "\n";
  3647. }
  3648. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3649. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3650. print '<table width=100% ><tr>' . "\n";
  3651. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3652. print '</tr></table>' . "\n";
  3653. for ($j = 0; $j < $i; $j ++) {
  3654. $icon_status = "";
  3655. $icon_comment = "";
  3656. if ($iassign_array[$j]->visible == 1) {
  3657. $iassign_current = $iassign_array[$j]->id;
  3658. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3659. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3660. $icon_status = "";
  3661. $icon_comment = "";
  3662. if ($iassign_submission) {
  3663. // receiver=1 - message to teacher
  3664. // receiver=2 - message to student
  3665. // $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");
  3666. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3667. $verify_message = $DB->get_record_sql(
  3668. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3669. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3670. if ($verify_message)
  3671. foreach ($verify_message as $tmp)
  3672. $sum_comment = $tmp;
  3673. if ($sum_comment > 0) {
  3674. $comment_unread_message = get_string('comment_unread', 'iassign');
  3675. if ($sum_comment == 1)
  3676. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3677. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3678. }
  3679. // $icon_comment = iassign_icons::insert('comment_unread');
  3680. if ($iassign_array[$j]->type_iassign == 3) {
  3681. if ($iassign_array[$j]->show_answer == 1) {
  3682. if ($iassign_submission->status == 3)
  3683. $icon_status = iassign_icons::insert('correct');
  3684. elseif ($iassign_submission->status == 2)
  3685. $icon_status = iassign_icons::insert('incorrect');
  3686. elseif ($iassign_submission->status == 1)
  3687. $icon_status = iassign_icons::insert('post');
  3688. elseif ($iassign_submission->status == 0)
  3689. $icon_status = iassign_icons::insert('not_post');
  3690. } // if ($iassign_array[$j]->show_answer==1)
  3691. else {
  3692. if ($iassign_submission->status == 0)
  3693. $icon_status = iassign_icons::insert('not_post');
  3694. else
  3695. $icon_status = iassign_icons::insert('post');
  3696. }
  3697. } // if ($iassign_array[$j]->type_iassign == 3)
  3698. } // if ($iassign_submission)
  3699. elseif ($iassign_array[$j]->type_iassign == 3) {
  3700. $icon_status = iassign_icons::insert('not_post');
  3701. } // if ($iassign_array[$j]->type_iassign == 3)
  3702. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3703. } // if ($iassign_array[$j]->visible == 1)
  3704. } // for ($j = 0; $j < $i; $j++)
  3705. } else if (isguestuser()) {
  3706. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3707. print '<table width=100% ><tr>' . "\n";
  3708. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3709. print '</tr></table>' . "\n";
  3710. for ($j = 0; $j < $i; $j ++) {
  3711. $icon_status = "";
  3712. $icon_comment = "";
  3713. if ($iassign_array[$j]->visible == 1) {
  3714. $iassign_current = $iassign_array[$j]->id;
  3715. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3716. print '<p>' . $links . '</p>' . "\n";
  3717. } // if ($iassign_array[$j]->visible == 1)
  3718. }
  3719. }
  3720. print $OUTPUT->box_end();
  3721. } // function show_iassign($title, $iassign_array, $i)
  3722. /// Show message of return
  3723. function return_home_course ($message) {
  3724. //D global $DB, $OUTPUT;
  3725. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3726. //D echo $OUTPUT->box_start();
  3727. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3728. //D echo '<tr><td align="left"><strong>' . "\n";
  3729. //D print_string($message, 'iassign');
  3730. //D echo '</strong></td>' . "\n";
  3731. //D echo '<td width=20% align="right">' . "\n";
  3732. //D echo $link_return;
  3733. //D echo '</td></tr></table>' . "\n";
  3734. //D echo $OUTPUT->box_end();
  3735. //D // echo $OUTPUT->footer();
  3736. redirect(new moodle_url($this->return . '&notice=' . $message));
  3737. exit;
  3738. }
  3739. /// Search comment of activity
  3740. function search_comment_submission ($iassign_submissionid) {
  3741. global $USER, $DB, $OUTPUT, $COURSE;
  3742. // $context = context_course::instance($COURSE->id);
  3743. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3744. $colorEdit2 = "#d2e5fc";
  3745. $has_capability = 0;
  3746. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3747. $text = "";
  3748. if ($comments) {
  3749. $even = 1;
  3750. foreach ($comments as $tmp) {
  3751. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3752. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3753. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3754. // $text .= $tmp->comment . "</td></tr>";
  3755. //} else {
  3756. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3757. $avatar = new user_picture($user_data);
  3758. $avatar->courseid = $COURSE->id;
  3759. $avatar->link = true;
  3760. $user_picture = $OUTPUT->render($avatar);
  3761. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3762. if ($even) {
  3763. $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";
  3764. $even = 0;
  3765. } else {
  3766. $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";
  3767. $even = 1;
  3768. }
  3769. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3770. } // foreach ($comments as $tmp)
  3771. }
  3772. return $text;
  3773. }
  3774. /// Update comment of activity
  3775. function update_comment ($iassign_submissionid) {
  3776. global $USER, $DB, $OUTPUT;
  3777. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3778. $receiver = 1; // student message to teacher
  3779. else
  3780. $receiver = 2; // teacher message to student
  3781. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3782. if ($verify_message) {
  3783. foreach ($verify_message as $message) {
  3784. if ($message->receiver == $receiver) {
  3785. $newentry = new stdClass();
  3786. $newentry->id = $message->id;
  3787. $newentry->return_status = 1;
  3788. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3789. print_error('error_update', 'iassign');
  3790. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3791. } // if ($message->receiver == $receiver)
  3792. // Trigger module viewed event.
  3793. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3794. 'objectid' => $this->iassign->id,
  3795. 'context' => $this->context
  3796. ));
  3797. $event->add_record_snapshot('course', $this->course);
  3798. $event->trigger();
  3799. } // foreach ($verify_message as $message)
  3800. }
  3801. }
  3802. /// Record comment of activity
  3803. function write_comment_submission () {
  3804. global $USER, $CFG, $DB;
  3805. $id = $this->cm->id;
  3806. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3807. $row = optional_param('row', 0, PARAM_INT);
  3808. $column = optional_param('column', 0, PARAM_INT);
  3809. $sum_comment = 0;
  3810. $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);
  3811. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3812. $str1 = trim($submission_comment);
  3813. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3814. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3815. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3816. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3817. $receiver = 1; // student message to teacher
  3818. $this->action = 'view';
  3819. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3820. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3821. } else {
  3822. $receiver = 2; // teacher message to student
  3823. $this->action = 'viewsubmission';
  3824. //D $tousers = array(); //MOOC 2016
  3825. //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
  3826. }
  3827. //MOOC 2016: foi p/ 15 linhas acima:
  3828. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3829. // verificar se existe uma submissão para o exercício e aluno informados
  3830. if (!$iassign_submission) {
  3831. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3832. }
  3833. if (!$iassign_submission) {
  3834. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3835. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3836. $this->iassign_submission_current = $id_submission;
  3837. } else {
  3838. $id_submission = $iassign_submission->id;
  3839. } // if (!$iassign_submission)
  3840. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3841. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3842. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3843. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3844. $comments = $DB->get_record_sql(
  3845. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3846. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3847. if ($comments)
  3848. foreach ($comments as $tmp)
  3849. $sum_comment = $tmp;
  3850. if ($sum_comment == 0) {
  3851. $newentry = new stdClass();
  3852. $newentry->iassign_submissionid = $id_submission;
  3853. $newentry->comment_authorid = $USER->id;
  3854. $newentry->timecreated = time();
  3855. $newentry->comment = $submission_comment;
  3856. $newentry->receiver = $receiver;
  3857. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3858. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3859. //T $eventdata = new stdClass();
  3860. //T $eventdata->component = 'mod_iassign'; //your component name
  3861. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3862. //T $eventdata->userfrom = $USER;
  3863. //T $eventdata->userto = $touser;
  3864. //T $eventdata->subject = "Teste de Subject";
  3865. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3866. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3867. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3868. //T $eventdata->smallmessage = "Teste de Mensagem";
  3869. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3870. //T // alteracao tulio faria
  3871. //T //message_send($eventdata);
  3872. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3873. // Trigger module viewed event.
  3874. $event = \mod_iassign\event\submission_comment_created::create(array(
  3875. 'objectid' => $this->iassign->id,
  3876. 'context' => $this->context
  3877. ));
  3878. $event->add_record_snapshot('course', $this->course);
  3879. $event->trigger();
  3880. }
  3881. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3882. // if ($this->action=='viewsubmission') {
  3883. // echo $OUTPUT->header();
  3884. // $this->return_last('confirm_add_comment', $link_return);
  3885. // die;
  3886. // }
  3887. return true;
  3888. } // function write_comment_submission()
  3889. /// Writes a new submission
  3890. // The first student answer is under 'function get_answer()'
  3891. function new_submission ($iassignid, $id_user, $receiver) {
  3892. global $USER, $DB, $OUTPUT;
  3893. $newentry = new stdClass();
  3894. $newentry->iassign_statementid = $iassignid;
  3895. $newentry->userid = $id_user;
  3896. $newentry->timecreated = time();
  3897. $newentry->timemodified = time();
  3898. $newentry->answer = 0; // student only submit message
  3899. if ($receiver == 2) // teacher message to student (write id teacher)
  3900. $newentry->teacher = $USER->id;
  3901. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3902. return_home_course('error_insert_submissions');
  3903. else {
  3904. // Trigger module view event
  3905. $event = \mod_iassign\event\submission_created::create(array(
  3906. 'objectid' => $this->iassign->id,
  3907. 'context' => $this->context
  3908. ));
  3909. $event->add_record_snapshot('course', $this->course);
  3910. $event->trigger();
  3911. }
  3912. return $newentry->id;
  3913. }
  3914. /// Return to a specific address of page
  3915. function return_last ($message, $link_return) {
  3916. global $DB, $OUTPUT;
  3917. print $OUTPUT->box_start();
  3918. print '<table width=100% border=0 valign="top">' . "\n";
  3919. print '<tr><td align="left"><strong>' . "\n";
  3920. print_string($message, 'iassign');
  3921. print '</strong></td>' . "\n";
  3922. print '<td width=20% align="right">' . "\n";
  3923. print $link_return;
  3924. print '</td></tr></table>' . "\n";
  3925. print $OUTPUT->box_end();
  3926. print $OUTPUT->footer();
  3927. die();
  3928. } // function return_last($message, $link_return)
  3929. } // class iassign
  3930. /// Class for manage activities
  3931. class activity {
  3932. var $activity;
  3933. /// Constructor of class.
  3934. // @param int $id Id of activity
  3935. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3936. //D public function activity($id) { self::__construct($id); }
  3937. function __construct ($id) {
  3938. global $DB;
  3939. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3940. if (empty($this->activity))
  3941. $this->activity = null;
  3942. }
  3943. /// Get an activity
  3944. // @return NULL
  3945. function get_activity () {
  3946. if ($this->activity != null)
  3947. return $this->activity;
  3948. else
  3949. return null;
  3950. }
  3951. /// Delete interactive activities
  3952. function delete ($return) {
  3953. global $USER, $CFG, $DB, $OUTPUT;
  3954. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3955. $output = $OUTPUT->header();
  3956. $output .= $OUTPUT->box_start();
  3957. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3958. if ($iassign_submission_currents) {
  3959. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3960. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3961. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3962. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3963. $output .= $OUTPUT->box_end();
  3964. $output .= $OUTPUT->footer();
  3965. print $output;
  3966. die();
  3967. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3968. } // if ($iassign_submission_currents)
  3969. else
  3970. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3971. $output .= '<table width=50% border=0>';
  3972. $output .= '<tr valign="top"><td>';
  3973. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3974. $output .= '</td><td>';
  3975. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3976. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3977. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3978. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3979. $output .= "</form>\n";
  3980. $output .= '</td><td>';
  3981. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3982. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3983. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3984. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3985. $output .= "</form>\n";
  3986. $output .= '</td></tr></table>' . "\n";
  3987. $output .= $OUTPUT->box_end();
  3988. $output .= $OUTPUT->footer();
  3989. print $output;
  3990. } // function delete($return)
  3991. /// Function for confirm the delete of activity
  3992. // @param String $return Url of return
  3993. // @param Object $iassign Object content an activity
  3994. function deleteyes ($return, $iassign) {
  3995. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3996. $msg = '';
  3997. if (!empty($this->activity->id)) {
  3998. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3999. if ($iassign_submission_currents) {
  4000. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4001. foreach ($iassign_submission_currents as $iassign_submission)
  4002. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4003. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4004. } // if ($iassign_submission_currents)
  4005. }
  4006. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4007. // Remove all files associated to this activity:
  4008. $fs = get_file_storage();
  4009. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4010. $this->delete_calendar($this->activity->id);
  4011. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4012. iassign::update_grade_iassign($this->activity->iassignid);
  4013. if ($delete_iassign_current) {
  4014. $iassign->return_home_course('confirm_delete_iassign');
  4015. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4016. } else {
  4017. $iassign->return_home_course('error_confirm_delete_iassign');
  4018. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4019. }
  4020. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4021. }
  4022. }
  4023. /// Changes position of activities (between those inside a group of interactive activities)
  4024. // @param $move_action = must be "up" or "down"
  4025. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4026. function move_iassign ($move_action, $target, $return) {
  4027. global $DB, $OUTPUT;
  4028. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4029. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4030. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4031. if ($move_action=="firstdown") {
  4032. $final_position_source = 2;
  4033. $final_position_target = 1;
  4034. }
  4035. else
  4036. if ($move_action=="down") {
  4037. $final_position_target = $this->activity->position;
  4038. $final_position_source = $final_position_target + 1;
  4039. }
  4040. else
  4041. if ($move_action=="up") {
  4042. $final_position_target = $this->activity->position;
  4043. $final_position_source = $final_position_target - 1;
  4044. }
  4045. else { // error:
  4046. print_error('error_update_move_iassign', 'iassign');
  4047. exit;
  4048. }
  4049. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4050. $newentry->id = $this->activity->id; // ID of the "source activity"
  4051. $newentry->position = $final_position_source;
  4052. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4053. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4054. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4055. print_error('error_update_move_iassign', 'iassign');
  4056. }
  4057. else { // first update performed successfully
  4058. $newentry->id = $iassign_target->id;
  4059. $newentry->position = $final_position_target;
  4060. if (!$DB->update_record('iassign_statement', $newentry))
  4061. print_error('error_update_move_iassign', 'iassign');
  4062. }
  4063. redirect($return);
  4064. }
  4065. /// Enable or disable the display of interactive activities
  4066. function visible_iassign ($return) {
  4067. global $DB;
  4068. $newentry = new stdClass();
  4069. $newentry->id = $this->activity->id;
  4070. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4071. if (!$DB->update_record('iassign_statement', $newentry))
  4072. print_error('error_update_visible_iassign', 'iassign');
  4073. redirect($return);
  4074. }
  4075. /// Add news interactive activities (register in table 'iassign_statement')
  4076. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4077. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4078. function new_iassign ($param) {
  4079. global $DB;
  4080. $newentry = new stdClass();
  4081. $newentry->iassignid = $param->iassignid;
  4082. $newentry->name = $param->name;
  4083. $newentry->type_iassign = $param->type_iassign;
  4084. $newentry->store_all_submissions = $param->store_all_submissions;
  4085. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4086. $proposition = $param->proposition;
  4087. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4088. else $proposition_text = $proposition;
  4089. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4090. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4091. //TODO Then get it directly from the form data $_POST!
  4092. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4093. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4094. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4095. $newentry->author_name = $param->author_name;
  4096. $newentry->author_modified_name = $param->author_modified_name;
  4097. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4098. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4099. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4100. $newentry->grade = $param->grade;
  4101. $newentry->timemodified = time();
  4102. $newentry->timecreated = time();
  4103. if ($param->type_iassign == 1) {
  4104. $newentry->timedue = 0;
  4105. $newentry->timeavailable = 0;
  4106. } // if ($param->type_iassign == 1)
  4107. else {
  4108. $newentry->timedue = $param->timedue;
  4109. $newentry->timeavailable = $param->timeavailable;
  4110. }
  4111. $newentry->preventlate = $param->preventlate;
  4112. $newentry->test = $param->test;
  4113. $newentry->special_param1 = $param->special_param1;
  4114. $newentry->visible = $param->visible;
  4115. $newentry->position = $param->position;
  4116. $newentry->max_experiment = $param->max_experiment;
  4117. $newentry->dependency = $param->dependency;
  4118. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4119. $newentry->show_answer = $param->show_answer;
  4120. $id = $DB->insert_record("iassign_statement", $newentry);
  4121. if ($id) {
  4122. $component = 'mod_iassign';
  4123. $filearea = 'exercise';
  4124. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4125. $file = $fs->get_file_by_id($param->file);
  4126. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4127. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4128. //$itemid = $id;
  4129. // File already inserted in other context!
  4130. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4131. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4132. $updateentry = new stdClass();
  4133. $updateentry->id = $id;
  4134. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4135. $updateentry->filesid = $newfile->get_itemid();
  4136. if (!$DB->update_record("iassign_statement", $updateentry))
  4137. print_error('error_add', 'iassign');
  4138. if ($param->type_iassign == 3)
  4139. iassign::update_grade_iassign($param->iassignid);
  4140. //TODO iLM_HTML5 :: //MOOC2014
  4141. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4142. //D if ($iassign_ilm_configs) {
  4143. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4144. //D if ($iassign_ilm_config->param_type != 'static') {
  4145. //D $newentry = new stdClass();
  4146. //D $newentry->iassign_statementid = $id;
  4147. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4148. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4149. //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});
  4150. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4151. //D print_error('error_add_param', 'iassign');
  4152. //D }
  4153. //D }
  4154. //D }
  4155. // log event --------------------------------------------------------------------------------------
  4156. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4157. // log event --------------------------------------------------------------------------------------
  4158. return $id;
  4159. }
  4160. else
  4161. print_error('error_add', 'iassign');
  4162. } // function new_iassign($param)
  4163. /// Add the calendar entries for this iassign
  4164. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4165. // @return bool
  4166. static function add_calendar ($iassignid) {
  4167. global $DB, $CFG;
  4168. require_once($CFG->dirroot . '/calendar/lib.php');
  4169. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4170. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4171. $event = new stdClass();
  4172. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4173. $event->description = $iassign_statement_activity_item->name;
  4174. $event->courseid = $iassign->course;
  4175. $event->groupid = 0;
  4176. $event->userid = 0;
  4177. $event->modulename = 'iassign';
  4178. $event->instance = $iassign->id;
  4179. $event->eventtype = 'due';
  4180. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4181. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4182. calendar_event::create($event);
  4183. }
  4184. /// Update the calendar entries for this iassign
  4185. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4186. // @return bool
  4187. function update_calendar ($iassignid, $olddescription) {
  4188. global $DB, $CFG;
  4189. require_once($CFG->dirroot . '/calendar/lib.php');
  4190. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4191. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4192. $event = new stdClass();
  4193. $event->id = 0;
  4194. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4195. if ($events) {
  4196. foreach ($events as $value) {
  4197. if ($value->description == $olddescription) {
  4198. $event->id = $value->id;
  4199. }
  4200. }
  4201. }
  4202. if ($event->id != 0) {
  4203. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4204. $event->description = $iassign_statement_activity_item->name;
  4205. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4206. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4207. $calendarevent = calendar_event::load($event->id);
  4208. $calendarevent->update($event);
  4209. } else
  4210. $this->add_calendar($iassignid);
  4211. }
  4212. /// Update the calendar entries for this iassign
  4213. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4214. // @return bool
  4215. function delete_calendar ($iassignid) {
  4216. global $DB, $CFG;
  4217. require_once($CFG->dirroot . '/calendar/lib.php');
  4218. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4219. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4220. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4221. if ($events) {
  4222. foreach ($events as $value) {
  4223. if ($value->description == $iassign_statement_activity_item->name) {
  4224. $DB->delete_records('event', array('id' => $value->id));
  4225. }
  4226. }
  4227. }
  4228. }
  4229. /// Update interactive activities
  4230. function update_iassign ($param) {
  4231. global $DB;
  4232. $component = 'mod_iassign';
  4233. $filearea = 'exercise';
  4234. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4235. $file = $fs->get_file_by_id($param->file);
  4236. $fileold = $fs->get_file_by_id($param->fileold);
  4237. if ($param->file != $param->fileold) {
  4238. if ($fileold) {
  4239. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4240. foreach ($fileoldarea as $value) {
  4241. $value->delete();
  4242. }
  4243. }
  4244. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4245. $itemid = $file->get_itemid() + $param->iassign_id;
  4246. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4247. $param->file = $newfile->get_itemid();
  4248. } else
  4249. $param->file = $file->get_itemid();
  4250. } else {
  4251. $param->file = $file->get_itemid();
  4252. }
  4253. $newentry = new stdClass();
  4254. $newentry->id = $param->iassign_id;
  4255. $newentry->name = $param->name;
  4256. $newentry->type_iassign = $param->type_iassign;
  4257. $newentry->store_all_submissions = $param->store_all_submissions;
  4258. //2019 $newentry->proposition = $param->proposition;
  4259. $proposition = $param->proposition;
  4260. if (is_array($proposition))
  4261. $proposition_text = $proposition['text'];
  4262. else
  4263. $proposition_text = $proposition;
  4264. $newentry->proposition = $proposition_text;
  4265. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4266. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4267. $newentry->grade = $param->grade;
  4268. $newentry->author_modified_name = $param->author_modified_name;
  4269. $newentry->timemodified = time();
  4270. if ($param->type_iassign == 1) {
  4271. $newentry->timedue = 0;
  4272. $newentry->timeavailable = 0;
  4273. } // if ($param->type_iassign == 1)
  4274. else {
  4275. $newentry->timedue = $param->timedue;
  4276. $newentry->timeavailable = $param->timeavailable;
  4277. }
  4278. $newentry->preventlate = $param->preventlate;
  4279. $newentry->test = $param->test;
  4280. if (isset($param->special_param1))
  4281. $newentry->special_param1 = $param->special_param1;
  4282. else
  4283. $newentry->special_param1 = NULL;
  4284. $newentry->visible = $param->visible;
  4285. $newentry->max_experiment = $param->max_experiment;
  4286. $newentry->dependency = $param->dependency;
  4287. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4288. $newentry->show_answer = $param->show_answer;
  4289. if (!$DB->update_record("iassign_statement", $newentry))
  4290. print_error('error_update', 'iassign');
  4291. if ($param->type_iassign == 3) {
  4292. iassign::update_grade_iassign($param->iassignid);
  4293. }
  4294. //$id = $newentry->id; // MOOC 2016 --- inicio
  4295. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4296. //if ($iassign_activity_item_configs) {
  4297. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4298. // $newentry = new stdClass();
  4299. // $newentry->id = $iassign_activity_item_config->id;
  4300. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4301. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4302. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4303. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4304. // print_error('error_edit_param', 'iassign');
  4305. // }
  4306. // } // MOOC 2016 --- final
  4307. // log event --------------------------------------------------------------------------------------
  4308. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4309. // log event --------------------------------------------------------------------------------------
  4310. return $newentry->id;
  4311. // if ($param->type_iassign==3)
  4312. // $this->update_grade_iassign($param->iassignid);
  4313. } // function update_iassign($param)
  4314. /// Show information of activity
  4315. function show_info_iassign () {
  4316. global $DB, $OUTPUT;
  4317. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4318. if ($this->activity->type_iassign == 3) {
  4319. if ($this->activity->dependency == 0) {
  4320. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4321. } else {
  4322. $dependencys = explode(';', $this->activity->dependency);
  4323. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4324. foreach ($dependencys as $dependency) {
  4325. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4326. if ($dependencyiassign)
  4327. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4328. } // foreach ($dependencys as $dependency)
  4329. } // if ($iassign_statement_activity_item->dependency == 0)
  4330. if ($this->activity->max_experiment == 0)
  4331. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4332. else
  4333. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4334. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4335. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4336. print $OUTPUT->box($output);
  4337. } // function show_info_iassign()
  4338. /// Shows date of opening and closing activities
  4339. function view_dates () {
  4340. global $USER, $CFG, $DB, $OUTPUT;
  4341. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4342. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4343. $status_iassign = "";
  4344. $status_iassign1 = "";
  4345. $status_iassign2 = "";
  4346. if ($this->activity->type_iassign == 1) // activity of type example
  4347. $type_iassign = get_string('example_iassign', 'iassign');
  4348. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4349. $type_iassign = get_string('test_iassign', 'iassign');
  4350. if ($this->activity->timeavailable > time()) {
  4351. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4352. } elseif ($this->activity->timedue < time()) {
  4353. $status_iassign = get_string('last_timedue', 'iassign');
  4354. }
  4355. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4356. $type_iassign = get_string('exercise_iassign', 'iassign');
  4357. if ($this->activity->timeavailable > time()) {
  4358. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4359. } elseif ($this->activity->timedue < time()) { // after delivery
  4360. $status_iassign = get_string('last_timedue', 'iassign');
  4361. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4362. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4363. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4364. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4365. if ($this->activity->test == 1) // allowed to test after of deadline
  4366. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4367. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4368. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4369. } // elseif ($iassign_statement_activity_item->test == 0)
  4370. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4371. } // elseif ($iassign_statement_activity_item->timedue < time())
  4372. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4373. $output = '<table width=100% >' . "\n";
  4374. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4375. $output .= '<tr>' . "\n";
  4376. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4377. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4378. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4379. // leo $output .= '<td width=80%>' . $type_iassign;
  4380. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4381. // $output .= '</td>' . "\n";
  4382. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4383. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4384. $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>";
  4385. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4386. } else {
  4387. $link_next = "";
  4388. $link_previous = "";
  4389. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4390. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4391. // previous_activity
  4392. if ($iassign_previous) {
  4393. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4394. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4395. } // next_activity
  4396. if ($iassign_next) {
  4397. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4398. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4399. }
  4400. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4401. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4402. $output .= '</tr></table>' . "\n";
  4403. $output .= '<table width=100% >' . "\n";
  4404. if ($this->activity->type_iassign > 1) {
  4405. if ($this->activity->timeavailable)
  4406. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4407. if ($this->activity->timedue)
  4408. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4409. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4410. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4411. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4412. $output .= '</table>' . "\n";
  4413. print $OUTPUT->box($output);
  4414. } // function view_dates()
  4415. } // class activity
  4416. /// Class to manage Interactive Learning Module (iLM)
  4417. class ilm {
  4418. var $ilm;
  4419. /// Constructor of class
  4420. // @param int $id Id of iLM
  4421. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4422. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4423. function __construct ($id) {
  4424. global $DB;
  4425. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4426. if (empty($this->ilm))
  4427. $this->ilm = null;
  4428. }
  4429. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4430. // @calledby view_iassign_current()
  4431. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4432. global $USER, $CFG, $DB;
  4433. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4434. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4435. $typec = strtolower($iassign_ilm->type);
  4436. require_once 'ilm_handlers/' . $typec . '.php';
  4437. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4438. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4439. return $retorno;
  4440. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4441. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4442. // @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);
  4443. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4444. // @param Object $file File in use in activity
  4445. // @return int Return the id of log
  4446. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4447. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4448. $newentry = new stdClass();
  4449. $newentry->iassign_statementid = $iassign_activity_itemid;
  4450. $newentry->userid = $USER->id;
  4451. $newentry->filesid = $content_or_id_from_ilm_security;
  4452. $newentry->timecreated = time();
  4453. $newentry->view = 1;
  4454. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4455. if (!$id_iLM_security) {
  4456. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4457. } // from (!$DB->insert_record("iassign_security", $newentry))
  4458. return $id_iLM_security;
  4459. }
  4460. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4461. // @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);
  4462. // @param int $userid
  4463. // @param int $iassign_activity_itemid Id of iassign statement
  4464. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4465. global $DB;
  4466. // 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")
  4467. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4468. }
  4469. } // class ilm
  4470. /// Class to manage settings of iLM.
  4471. class ilm_settings {
  4472. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4473. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4474. // @param int $ilm_id Id of iLM
  4475. // @param array $options An array with options for create dynamic tag html APPLET
  4476. // @return string Return with a tag html APPLET created
  4477. static function build_ilm_tags ($ilm_id, $options = array()) {
  4478. global $DB;
  4479. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4480. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4481. $typec = strtolower($iassign_ilm->type);
  4482. require_once 'ilm_handlers/' . $typec . '.php';
  4483. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4484. return $retorno;
  4485. } // static function build_ilm_tags($ilm_id, $options = array())
  4486. /// Function for get modified date of iLM file
  4487. // @param string $file_jar String with Ids of iLM files
  4488. // @return string Return with the filenames and modified date
  4489. static function applet_filetime ($file_jar) {
  4490. $filetime = "";
  4491. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4492. $files_jar = explode(",", $file_jar);
  4493. foreach ($files_jar as $one_file) {
  4494. $file = $fs->get_file_by_id($one_file);
  4495. if ($file)
  4496. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4497. }
  4498. return $filetime;
  4499. }
  4500. /// Function for verify an default applet
  4501. // @param String $file_jar String containing an list de ids of applet files
  4502. // @return boolean Return true or fale if applet is default
  4503. static function applet_default ($file_jar) {
  4504. $is_default = true;
  4505. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4506. $files_jar = explode(",", $file_jar);
  4507. foreach ($files_jar as $one_file) {
  4508. $file = $fs->get_file_by_id($one_file);
  4509. if ($file)
  4510. $is_default &= ($file->get_itemid() == 0);
  4511. }
  4512. return $is_default;
  4513. }
  4514. /// Function for get form variables for add, edit, or copy iLM
  4515. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4516. // @see settings_form.php
  4517. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4518. // @param int $ilm_id Id of iLM
  4519. // @param string $action String with the action
  4520. // @return object Return an object with forms variables
  4521. static function add_edit_copy_ilm ($ilm_id, $action) {
  4522. global $USER, $DB, $CFG;
  4523. require_once('settings_form.php'); // put the form
  4524. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4525. $param = new stdClass();
  4526. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4527. $param->action = $action;
  4528. $param->ilm_id = $ilm_id;
  4529. $CFG->action_ilm = $action;
  4530. $CFG->ilm_id = $ilm_id;
  4531. if ($action == 'add') {
  4532. $param->title = get_string('add_ilm', 'iassign');
  4533. $param->name = "";
  4534. $param->version = "";
  4535. $param->url = "";
  4536. $param->description = "";
  4537. $param->extension = "";
  4538. $param->author = $USER->id;
  4539. $param->file_jar = "";
  4540. $param->file_jar_static = "";
  4541. $param->file_class = "";
  4542. $param->width = 800;
  4543. $param->height = 600;
  4544. $param->enable = 0; // 0 - hide / 1 - show
  4545. $param->timecreated = time();
  4546. $param->timemodified = time();
  4547. $param->evaluate = 0;
  4548. $param->parent = 0;
  4549. }
  4550. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4551. if ($iassign_ilm) {
  4552. $description = json_decode($iassign_ilm->description);
  4553. $param->title = get_string('edit_ilm', 'iassign');
  4554. $param->id = $iassign_ilm->id;
  4555. $param->name_ilm = $iassign_ilm->name;
  4556. $param->name = $iassign_ilm->name;
  4557. $param->version = $iassign_ilm->version;
  4558. $param->ilm_type = $iassign_ilm->type;
  4559. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4560. $param->url = $iassign_ilm->url; // iLM official URL
  4561. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  4562. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4563. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4564. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4565. if (!isset($description->{current_language()})) {
  4566. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4567. else
  4568. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4569. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4570. }
  4571. else
  4572. $param->description = $description->{current_language()};
  4573. $param->description_lang = $iassign_ilm->description;
  4574. $param->extension = $iassign_ilm->extension;
  4575. $param->author = $iassign_ilm->author;
  4576. $param->file_jar = $iassign_ilm->file_jar;
  4577. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4578. $param->file_class = $iassign_ilm->file_class;
  4579. $param->width = $iassign_ilm->width;
  4580. $param->height = $iassign_ilm->height;
  4581. $param->enable = $iassign_ilm->enable;
  4582. $param->timecreated = $iassign_ilm->timecreated;
  4583. $param->timemodified = time();
  4584. $param->evaluate = $iassign_ilm->evaluate;
  4585. $param->parent = $iassign_ilm->parent;
  4586. }
  4587. }
  4588. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4589. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4590. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4591. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4592. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4593. // echo "Sem dados<br/>"; exit;
  4594. return;
  4595. }
  4596. $description = json_decode($iassign_ilm->description);
  4597. if ($iassign_ilm) {
  4598. if ($iassign_ilm->parent == 0)
  4599. $iassign_ilm->parent = $ilm_id;
  4600. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4601. $param->title = get_string('new_version_ilm', 'iassign');
  4602. $param->name_ilm = $iassign_ilm->name;
  4603. $param->name = $iassign_ilm->name;
  4604. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4605. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4606. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4607. $param->ilm_type = $iassign_ilm->type;
  4608. $param->url = $iassign_ilm->url;
  4609. $param->description = $description->{current_language()};
  4610. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4611. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4612. $param->extension = $iassign_ilm->extension;
  4613. $param->author = $USER->id;
  4614. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4615. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4616. $param->file_jar_static = '';
  4617. $param->file_class = $iassign_ilm->file_class;
  4618. $param->width = $iassign_ilm->width;
  4619. $param->height = $iassign_ilm->height;
  4620. $param->enable = 0;
  4621. $param->timecreated = time();
  4622. $param->timemodified = time();
  4623. $param->evaluate = $iassign_ilm->evaluate;
  4624. $param->parent = $iassign_ilm->parent;
  4625. }
  4626. }
  4627. elseif ($action == 'copy') {
  4628. $description = json_decode($iassign_ilm->description);
  4629. if ($iassign_ilm) {
  4630. if ($iassign_ilm->parent == 0)
  4631. $iassign_ilm->parent = $ilm_id;
  4632. $param->title = get_string('copy_ilm', 'iassign');
  4633. $param->id = $iassign_ilm->id;
  4634. $param->name_ilm = $iassign_ilm->name;
  4635. $param->name = $iassign_ilm->name;
  4636. $param->version = "";
  4637. $param->ilm_type = $iassign_ilm->type;
  4638. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4639. $param->url = $iassign_ilm->url;
  4640. $param->description = $description->{current_language()};
  4641. $param->description_lang = $iassign_ilm->description;
  4642. $param->extension = $iassign_ilm->extension;
  4643. $param->author = $USER->id;
  4644. $param->file_jar = '';
  4645. $param->file_jar_static = '';
  4646. $param->file_class = $iassign_ilm->file_class;
  4647. $param->width = $iassign_ilm->width;
  4648. $param->height = $iassign_ilm->height;
  4649. $param->enable = 0;
  4650. $param->timecreated = time();
  4651. $param->timemodified = time();
  4652. $param->evaluate = $iassign_ilm->evaluate;
  4653. $param->parent = $iassign_ilm->parent;
  4654. }
  4655. }
  4656. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  4657. //D var_dump(debug_backtrace());
  4658. //D print_r(debug_backtrace());
  4659. return $param;
  4660. } // static function add_edit_copy_ilm($ilm_id, $action)
  4661. /// Function for save iLM file in moodledata
  4662. // @param int $itemid Itemid of file save in draft (upload file)
  4663. // @param int $ilm_id Id of iLM
  4664. // @return string Return an string with ids of iLM files
  4665. static function new_file_ilm ($itemid, $iassign_ilm) {
  4666. global $CFG, $USER, $DB;
  4667. $return = null;
  4668. $file_jar = array();
  4669. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4670. $contextuser = context_user::instance($USER->id);
  4671. $contextsystem = context_system::instance();
  4672. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4673. if ($files_ilm) {
  4674. foreach ($files_ilm as $value) {
  4675. // CHECK IF file is HTML type
  4676. if ($iassign_ilm->type == 1) {
  4677. // Check if the file extension is ZIP
  4678. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4679. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4680. if ((strtolower($ext) == 'zip')) {
  4681. // Coping...:
  4682. $destination = 'ilm_debug/' . $value->get_filename();
  4683. $value->copy_content_to($destination);
  4684. // Extracting content...:
  4685. $zip = new ZipArchive();
  4686. $extracted = './ilm';
  4687. $dir = "";
  4688. if ($zip->open($destination) === TRUE) {
  4689. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4690. if (is_dir($dir)) {
  4691. $i = 1;
  4692. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4693. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4694. $i ++;
  4695. }
  4696. $name = $previous . "_" . $i;
  4697. $dir = './ilm/' . $name . "/";
  4698. $j = 0;
  4699. while ($item_name = $zip->getNameIndex($j)) {
  4700. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4701. $j++;
  4702. }
  4703. $zip->close();
  4704. }
  4705. $zip->open($destination);
  4706. $zip->extractTo($extracted);
  4707. $zip->close();
  4708. // After the extraction, remove it from DEBUG
  4709. unlink($destination);
  4710. } else { // Error trying to open destination...
  4711. // After the extraction error, also remove it from DEBUG
  4712. unlink($destination);
  4713. print_error('error_add_ilm_zip', 'iassign');
  4714. }
  4715. return $dir;
  4716. }
  4717. } // if ($iassign_ilm->type == 1)
  4718. if ($value->get_filename() != '.') {
  4719. $file_ilm = array(
  4720. 'userid' => $USER->id,
  4721. 'contextid' => $contextsystem->id,
  4722. 'component' => 'mod_iassign',
  4723. 'filearea' => 'ilm',
  4724. 'itemid' => rand(1, 999999999),
  4725. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4726. 'filename' => $value->get_filename());
  4727. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4728. array_push($file_jar, $file_ilm->get_id());
  4729. }
  4730. }
  4731. if (!empty($file_jar)) {
  4732. $return = implode(",", $file_jar);
  4733. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4734. foreach ($old_file_jar as $value) {
  4735. $file = $fs->get_file_by_id($value);
  4736. if ($file)
  4737. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4738. }
  4739. }
  4740. }
  4741. else // if ($files_ilm)
  4742. $return = $iassign_ilm->file_jar;
  4743. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4744. return $return;
  4745. } // static function new_file_ilm($itemid, $iassign_ilm)
  4746. /// Function for save in database an new iLM
  4747. // @param object $param An object with iLM params
  4748. static function new_ilm ($itemid) {
  4749. global $CFG, $USER, $OUTPUT;
  4750. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4751. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4752. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4753. }
  4754. $pathtemp = $CFG->dataroot . '/temp/';
  4755. $contextuser = context_user::instance($USER->id);
  4756. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4757. $zip = new zip_packer();
  4758. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4759. foreach ($files as $file) {
  4760. if (!$file->is_directory())
  4761. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4762. }
  4763. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4764. // Verifica se o pacote possui o XML
  4765. if (!$application_xml) {
  4766. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4767. return;
  4768. } else {
  4769. $missing = "";
  4770. if (!isset($application_xml->name)) {
  4771. $missing .= "name";
  4772. }
  4773. if (!isset($application_xml->version)) {
  4774. $missing .= ", version";
  4775. }
  4776. if (!isset($application_xml->type)) {
  4777. $missing .= ", type";
  4778. }
  4779. if (!isset($application_xml->extension)) {
  4780. $missing .= ", extension";
  4781. }
  4782. if (!isset($application_xml->file_jar)) {
  4783. $missing .= ", file_jar";
  4784. }
  4785. if (!isset($application_xml->file_class)) {
  4786. $missing .= ", file_class";
  4787. }
  4788. if (!isset($application_xml->width)) {
  4789. $missing .= ", width";
  4790. }
  4791. if (!isset($application_xml->height)) {
  4792. $missing .= ", height";
  4793. }
  4794. if (!isset($application_xml->evaluate)) {
  4795. $missing .= ", evaluate";
  4796. }
  4797. if (strlen($missing) > 2) {
  4798. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4799. return;
  4800. }
  4801. }
  4802. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4803. $typec = strtolower($application_xml->type);
  4804. require_once 'ilm_handlers/' . $typec . '.php';
  4805. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4806. return $retorno;
  4807. } // static function new_ilm($itemid)
  4808. /// Function for save in database an iLM edit
  4809. // @param object $param An object with iLM params
  4810. static function edit_ilm ($param, $itemid) {
  4811. // Descobrir o tipo de iLM:
  4812. global $DB, $USER, $CFG;
  4813. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4814. $pathtemp = $CFG->dataroot . '/temp/';
  4815. $contextuser = context_user::instance($USER->id);
  4816. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4817. $zip = new zip_packer();
  4818. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4819. $files_extract = null;
  4820. foreach ($files as $file) {
  4821. if (!$file->is_directory())
  4822. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4823. }
  4824. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4825. $typec = strtolower($iassign_t->type);
  4826. require_once 'ilm_handlers/' . $typec . '.php';
  4827. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4828. }
  4829. /// Function for register the new iLM (in database and in the directory)
  4830. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4831. // @param object $param An object with iLM params
  4832. static function copy_new_version_ilm ($param) {
  4833. global $DB, $CFG, $USER;
  4834. $itemid = $param->file;
  4835. $pathtemp = $CFG->dataroot . '/temp/';
  4836. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4837. //D echo "pathtemp=$pathtemp<br/>";
  4838. $contextuser = context_user::instance($USER->id);
  4839. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4840. $zip = new zip_packer();
  4841. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4842. $files_extract = null;
  4843. foreach ($files as $file) {
  4844. if (!$file->is_directory())
  4845. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4846. }
  4847. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4848. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4849. $typec = strtolower($iassign_t->type);
  4850. require_once 'ilm_handlers/' . $typec . '.php';
  4851. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4852. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4853. } // static function copy_new_version_ilm($param)
  4854. //VER::
  4855. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4856. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4857. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4858. /// Function for change visibility of iLM
  4859. // @param int $ilm_id Id of iLM
  4860. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4861. static function visible_ilm ($ilm_id, $status) {
  4862. global $DB;
  4863. if ($status == 0)
  4864. $visible = 1;
  4865. else
  4866. $visible = 0;
  4867. $newentry = new stdClass();
  4868. $newentry->id = $ilm_id;
  4869. $newentry->enable = $visible;
  4870. if (!$DB->update_record("iassign_ilm", $newentry))
  4871. error(get_string('error_edit_ilm', 'iassign'));
  4872. }
  4873. /// Function for confirm change default iLM
  4874. // @param int $ilm_id Id of iLM
  4875. // @param int $ilm_parent Id of parent iLM
  4876. // @return string Return with an string for create default page confirmation
  4877. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4878. global $OUTPUT, $DB;
  4879. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4880. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4881. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4882. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4883. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4884. return $return;
  4885. }
  4886. /// Function for change the default iLM
  4887. // @see settings_ilm.php
  4888. // @param int $ilm_id Id of iLM
  4889. // @return int Return Id of default iLM
  4890. static function default_ilm ($ilm_id) {
  4891. global $DB;
  4892. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4893. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4894. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4895. $iassign_ilm_default->id = $iassign_ilm->id;
  4896. $iassign_ilm_default->parent = 0;
  4897. $iassign_ilm->parent = $iassign_ilm_default->id;
  4898. $iassign_ilm->id = 0;
  4899. $iassign_ilm_default->enable = 1;
  4900. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4901. print_error('error_edit_ilm', 'iassign');
  4902. }
  4903. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4904. if (!$inserted) {
  4905. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4906. print_error($msg_error);
  4907. //xx print_error('error_add_ilm', 'iassign');
  4908. }
  4909. return $iassign_ilm_default->id;
  4910. } // static function default_ilm ($ilm_id)
  4911. /// Function for confirm delete iLM
  4912. // @param int $ilm_id Id of iLM
  4913. // @param int $ilm_parent Id of parent iLM
  4914. // @return string Return with an string for create delete page confirmation
  4915. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4916. global $OUTPUT, $DB;
  4917. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4918. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4919. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4920. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4921. }
  4922. /// Function for delete directory where the iLM is allocated.
  4923. // @param string $dirPath
  4924. // @throws InvalidArgumentException
  4925. public static function delete_dir ($dirPath) {
  4926. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4927. $dirPath .= '/';
  4928. }
  4929. $files = glob($dirPath . '*', GLOB_MARK);
  4930. foreach ($files as $file) {
  4931. if (is_dir($file)) {
  4932. ilm_settings::delete_dir($file);
  4933. } else {
  4934. unlink($file);
  4935. }
  4936. }
  4937. rmdir($dirPath);
  4938. }
  4939. /// Function for delete iLM
  4940. // @param int $ilm_id Id of iLM
  4941. // @return int Return Id of parent iLM
  4942. static function delete_ilm ($ilm_id) {
  4943. global $DB;
  4944. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4945. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4946. $typec = strtolower($iassign_ilm->type);
  4947. require_once 'ilm_handlers/' . $typec . '.php';
  4948. $retorno = $typec::delete_ilm($ilm_id);
  4949. return $retorno;
  4950. }
  4951. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4952. // @param int $ilm_id Id of iLM
  4953. static function export_ilm ($ilm_id) {
  4954. global $DB;
  4955. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4956. if (!$iassign_ilm) return; // security debug...
  4957. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4958. $typec = strtolower($iassign_ilm->type);
  4959. if (!$typec) $typec = "html5"; // security debug...
  4960. require_once 'ilm_handlers/' . $typec . '.php';
  4961. $typec::export_ilm($ilm_id);
  4962. } // static function export_ilm($ilm_id)
  4963. //TODO iLM_HTML5 :: //MOOC 2016
  4964. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4965. // @param int $ilm_id Id of iLM
  4966. static function export_update_ilm ($ilm_id) {
  4967. global $DB, $CFG;
  4968. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4969. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4970. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4971. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4972. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4973. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4974. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4975. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4976. $upgrade_descriptor .= '</upgrade>' . "\n";
  4977. file_put_contents($xml_filename, $upgrade_descriptor);
  4978. header("Pragma: public");
  4979. header("Expires: 0");
  4980. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4981. header("Cache-Control: private", false);
  4982. header('Content-Type: application/xml; charset=utf-8');
  4983. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4984. header("Content-Length: " . @filesize($xml_filename));
  4985. set_time_limit(0);
  4986. @readfile("$xml_filename") || die("File not found.");
  4987. unlink($xml_filename);
  4988. exit;
  4989. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4990. /// Function for save iLM from XML descriptor
  4991. // @param array $application_xml Data of XML descriptor
  4992. // @param array $files_extract Filenames of extract files
  4993. // @return array Return an array content id of JAR files
  4994. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4995. global $CFG, $USER;
  4996. // Tratamento diferenciado se for do tipo HTML5:
  4997. $source = "";
  4998. $diretorio = "";
  4999. if (strtolower($application_xml->type) == 'html5') {
  5000. $i = 0;
  5001. foreach ($files_extract as $key => $value) {
  5002. $file = $CFG->dataroot . '/temp/' . $key;
  5003. // Verifica se já existe a pasta no diretório dos iLM:
  5004. if ($i == 0) {
  5005. $source = $file;
  5006. if (file_exists("ilm/" . basename($file))) {
  5007. $j = 1;
  5008. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5009. $j ++;
  5010. }
  5011. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5012. // mkdir($diretorio, 0777, true);
  5013. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5014. }
  5015. else {
  5016. $diretorio = 'ilm/' . basename($file);
  5017. // mkdir($diretorio, 0777, true);
  5018. mkdir($diretorio, 0755, true);
  5019. }
  5020. break;
  5021. }
  5022. $i ++;
  5023. }
  5024. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5025. if ($item->isDir()) {
  5026. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5027. }
  5028. else {
  5029. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5030. }
  5031. }
  5032. ilm_settings::delete_dir($source);
  5033. return "./" . $diretorio;
  5034. }
  5035. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5036. $file_jar = array();
  5037. $files_ilm = explode(",", $application_xml->file_jar);
  5038. $contextsystem = context_system::instance();
  5039. foreach ($files_ilm as $value) {
  5040. $file_ilm = array(
  5041. 'userid' => $USER->id,
  5042. 'contextid' => $contextsystem->id,
  5043. 'component' => 'mod_iassign',
  5044. 'filearea' => 'ilm',
  5045. 'itemid' => rand(1, 999999999),
  5046. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5047. 'filename' => $value);
  5048. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5049. array_push($file_jar, $file_ilm->get_id());
  5050. }
  5051. foreach ($files_extract as $key => $value) {
  5052. $file = $CFG->dataroot . '/temp/' . $key;
  5053. if (file_exists($file))
  5054. unlink($file);
  5055. }
  5056. return $file_jar;
  5057. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5058. /// Function for import the iLM from an package
  5059. // @param int $itemid Itemid of zip file
  5060. static function import_ilm ($itemid) {
  5061. global $CFG, $USER, $OUTPUT;
  5062. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5063. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5064. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5065. }
  5066. $pathtemp = $CFG->dataroot . '/temp/';
  5067. $contextuser = context_user::instance($USER->id);
  5068. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5069. $zip = new zip_packer();
  5070. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5071. foreach ($files as $file) {
  5072. if (!$file->is_directory())
  5073. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5074. }
  5075. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5076. // Verifica se o pacote possui o XML
  5077. if (!$application_xml) {
  5078. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5079. return;
  5080. } else {
  5081. $missing = "";
  5082. if (!isset($application_xml->name)) {
  5083. $missing .= "name";
  5084. }
  5085. if (!isset($application_xml->version)) {
  5086. $missing .= ", version";
  5087. }
  5088. if (!isset($application_xml->type)) {
  5089. $missing .= ", type";
  5090. }
  5091. if (!isset($application_xml->extension)) {
  5092. $missing .= ", extension";
  5093. }
  5094. if (!isset($application_xml->file_jar)) {
  5095. $missing .= ", file_jar";
  5096. }
  5097. if (!isset($application_xml->file_class)) {
  5098. $missing .= ", file_class";
  5099. }
  5100. if (!isset($application_xml->width)) {
  5101. $missing .= ", width";
  5102. }
  5103. if (!isset($application_xml->height)) {
  5104. $missing .= ", height";
  5105. }
  5106. if (!isset($application_xml->evaluate)) {
  5107. $missing .= ", evaluate";
  5108. }
  5109. if (strlen($missing) > 2) {
  5110. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5111. return;
  5112. }
  5113. }
  5114. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5115. $typec = strtolower($application_xml->type);
  5116. require_once 'ilm_handlers/' . $typec . '.php';
  5117. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5118. } // static function import_ilm($itemid)
  5119. /// Function for list iLM defaults
  5120. // @return string Return an string with a table of iLM
  5121. static function list_ilm () {
  5122. global $DB, $OUTPUT;
  5123. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5124. $str = '';
  5125. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5126. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5127. if ($iassign_ilm) {
  5128. foreach ($iassign_ilm as $ilm) {
  5129. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5130. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5131. $str .= '<tr><td>';
  5132. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5133. $str .= '<tr>';
  5134. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5135. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5136. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5137. $str .= '</tr>';
  5138. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5139. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5140. $str .= '</table>';
  5141. $str .= '</td></tr>';
  5142. }
  5143. }
  5144. $str .= '</table>';
  5145. return $str;
  5146. }
  5147. /// Function for download and install an upgrade of an iLM
  5148. // @param int $ilm_id Id of iLM
  5149. static function upgrade_ilm ($ilm_id) {
  5150. global $DB, $CFG, $USER;
  5151. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5152. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5153. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5154. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5155. if (!$result)
  5156. print_error('error_upgrade_ilm', 'iassign');
  5157. else {
  5158. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5159. $extension = explode(".", $zip_filename);
  5160. if ($extension[count($extension) - 1] != 'ipz') {
  5161. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5162. die;
  5163. }
  5164. $zip = new zip_packer();
  5165. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5166. $contextuser = context_user::instance($USER->id);
  5167. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5168. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5169. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5170. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5171. if (file_exists($zip_filename))
  5172. unlink($zip_filename);
  5173. if (empty($file_jar)) {
  5174. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5175. print_error($msg_error);
  5176. //xx print_error('error_add_ilm', 'iassign');
  5177. }
  5178. else {
  5179. $newentry = new stdClass();
  5180. $newentry->name = (String) $application_xml->name;
  5181. $newentry->version = (String) $application_xml->version;
  5182. $newentry->url = (String) $application_xml->url;
  5183. $newentry->description = $description_str;
  5184. $newentry->extension = strtolower((String) $application_xml->extension);
  5185. $newentry->file_jar = implode(",", $file_jar);
  5186. $newentry->file_class = (String) $application_xml->file_class;
  5187. $newentry->width = (String) $application_xml->width;
  5188. $newentry->height = (String) $application_xml->height;
  5189. $newentry->enable = 0;
  5190. $newentry->timemodified = time();
  5191. $newentry->author = $USER->id;
  5192. $newentry->timecreated = time();
  5193. $newentry->evaluate = (String) $application_xml->evaluate;
  5194. $newentry->parent = $ilm_id;
  5195. }
  5196. }
  5197. return $iassign_ilm->id;
  5198. } // static function upgrade_ilm($ilm_id)
  5199. //MOOC2014 -- inicio
  5200. //TODO: REVIEW
  5201. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5202. // static function move_iassign($ilm_id)
  5203. //MOOC2014 -- final
  5204. /// Function for list iLM versions with all informations
  5205. // @return string Return an string with a table of iLM
  5206. static function view_ilm ($ilmid, $from) {
  5207. global $DB;
  5208. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5209. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5210. $typec = strtolower($iassign_ilm->type);
  5211. require_once 'ilm_handlers/' . $typec . '.php';
  5212. $retorno = $typec::view_ilm($ilmid, $from);
  5213. return $retorno;
  5214. }
  5215. /// Function for get form variables for add, edit, or copy iLM params
  5216. // @param int $ilm_param_id Id of iLM param
  5217. // @param string $action String with the action
  5218. // @return object Return an object with forms variables
  5219. static function add_edit_copy_param ($ilm_param_id, $action) {
  5220. global $DB;
  5221. require_once('params_form.php');
  5222. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5223. $param = new stdClass();
  5224. $param->action = $action;
  5225. $param->ilm_param_id = $ilm_param_id;
  5226. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5227. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5228. $type = $iassign_ilm_config->param_type;
  5229. if ($action == 'add') {
  5230. $param->title = get_string('add_ilm', 'iassign');
  5231. $param->iassign_ilmid = $ilm_param_id;
  5232. $param->param_name = "";
  5233. $param->param_value = "";
  5234. $param->description = "";
  5235. $param->visible = 1;
  5236. }
  5237. elseif ($action == 'edit') {
  5238. if ($iassign_ilm_config) {
  5239. $param->title = get_string('edit_ilm', 'iassign');
  5240. $param->id = $iassign_ilm_config->id;
  5241. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5242. $param->param_type = $type; //MOOC2014
  5243. $param->param_name = $iassign_ilm_config->param_name;
  5244. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5245. $param->param_value = $iassign_ilm_config->param_value;
  5246. else //MOOC2014
  5247. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5248. $param->param_value = $iassign_ilm_config->param_value;
  5249. $param->description = $iassign_ilm_config->description;
  5250. $param->visible = $iassign_ilm_config->visible;
  5251. }
  5252. }
  5253. elseif ($action == 'copy') {
  5254. if ($iassign_ilm_config) {
  5255. $param->title = get_string('copy_ilm', 'iassign');
  5256. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5257. $param->param_type = $type; //MOOC2014
  5258. $param->param_name = $iassign_ilm_config->param_name;
  5259. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5260. $param->param_value = $iassign_ilm_config->param_value;
  5261. else //MOOC2014
  5262. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5263. $param->description = $iassign_ilm_config->description;
  5264. $param->visible = $iassign_ilm_config->visible;
  5265. }
  5266. }
  5267. return $param;
  5268. } // static function add_edit_copy_param($ilm_param_id, $action)
  5269. /// Function for change visibility of iLM param
  5270. // @param int $ilm_param_id Id of iLM param
  5271. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5272. static function visible_param ($ilm_param_id, $status) {
  5273. global $DB, $CFG;
  5274. if ($status == 0)
  5275. $visible = 1;
  5276. else
  5277. $visible = 0;
  5278. $newentry = new stdClass();
  5279. $newentry->id = $ilm_param_id;
  5280. $newentry->visible = $visible;
  5281. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5282. error(get_string('error_edit_param', 'iassign'));
  5283. }
  5284. /// Function for save in database an new iLM param
  5285. // @param object $param An object with iLM params
  5286. static function add_param ($param) {
  5287. global $DB;
  5288. $newentry = new stdClass();
  5289. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5290. //MOOC2014 $newentry->param_name = $param->param_name;
  5291. $newentry->param_type = $param->param_type; //MOOC2014
  5292. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5293. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5294. $newentry->param_value = $param->param_value;
  5295. else //MOOC2014
  5296. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5297. $newentry->description = $param->description;
  5298. $newentry->visible = $param->visible;
  5299. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5300. if (!$newentry->id) {
  5301. print_error('error_add_param', 'iassign');
  5302. }
  5303. }
  5304. /// Function for save in database a iLM param edit
  5305. // @param object $param An object with iLM params
  5306. static function edit_param ($param) {
  5307. global $DB;
  5308. $updentry = new stdClass();
  5309. $updentry->id = $param->id;
  5310. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5311. $updentry->param_type = $param->param_type; //MOOC2014
  5312. // $updentry->param_name = $param->param_name;
  5313. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5314. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5315. $updentry->param_value = $param->param_value;
  5316. else //MOOC2014
  5317. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5318. $updentry->description = $param->description;
  5319. $updentry->visible = $param->visible;
  5320. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5321. error(get_string('error_edit_param', 'iassign'));
  5322. }
  5323. }
  5324. /// Function for save in database a iLM param copy
  5325. // @param object $param An object with iLM params
  5326. static function copy_param ($param) {
  5327. global $DB;
  5328. $newentry = new stdClass();
  5329. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5330. //$newentry->param_name = $param->param_name;
  5331. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5332. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5333. $newentry->param_value = $param->param_value;
  5334. else //MOOC2014
  5335. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5336. $newentry->description = $param->description;
  5337. $newentry->visible = $param->visible;
  5338. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5339. if (!$newentry->id) {
  5340. print_error('error_add_param', 'iassign');
  5341. }
  5342. }
  5343. /// Function for delete iLM param of database
  5344. // @param int $param_id Id of iLM param
  5345. static function delete_param ($param_id) {
  5346. global $DB;
  5347. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5348. print_error('error_delete_param', 'iassign');
  5349. }
  5350. }
  5351. } // class ilm_settings
  5352. /// Class for manage iLM files (editor).
  5353. class ilm_manager {
  5354. var $id; // course id
  5355. var $url;
  5356. var $from;
  5357. /// Constructor for the base ilm_manager class
  5358. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5359. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5360. function __construct ($id, $url, $from) {
  5361. $this->id = $id; // course id
  5362. $this->url = $url;
  5363. $this->from = $from;
  5364. }
  5365. /// Function to get iAssign content file in Moodle data (exercise)
  5366. // @calledby x function preview_ilm($iassign_ilm) :
  5367. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5368. function get_file_ilm () {
  5369. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5370. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5371. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5372. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5373. $md_file = $fs->get_file_by_id($fileid);
  5374. $ilm_content_file = $md_file->get_content();
  5375. return $ilm_content_file;
  5376. }
  5377. /// Function for creating a new file from the iLM online editor
  5378. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5379. function ilm_editor_new () {
  5380. global $CFG, $DB, $OUTPUT, $PAGE;
  5381. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5382. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5383. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5384. $context = context_course::instance($this->id);
  5385. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5386. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5387. if (!$iassign) {
  5388. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5389. die();
  5390. }
  5391. $temp = explode(",", $iassign->extension);
  5392. $extension = $temp[0]; // default extension for this iLM
  5393. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5394. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5395. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5396. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5397. if ($stringArchiveContent != NULL) {
  5398. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5399. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5400. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5401. $filename = optional_param('filename', NULL, PARAM_RAW);
  5402. //Leo $filename = iassign_utils::format_filename($filename); //
  5403. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5404. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5405. //2019/02 $arrayfilename = explode(".", $filename);
  5406. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5407. //2019/02 $count_dots = count($arrayfilename);
  5408. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5409. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5410. //2019/02 if ($last_name != $extension)
  5411. //2019/02 $filename = $filename . '.' . $extension;
  5412. //2019/02 }
  5413. //2019/02 else { // no extension...
  5414. //2019/02 $filename = $filename . '.' . $extension;
  5415. //2019/02 }
  5416. // Store the name of recent created file
  5417. $_SESSION['file_name'] = $filename;
  5418. //$this->write_file_iassign($string, $filename);
  5419. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5420. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5421. die();
  5422. }
  5423. else { // if ($stringArchiveContent != NULL)
  5424. // iLM On-line editor
  5425. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5426. $str_get_iLM = "window.frames.iLM";
  5427. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5428. }
  5429. else { // otherwise it is JAR named 'iLM'
  5430. $str_get_iLM = "document.iLM";
  5431. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5432. }
  5433. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5434. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5435. $files_array = '';
  5436. foreach ($files as $value) {
  5437. if ($value->get_filename() != ".")
  5438. $files_array .= "'" . $value->get_filename() . "',";
  5439. }
  5440. $files_array .= "''";
  5441. $file = null;
  5442. $ia_content = "";
  5443. $filename = "";
  5444. $error_files_exists = get_string('error_file_exists', 'iassign');
  5445. $output = "<script type='text/javascript'>
  5446. //<![CDATA[
  5447. //D alert('locallib.php: ilm_editor_new');
  5448. function submit_iLM_Answer () {
  5449. var docFormOnLineEditor = document.formEnvio;
  5450. var resposta_exerc = new Array(3);
  5451. var valor_resposta = new Array(3);
  5452. var sessao = new Array(3);
  5453. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5454. resposta_exerc[0] = doc_iLM.getAnswer();
  5455. valor_resposta[0] = doc_iLM.getEvaluation();
  5456. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5457. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5458. var files = new Array(" . $files_array . ");
  5459. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5460. if (docFormOnLineEditor.filename.value=='') {
  5461. // ERROR: the file name is empty
  5462. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5463. return false;
  5464. }
  5465. // }
  5466. for (i=0; i<files.length; i++) {
  5467. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5468. alert('" . $error_files_exists . "');
  5469. return false;
  5470. }
  5471. }
  5472. docFormOnLineEditor.submit();
  5473. return true;
  5474. }
  5475. //]]>
  5476. </script>\n";
  5477. $output .= "
  5478. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5479. $output .= $OUTPUT->box_start();
  5480. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5481. $output .= "
  5482. <table width='100%' cellpadding='20'>
  5483. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5484. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5485. </tr>
  5486. </table>\n";
  5487. $output .= $OUTPUT->box_end();
  5488. $output .= "<center>\n";
  5489. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5490. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5491. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5492. $output .= $output_ilm;
  5493. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5494. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5495. </center>
  5496. </form>\n";
  5497. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5498. $PAGE->navbar->add($title);
  5499. $PAGE->set_title($title);
  5500. $PAGE->set_heading($title); // insert title above the navigation bar
  5501. print $OUTPUT->header();
  5502. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5503. print $output;
  5504. print $OUTPUT->footer();
  5505. }
  5506. die();
  5507. } // function ilm_editor_new()
  5508. /// Function for editing an file in online editor
  5509. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5510. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5511. global $CFG, $DB, $OUTPUT, $PAGE;
  5512. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5513. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5514. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5515. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5516. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5517. // If iLM is not registered, error!
  5518. if (!$iassign) {
  5519. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5520. die;
  5521. }
  5522. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5523. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5524. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5525. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5526. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5527. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5528. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5529. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5530. if ($stringArchiveContent != NULL) {
  5531. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5532. die();
  5533. } else { // if ($stringArchiveContent != NULL)
  5534. $end_file = '';
  5535. if ($content_file) {
  5536. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5537. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5538. }
  5539. $temp = explode(",", $iassign->extension);
  5540. $extension = $temp[0]; // default extension for this iLM
  5541. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5542. $str_get_iLM = "window.frames.iLM";
  5543. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5544. } else { // otherwise it is JAR named 'iLM'
  5545. $str_get_iLM = "document.iLM";
  5546. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5547. }
  5548. $output = "<script type='text/javascript'>
  5549. //<![CDATA[
  5550. function submit_iLM_Answer () {
  5551. var docFormEditor = document.formEnvio;
  5552. var activityAnswer; // to get activity answer (text)
  5553. var activityValue; // to get activity answer value (float)
  5554. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5555. //activityAnswer = doc_iLM.getAnswer();
  5556. //activityValue = doc_iLM.getEvaluation();
  5557. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5558. activityValue = " . $str_get_iLM . ".getEvaluation();
  5559. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5560. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5561. docFormEditor.submit();
  5562. return true;
  5563. }
  5564. //]]>
  5565. </script>\n";
  5566. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5567. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5568. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5569. // return true;
  5570. // }
  5571. $output .= "
  5572. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5573. $output .= $OUTPUT->box_start();
  5574. $output .= "
  5575. <table width='100%' cellpadding='20'>
  5576. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5577. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5578. <input type='hidden' name='filename' value='$filename'/></td>
  5579. <td>
  5580. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5581. </tr>
  5582. </table>\n";
  5583. $output .= $OUTPUT->box_end();
  5584. $output .= " <center>\n";
  5585. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5586. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5587. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5588. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5589. </center>
  5590. </form>\n";
  5591. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5592. $PAGE->navbar->add($title);
  5593. $PAGE->set_title($title);
  5594. $PAGE->set_heading($title); // insert title above the navigation bar
  5595. print $OUTPUT->header();
  5596. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5597. print $output;
  5598. print $OUTPUT->footer();
  5599. } // else if ($stringArchiveContent != NULL)
  5600. die();
  5601. } // function ilm_editor_update()
  5602. /// Function for write iAssign file in Moodle data (exercise)
  5603. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5604. // @param string $stringArchiveContent Content of iassign file
  5605. // @param string $filename Filename of iassign file
  5606. function write_file_iassign ($stringArchiveContent, $filename) {
  5607. global $USER;
  5608. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5609. $context = context_course::instance($this->id);
  5610. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5611. $dirid = $this->get_dir_ilm('dirid');
  5612. $dir = $fs->get_file_by_id($dirid);
  5613. $fileinfo = array('contextid' => $context->id, // ID of course
  5614. 'component' => 'mod_iassign', // usually = table name
  5615. 'filearea' => 'activity', // usually = table name
  5616. 'itemid' => 0, // usually = ID of row in table
  5617. 'filepath' => '/', // any path beginning and ending whith '/'
  5618. 'userid' => $USER->id,
  5619. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5620. 'filename' => $filename); // any filename
  5621. // Create file containing text. '$stringArchiveContent'
  5622. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5623. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5624. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5625. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5626. // 'Activité interactive enregistrée avec succès sous le nom:';
  5627. // 'Atividade interativa gravada com sucesso sob o nome:'
  5628. $output = "
  5629. <script type='text/javascript'>
  5630. //<![CDATA[
  5631. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5632. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5633. //]]>
  5634. </script>";
  5635. print $output;
  5636. die();
  5637. }
  5638. /// Function for write iAssign file in Moodle data (exercise)
  5639. // @param string $stringArchiveContent Content of iassign file
  5640. // @param string $filename Filename of iassign file
  5641. // @param int $itemid Itemid of iassign file
  5642. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5643. global $OUTPUT, $USER;
  5644. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5645. $context = context_course::instance($this->id);
  5646. $dirid = $this->get_dir_ilm('dirid');
  5647. if ($stringArchiveContent != (-1)) {
  5648. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5649. $file = $fs->get_file_by_id($fileid);
  5650. if (!$file) {
  5651. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5652. die;
  5653. }
  5654. $fileinfo = array('contextid' => $context->id, // ID of context
  5655. 'component' => 'mod_iassign', // usually = table name
  5656. 'filearea' => 'activity', // usually = table name
  5657. 'itemid' => 0, // usually = ID of row in table
  5658. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5659. 'userid' => $USER->id,
  5660. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5661. 'license' => 'allrightsreserved', // allrightsreserved
  5662. 'timecreated' => $file->get_timecreated(),
  5663. 'filename' => $file->get_filename()); // any filename
  5664. $file->delete();
  5665. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5666. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5667. }
  5668. $output = "<script type='text/javascript'>
  5669. //<![CDATA[
  5670. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5671. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5672. //]]>
  5673. </script>";
  5674. print $output;
  5675. die();
  5676. }
  5677. /// Function for create an tag for iAssign filter
  5678. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5679. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5680. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5681. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5682. // @param int $fileid Id of file
  5683. // @return string Return an string with an tag of iassign filter
  5684. function tag_ilm ($fileid) {
  5685. global $DB;
  5686. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5687. $width = '600';
  5688. $height = '400';
  5689. $file = $fs->get_file_by_id($fileid);
  5690. $filetype = explode(".", $file->get_filename());
  5691. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5692. foreach ($iassign_ilm as $value) {
  5693. $extensions = explode(",", $value->extension);
  5694. if (in_array($filetype[1], $extensions)) {
  5695. $width = $value->width;
  5696. $height = $value->height;
  5697. }
  5698. }
  5699. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5700. }
  5701. /// Function for delete iAssign file in Moodle data (exercise)
  5702. function delete_file_ilm () {
  5703. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5704. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5705. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5706. $file = $fs->get_file_by_id($fileid);
  5707. if ($file)
  5708. $file->delete();
  5709. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5710. die();
  5711. }
  5712. /// Function for delete selected iAssign file in Moodle data (exercise)
  5713. function delete_selected_ilm () {
  5714. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5715. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5716. $context = context_course::instance($this->id);
  5717. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5718. $dirid = $this->get_dir_ilm('dirid');
  5719. foreach ($files_id as $file_id) {
  5720. $file = $fs->get_file_by_id($file_id);
  5721. if ($file) {
  5722. if (!$file->is_directory())
  5723. $file->delete();
  5724. else {
  5725. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5726. foreach ($files_delete as $value)
  5727. $value->delete();
  5728. $file->delete();
  5729. }
  5730. }
  5731. }
  5732. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5733. die();
  5734. }
  5735. /// Function for duplicate iAssign file from "online" edition
  5736. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5737. function duplicate_file_ilm () {
  5738. global $USER, $COURSE;
  5739. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5740. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5741. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5742. $filename = optional_param('filename', NULL, PARAM_RAW);
  5743. $file = $fs->get_file_by_id($fileid);
  5744. $context = context_course::instance($this->id);
  5745. $fileinfo = array(
  5746. 'contextid' => $context->id, // ID of context
  5747. 'component' => 'mod_iassign', // usually = table name
  5748. 'filearea' => 'activity', // usually = table name
  5749. 'itemid' => 0, // usually = ID of row in table
  5750. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5751. 'userid' => $USER->id,
  5752. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5753. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5754. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5755. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5756. die();
  5757. }
  5758. /// Function for rename iAssign file
  5759. function rename_file_ilm () {
  5760. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5761. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5762. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5763. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5764. $file = $fs->get_file_by_id($fileid);
  5765. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5766. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5767. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5768. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5769. die();
  5770. }
  5771. /// Function for get iassign file for iassign form
  5772. function add_ilm () {
  5773. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5774. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5775. $output = "
  5776. <script type='text/javascript'>
  5777. //<![CDATA[
  5778. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5779. iassign_file_link.innerHTML = '$filename';
  5780. window.opener.document.forms['mform1'].file.value='$fileid';
  5781. window.opener.document.forms['mform1'].filename.value='$filename';
  5782. window.close();
  5783. //]]>
  5784. </script>";
  5785. print $output;
  5786. die();
  5787. }
  5788. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5789. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5790. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5791. function preview_ilm ($courseid, $iassign_ilm) {
  5792. global $OUTPUT, $CFG, $USER;
  5793. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5794. $title = get_string('modulename', 'iassign'); // iAssign
  5795. print $OUTPUT->header();
  5796. print $OUTPUT->box_start();
  5797. $javascript = "
  5798. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5799. <script type='text/javascript'>
  5800. //<![CDATA[
  5801. function submit_close () {
  5802. window.opener.location.reload();
  5803. window.close();
  5804. }
  5805. //]]>
  5806. </script>\n";
  5807. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5808. // to the complete "applet" tag
  5809. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5810. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5811. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5812. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5813. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5814. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5815. if ($ilm_name != "ivprog") {
  5816. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5817. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5818. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5819. } else {
  5820. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5821. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5822. $timecreated = time();
  5823. $token = md5($timecreated);
  5824. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5825. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5826. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5827. $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)
  5828. }
  5829. $html = "
  5830. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5831. <table border='1'>
  5832. <tr><td>
  5833. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5834. <!-- iLM calls : end -->
  5835. </td></tr>
  5836. </table>
  5837. <table>
  5838. <tr>
  5839. <td align='center'>
  5840. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5841. </td></tr>
  5842. </table>
  5843. </form>\n";
  5844. print $javascript . $html;
  5845. print $OUTPUT->box_end();
  5846. //NAO echo format_string($html); // Moodle 3.X
  5847. die();
  5848. } // function preview_ilm($courseid, $iassign_ilm)
  5849. //r_ function preview_ilm ($iassign_ilm)
  5850. //r_ /// Function for preview iassign file from iassign filter.
  5851. //r_ function preview_ilm() {
  5852. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5853. //r_ $tag_filter = $this->tag_ilm($fileid);
  5854. //r_ $javascript = "<script type='text/javascript'>
  5855. //r_ //<![CDATA[
  5856. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5857. //r_ //]]>
  5858. //r_ </script>";
  5859. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5860. //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>
  5861. //r_ </table></form></body></html>";
  5862. //r_ echo $javascript . format_text($html);
  5863. //r_ die;
  5864. //r_ }
  5865. /// Function for export an package (zip) of iassign files
  5866. function export_files_ilm () {
  5867. global $CFG;
  5868. $context = context_course::instance($this->id);
  5869. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5870. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5871. $zip = new zip_archive();
  5872. $zip->open($zip_filename);
  5873. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5874. foreach ($files_id as $file_id) {
  5875. $file = $fs->get_file_by_id($file_id);
  5876. if (!$file->is_directory())
  5877. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5878. else {
  5879. $zip->add_directory($file->get_filepath());
  5880. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5881. foreach ($files_zip as $value) {
  5882. if (!$value->is_directory())
  5883. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5884. else
  5885. $zip->add_directory($value->get_filepath());
  5886. }
  5887. }
  5888. }
  5889. $zip->close();
  5890. header("Pragma: public");
  5891. header("Expires: 0");
  5892. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5893. header("Cache-Control: private", false);
  5894. header("Content-Type: application/zip");
  5895. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5896. header("Content-Transfer-Encoding: binary");
  5897. header("Content-Length: " . @filesize($zip_filename));
  5898. set_time_limit(0);
  5899. @readfile("$zip_filename") || die("File not found.");
  5900. unlink($zip_filename);
  5901. exit;
  5902. }
  5903. /// Function of execute a command in button editor tinymce
  5904. // @param int $fileid Id of file
  5905. function tinymce_ilm ($fileid) {
  5906. $tag_filter = $this->tag_ilm($fileid);
  5907. $output = "<script type='text/javascript'>
  5908. //<![CDATA[
  5909. var tag_filter = '$tag_filter';
  5910. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5911. // all right, insert it
  5912. } else {
  5913. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5914. }
  5915. // window.close();
  5916. //]]>
  5917. </script>\n";
  5918. print $output;
  5919. die();
  5920. }
  5921. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5922. /// Function to add content to the Editor Window
  5923. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5924. // @param int $fileid Id of file
  5925. function editor_ilm ($fileid, $editor) {
  5926. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5927. $output1 = "<script type='text/javascript'>
  5928. //<![CDATA[
  5929. var tag_filter = '$tag_filter';\n";
  5930. if ($editor == 'atto') {
  5931. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5932. } elseif ($editor == 'tinyMCE') {
  5933. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5934. } else
  5935. $output2 = "";
  5936. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5937. window.close();
  5938. //]]>
  5939. </script>\n";
  5940. //D var_dump($output);
  5941. print $output1 . $output2 . $output3;
  5942. die();
  5943. }
  5944. /// Function to add content to the Atto Editor Window
  5945. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5946. // @param int $fileid Id of file
  5947. function atto_ilm ($fileid) {
  5948. global $CFG, $DB;
  5949. $tag_filter = $this->tag_ilm($fileid);
  5950. $output = "<script type='text/javascript'>
  5951. //<![CDATA[
  5952. var tag_filter = '$tag_filter';
  5953. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5954. // all right, insert iLM tag to this editor
  5955. } else {
  5956. // error trying to insert
  5957. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5958. }
  5959. //window.close();
  5960. //]]>
  5961. </script>\n";
  5962. print $output;
  5963. die();
  5964. }
  5965. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5966. // @param string $key Key for return information
  5967. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5968. function get_dir_ilm ($key) {
  5969. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5970. $context = context_course::instance($this->id);
  5971. $dirid = optional_param('dirid', 0, PARAM_INT);
  5972. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5973. if ($dirid == 0) {
  5974. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5975. $dirid = $dir->get_id();
  5976. }
  5977. else {
  5978. $dir = $fs->get_file_by_id($dirid);
  5979. $dir_base = $dir->get_filepath();
  5980. }
  5981. $dir_parent = $dir->get_parent_directory();
  5982. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5983. return $data[$key];
  5984. }
  5985. /// Function for create an new dir
  5986. function new_dir_ilm () {
  5987. global $USER;
  5988. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5989. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5990. $dir_base = $this->get_dir_ilm('dir_base');
  5991. $context = context_course::instance($this->id);
  5992. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5993. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5994. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5995. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5996. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5997. }
  5998. /// Function for delete an dir
  5999. function delete_dir_ilm () { //
  6000. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6001. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6002. $context = context_course::instance($this->id);
  6003. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6004. $dir_parent = $this->get_dir_ilm('dir_parent');
  6005. if ($dir) {
  6006. if ($dir->is_directory()) {
  6007. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6008. foreach ($files_delete as $value)
  6009. $value->delete();
  6010. $dir->delete();
  6011. }
  6012. }
  6013. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6014. die();
  6015. }
  6016. /// Function for rename an dir
  6017. function rename_dir_ilm () {
  6018. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6019. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6020. $context = context_course::instance($this->id);
  6021. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6022. $dir_parent = $this->get_dir_ilm('dir_parent');
  6023. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6024. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6025. if ($dir->is_directory()) {
  6026. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6027. foreach ($files_rename_path as $value)
  6028. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6029. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6030. }
  6031. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6032. die();
  6033. }
  6034. /// Function for move an dir and your content for other dir
  6035. function selected_move_ilm () {
  6036. global $PAGE, $OUTPUT, $CFG;
  6037. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6038. $context = context_course::instance($this->id);
  6039. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6040. $dirid = $this->get_dir_ilm('dirid');
  6041. $dir_base = $this->get_dir_ilm('dir_base');
  6042. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6043. $code_javascript_ilm = "
  6044. <script type='text/javascript'>
  6045. //<![CDATA[
  6046. function getRadiobutton () {
  6047. var radioButtons = document.getElementsByTagName('input');
  6048. var param = '';
  6049. for (var counter=0; counter < radioButtons.length; counter++) {
  6050. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6051. param = radioButtons[counter].value;
  6052. }
  6053. return param;
  6054. }
  6055. function move_selected_ilm () {
  6056. var msgAnswer;
  6057. if (getRadiobutton() != '') {
  6058. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6059. if (msgAnswer)
  6060. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6061. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6062. }
  6063. else
  6064. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6065. }
  6066. function cancel_selected_ilm () {
  6067. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6068. }
  6069. //]]>
  6070. </script>\n";
  6071. $title = get_string('move_files', 'iassign');
  6072. $PAGE->set_title($title);
  6073. $PAGE->set_pagelayout('base');
  6074. print $OUTPUT->header();
  6075. print $OUTPUT->heading($title);
  6076. $dir_paths = array();
  6077. print $OUTPUT->box_start();
  6078. print "<center>";
  6079. foreach ($files_id as $file_id) {
  6080. $file = $fs->get_file_by_id($file_id);
  6081. if ($file) {
  6082. if (!$file->is_directory())
  6083. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6084. else {
  6085. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6086. array_push($dir_paths, $file->get_filepath());
  6087. }
  6088. }
  6089. }
  6090. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6091. if ($dir_base != '/') {
  6092. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6093. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6094. }
  6095. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6096. foreach ($files_tree as $file) {
  6097. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6098. $is_parent = false;
  6099. foreach ($dir_paths as $dir) {
  6100. $path = explode("/", $dir);
  6101. array_pop($path);
  6102. $path[count($path) - 1] = '';
  6103. $path = implode("/", $path);
  6104. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6105. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6106. }
  6107. if ($is_parent == false) {
  6108. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6109. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6110. }
  6111. }
  6112. }
  6113. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6114. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6115. print "</center>";
  6116. print $OUTPUT->box_end();
  6117. print $OUTPUT->footer();
  6118. print $code_javascript_ilm;
  6119. die;
  6120. }
  6121. /// Function for move files for an dir
  6122. function move_files_ilm () {
  6123. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6124. $context = context_course::instance($this->id);
  6125. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6126. $dirid = $this->get_dir_ilm('dirid');
  6127. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6128. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6129. foreach ($files_id as $file_id) {
  6130. $file = $fs->get_file_by_id($file_id);
  6131. if ($file) {
  6132. if ($file->is_directory()) {
  6133. $pathname = explode("/", $file->get_filepath());
  6134. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6135. foreach ($files_move_path as $value) {
  6136. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6137. $value->rename($path_move, $value->get_filename());
  6138. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6139. }
  6140. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6141. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6142. $file->rename($path_move, $file->get_filename());
  6143. } else {
  6144. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6145. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6146. }
  6147. }
  6148. }
  6149. //die;
  6150. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6151. die();
  6152. } // function move_files_ilm()
  6153. /// Function for recover files in use on all activities of a course
  6154. function recover_files_ilm () {
  6155. global $DB, $USER;
  6156. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6157. $courseid = optional_param('id', NULL, PARAM_INT);
  6158. $dirid = $this->get_dir_ilm('dirid');
  6159. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6160. $contextfile = context_course::instance($this->id);
  6161. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6162. foreach ($iassigns as $iassign) {
  6163. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6164. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6165. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6166. $context = context_module::instance($cm->id);
  6167. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6168. if ($files) {
  6169. foreach ($files as $value) {
  6170. $extension = explode(".", $value->get_filename());
  6171. if (!$value->is_directory()) {
  6172. $fileinfo = array('contextid' => $contextfile->id,
  6173. 'component' => 'mod_iassign',
  6174. 'filearea' => 'activity',
  6175. 'itemid' => 0,
  6176. 'filepath' => $this->get_dir_ilm('dir_base'),
  6177. 'userid' => $USER->id,
  6178. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6179. 'license' => 'allrightsreserved',
  6180. 'timecreated' => time(),
  6181. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6182. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6183. }
  6184. }
  6185. } // if ($files)
  6186. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6187. } // foreach ($iassigns as $iassign)
  6188. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6189. die();
  6190. } // function recover_files_ilm()
  6191. /// Auxiliary function the get all files in a given context
  6192. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6193. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6194. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6195. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6196. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6197. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6198. // (NAO s_iassign_statement.file = s_files.id)
  6199. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6200. $dir_base = $this->get_dir_ilm('dir_base');
  6201. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6202. $countf = 0;
  6203. $array_files_id = array(); // all files from this context
  6204. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6205. //$filename = $item_fc->get_filename();
  6206. //$filepath = $item_fc->get_filepath();
  6207. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6208. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6209. // $array_files_aux[] = $item_fc;
  6210. $itemid = $item_fc->get_id();
  6211. if (!in_array($itemid, $array_files_id)) {
  6212. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6213. if ($fileuserid == $userid)
  6214. $filesfrommine[] = $item_fc;
  6215. else
  6216. $filesfromothers[] = $item_fc;
  6217. $array_files_id[] = $itemid;
  6218. $countf++;
  6219. }
  6220. }
  6221. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6222. return $countf;
  6223. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6224. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6225. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6226. function get_all_ilm_files_by_fileid ($fileid) {
  6227. global $DB, $USER;
  6228. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6229. //TODO Criar coluna 'authorid'
  6230. $str_query = "SELECT * FROM {iassign_statement} " .
  6231. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6232. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6233. return $array_iassign_ilm;
  6234. }
  6235. //NN
  6236. //NN
  6237. // Build string with JavaScript code with function to edit/remove/double iLM files
  6238. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6239. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6240. global $CFG;
  6241. $error_files_exists = get_string('error_file_exists', 'iassign');
  6242. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6243. $code_javascript_ilm = "
  6244. <script type='text/javascript'>
  6245. //<![CDATA[
  6246. function preview_ilm (fileid, ilmid) { //JavaScript function
  6247. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6248. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6249. }
  6250. function update_ilm (ilmid, fileid) { //JavaScript function
  6251. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6252. }
  6253. function delete_ilm (ilmid, fileid) { //JavaScript function
  6254. var msgAnswer;
  6255. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6256. if (msgAnswer) {
  6257. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6258. }
  6259. }
  6260. function delete_selected_ilm () { //JavaScript function
  6261. var msgAnswer;
  6262. var param = getCheckbox();
  6263. if (param.join() != '') {
  6264. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6265. if (msgAnswer)
  6266. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6267. }
  6268. else
  6269. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6270. }
  6271. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6272. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6273. }
  6274. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6275. var filenamecopy;
  6276. var i;
  6277. var files = new Array(" . $files_array . ");
  6278. do {
  6279. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6280. } while (filenamecopy == '');
  6281. if (filenamecopy == null)
  6282. return false;\n
  6283. else {
  6284. for (i=0;i<files.length;i++) {
  6285. if (files[i]==filenamecopy) {
  6286. alert('" . $error_files_exists . "');
  6287. return false;\n
  6288. }
  6289. }\n" .
  6290. // @see: function 'duplicate_file_ilm()' above
  6291. "
  6292. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6293. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6294. } // else
  6295. }
  6296. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6297. var filenamecopy;
  6298. var i;
  6299. var files = new Array($files_array);
  6300. do {
  6301. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6302. } while (filenamecopy == '');
  6303. if (filenamecopy == null)
  6304. return false;
  6305. else {
  6306. for (i=0;i<files.length;i++) {
  6307. if (files[i]==filenamecopy) {
  6308. alert('" . $error_files_exists . "');
  6309. return false;
  6310. }
  6311. }
  6312. 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;
  6313. }
  6314. }
  6315. function export_files_ilm () { //JavaScript function
  6316. var param = getCheckbox();
  6317. if (param.join() != '')
  6318. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6319. else
  6320. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6321. }
  6322. function select_all_ilm () { //JavaScript function
  6323. var checkBoxes = document.getElementsByTagName('input');
  6324. var selectAll = document.getElementById('select_all');
  6325. for (var counter=0; counter < checkBoxes.length; counter++) {
  6326. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6327. checkBoxes[counter].checked = selectAll.checked;
  6328. }
  6329. }
  6330. function getCheckbox () { //JavaScript function
  6331. var checkBoxes = document.getElementsByTagName('input');
  6332. var param = new Array();
  6333. for (var counter=0; counter < checkBoxes.length; counter++) {
  6334. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6335. param.push(checkBoxes[counter].value);
  6336. }
  6337. return param;
  6338. }
  6339. function new_dir_ilm () { //JavaScript function
  6340. var dirname = '';
  6341. var i;
  6342. var dirs = new Array(" . $dirs_array . ");
  6343. do {
  6344. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6345. } while (dirname == '');
  6346. if (dirname == null)
  6347. return false;\n
  6348. else {
  6349. for (i=0;i<dirs.length;i++) {
  6350. if (dirs[i]==dirname) {
  6351. alert('" . $error_dir_exists . "');
  6352. return false;\n
  6353. }
  6354. }
  6355. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6356. }
  6357. }
  6358. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6359. var msgAnswer;
  6360. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6361. if (msgAnswer) {
  6362. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6363. }
  6364. }
  6365. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6366. var dirnamecopy;
  6367. var i;
  6368. var dirs = new Array($dirs_array);
  6369. do {
  6370. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6371. } while (dirnamecopy == '');
  6372. if (dirnamecopy == null)
  6373. return false;\n
  6374. else {
  6375. for (i=0;i<dirs.length;i++) {
  6376. if (dirs[i]==dirnamecopy) {
  6377. alert('" . $error_dir_exists . "');
  6378. return false;\n
  6379. }
  6380. }
  6381. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6382. }
  6383. }
  6384. function move_selected_ilm (ilmid) { //JavaScript function
  6385. var param = getCheckbox();
  6386. if (param.join() != '')
  6387. 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();
  6388. else
  6389. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6390. }
  6391. function recover_files_ilm () { //JavaScript function
  6392. var msgAnswer;
  6393. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6394. if (msgAnswer) {
  6395. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6396. }
  6397. }
  6398. window.onload = function() { //JavaScript function
  6399. var xPosition = 0;
  6400. var yPosition = 0;
  6401. element=document.getElementById('new_file');
  6402. while(element) {
  6403. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6404. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6405. element = element.offsetParent;
  6406. }
  6407. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6408. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6409. location.hash = '#new_file';
  6410. };
  6411. //]]>
  6412. </script>\n"; // end of $code_javascript_ilm
  6413. return $code_javascript_ilm;
  6414. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6415. /// List iassign files from course directory
  6416. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6417. function view_files_ilm ($iassign_ilm_class, $extension) {
  6418. global $CFG, $DB, $USER, $OUTPUT;
  6419. $fs = get_file_storage();
  6420. $context = context_course::instance($this->id);
  6421. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6422. $dirid = $this->get_dir_ilm('dirid');
  6423. $dir_base = $this->get_dir_ilm('dir_base');
  6424. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6425. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6426. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6427. $files_array = '';
  6428. foreach ($files_course as $value) {
  6429. if (!$value->is_directory())
  6430. $files_array .= "'" . $value->get_filename() . "',";
  6431. }
  6432. $files_array .= "''";
  6433. $error_files_exists = get_string('error_file_exists', 'iassign');
  6434. $dirs_array = '';
  6435. foreach ($files_course as $value) {
  6436. if ($value->is_directory()) {
  6437. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6438. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6439. }
  6440. }
  6441. $dirs_array .= "''";
  6442. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6443. // TODO Rever o preview pois só deixar ver uma vez.
  6444. $code_javascript_ilm = "
  6445. <script type='text/javascript'>
  6446. //<![CDATA[
  6447. function preview_ilm (fileid, ilmid) {
  6448. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6449. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6450. }
  6451. function update_ilm (ilmid, fileid) {
  6452. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6453. }
  6454. function delete_ilm (ilmid, fileid) {
  6455. var msgAnswer;
  6456. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6457. if (msgAnswer) {
  6458. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6459. }
  6460. }
  6461. function delete_selected_ilm () {
  6462. var msgAnswer;
  6463. var param = getCheckbox();
  6464. if (param.join() != '') {
  6465. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6466. if (msgAnswer)
  6467. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6468. }
  6469. else
  6470. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6471. }
  6472. function add_ilm_iassign (ilmid, filename, fileid) {
  6473. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6474. }
  6475. function duplicate_ilm (ilmid, filename, fileid) {
  6476. var filenamecopy;
  6477. var i;
  6478. var files = new Array($files_array);
  6479. do {
  6480. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6481. } while (filenamecopy == '');
  6482. if (filenamecopy == null)
  6483. return false;\n
  6484. else {
  6485. for (i=0;i<files.length;i++) {
  6486. if (files[i]==filenamecopy) {
  6487. alert('$error_files_exists');
  6488. return false;\n
  6489. }
  6490. }\n" .
  6491. // @see: function 'duplicate_file_ilm()' above
  6492. "
  6493. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6494. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6495. } // else
  6496. }
  6497. function rename_ilm (ilmid, filename, fileid) {
  6498. var filenamecopy;
  6499. var i;
  6500. var files = new Array($files_array);
  6501. do {
  6502. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6503. } while (filenamecopy == '');
  6504. if (filenamecopy == null)
  6505. return false;
  6506. else {
  6507. for (i=0;i<files.length;i++) {
  6508. if (files[i]==filenamecopy) {
  6509. alert('$error_files_exists');
  6510. return false;
  6511. }
  6512. }
  6513. 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;
  6514. }
  6515. }
  6516. function export_files_ilm () {
  6517. var param = getCheckbox();
  6518. if (param.join() != '')
  6519. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6520. else
  6521. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6522. }
  6523. function select_all_ilm () {
  6524. var checkBoxes = document.getElementsByTagName('input');
  6525. var selectAll = document.getElementById('select_all');
  6526. for (var counter=0; counter < checkBoxes.length; counter++) {
  6527. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6528. checkBoxes[counter].checked = selectAll.checked;
  6529. }
  6530. }
  6531. function getCheckbox () {
  6532. var checkBoxes = document.getElementsByTagName('input');
  6533. var param = new Array();
  6534. for (var counter=0; counter < checkBoxes.length; counter++) {
  6535. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6536. param.push(checkBoxes[counter].value);
  6537. }
  6538. return param;
  6539. }
  6540. function new_dir_ilm () {
  6541. var dirname = '';
  6542. var i;
  6543. var dirs = new Array($dirs_array);
  6544. do {
  6545. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6546. } while (dirname == '');
  6547. if (dirname == null)
  6548. return false;\n
  6549. else {
  6550. for (i=0;i<dirs.length;i++) {
  6551. if (dirs[i]==dirname) {
  6552. alert('$error_dir_exists');
  6553. return false;\n
  6554. }
  6555. }
  6556. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6557. }
  6558. }
  6559. function delete_dir_ilm (ilmid, dirid) {
  6560. var msgAnswer;
  6561. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6562. if (msgAnswer) {
  6563. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6564. }
  6565. }
  6566. function rename_dir_ilm (ilmid, dirname, dirid) {
  6567. var dirnamecopy;
  6568. var i;
  6569. var dirs = new Array($dirs_array);
  6570. do {
  6571. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6572. } while (dirnamecopy == '');
  6573. if (dirnamecopy == null)
  6574. return false;\n
  6575. else {
  6576. for (i=0;i<dirs.length;i++) {
  6577. if (dirs[i]==dirnamecopy) {
  6578. alert('$error_dir_exists');
  6579. return false;\n
  6580. }
  6581. }
  6582. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6583. }
  6584. }
  6585. function move_selected_ilm (ilmid) {
  6586. var param = getCheckbox();
  6587. if (param.join() != '')
  6588. 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();
  6589. else
  6590. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6591. }
  6592. function recover_files_ilm () {
  6593. var msgAnswer;
  6594. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6595. if (msgAnswer) {
  6596. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6597. }
  6598. }
  6599. window.onload = function() {
  6600. var xPosition = 0;
  6601. var yPosition = 0;
  6602. element=document.getElementById('new_file');
  6603. while(element) {
  6604. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6605. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6606. element = element.offsetParent;
  6607. }
  6608. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6609. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6610. location.hash = '#new_file';
  6611. };
  6612. //]]>
  6613. </script>\n";
  6614. $output = "";
  6615. $select_all = "";
  6616. $count_files = 0;
  6617. $extensions_allow = array();
  6618. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6619. foreach ($iassign_ilm as $item_iassign_ilm)
  6620. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6621. foreach ($files_course as $value) {
  6622. $filename = $value->get_filename();
  6623. $filepath = $value->get_filepath();
  6624. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6625. $pathname = $pathname[count($pathname) - 1];
  6626. $fileid = $value->get_id();
  6627. $tmp = explode(".", $filename);
  6628. if (count($tmp)>1) // avoid error if the file has no extension
  6629. $filetype = $tmp[1];
  6630. else // probably error...
  6631. $filetype = '';
  6632. $author = $value->get_author();
  6633. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6634. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6635. $extensions = explode(",", $extension);
  6636. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6637. $count_files ++;
  6638. // buscar fileid nas tabelas do iassign
  6639. $list_filein_use = "";
  6640. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6641. if ($iassign_statement_activity_list) {
  6642. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6643. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6644. }
  6645. }
  6646. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6647. if (!$iassign_ilm) {
  6648. $iassign_ilm = new stdClass();
  6649. $iassign_ilm->id = $ilmid;
  6650. }
  6651. // Do not use $var inside "..." - problem with some "unusual" operational system
  6652. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6653. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6654. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6655. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6656. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6657. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6658. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6659. $check_select = "";
  6660. $link_rename = "";
  6661. $link_delete = "";
  6662. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6663. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6664. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6665. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6666. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6667. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6668. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6669. if ($value->get_userid() == $USER->id) {
  6670. if ($iassign_statement_activity_list) {
  6671. $check_select = "";
  6672. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6673. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6674. $link_rename = "";
  6675. } else {
  6676. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6677. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6678. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6679. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6680. }
  6681. }
  6682. if (!in_array($filetype, $extensions_allow)) {
  6683. $link_edit = "";
  6684. $link_add_ilm_iassign = "";
  6685. $link_add_ilm_tinymce = "";
  6686. $link_add_ilm_atto = "";
  6687. $link_filter = "";
  6688. }
  6689. if ($value->is_directory()) {
  6690. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6691. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6692. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6693. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6694. <td><center>$author</center></td>
  6695. <td><center>$timecreated</center></td>
  6696. <td><center>$timemodified</center></td></tr>\n";
  6697. }
  6698. else if ($this->from == 'iassign') {
  6699. $new_id = "";
  6700. $new_class = "";
  6701. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6702. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6703. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6704. }
  6705. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6706. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6707. <td><center>$author</center></td>
  6708. <td><center>$timecreated</center></td>
  6709. <td><center>$timemodified</center></td></tr>\n";
  6710. }
  6711. else if ($this->from == 'block') {
  6712. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6713. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6714. <td><center>$author</center></td>
  6715. <td><center>$timecreated</center></td>
  6716. <td><center>$timemodified</center></td></tr>\n";
  6717. }
  6718. else if ($this->from == 'tinymce') {
  6719. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6720. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6721. <td><center>$author</center></td>
  6722. <td><center>$timecreated</center></td>
  6723. <td><center>$timemodified</center></td></tr>\n";
  6724. }
  6725. else if ($this->from == 'atto') {
  6726. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6727. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6728. <td><center>$author</center></td>
  6729. <td><center>$timecreated</center></td>
  6730. <td><center>$timemodified</center></td></tr>\n";
  6731. }
  6732. }
  6733. }
  6734. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6735. $dir_base = "";
  6736. $header = "";
  6737. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6738. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6739. foreach ($basename as $value) {
  6740. $dir_base .= $value . "/";
  6741. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6742. if ($dir_id) {
  6743. if ($value == "") {
  6744. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6745. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6746. } else {
  6747. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6748. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6749. }
  6750. }
  6751. } // foreach ($basename as $value)
  6752. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6753. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6754. $html .= "
  6755. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6756. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6757. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6758. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6759. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6760. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6761. </table>\n";
  6762. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6763. $html .= "<table width='100%'><tr>\n";
  6764. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6765. if ($count_files != 0) {
  6766. $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";
  6767. $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";
  6768. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6769. }
  6770. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6771. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6772. $html .= "</form>\n";
  6773. print $code_javascript_ilm;
  6774. print $html;
  6775. } // function view_files_ilm($extension)
  6776. } // class ilm_manager
  6777. /// Class to insert of icons
  6778. class iassign_icons {
  6779. static function insert ($icon) {
  6780. global $CFG;
  6781. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6782. return $string;
  6783. }
  6784. }
  6785. /// Class with util functions for plugin manage
  6786. class iassign_utils {
  6787. /// Function to return the filename extension
  6788. // @param string The $filename as an string
  6789. // @return string Return an string (last group after '.')
  6790. static function filename_extension ($filename) {
  6791. if ($filename == null || $filename == '') {
  6792. return null;
  6793. }
  6794. $itens = explode('.', $filename);
  6795. $num = count($itens);
  6796. if ($num < 2) {
  6797. return null;
  6798. }
  6799. return $itens[$num - 1];
  6800. }
  6801. /// Use the PHP class/package ZipArchive to create a Zip file
  6802. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6803. // 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
  6804. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6805. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6806. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6807. $zip = new zip_archive(); //2
  6808. $res = $zip->open($full_path_zip_filename);
  6809. $total_vet = count($vet_student_filename);
  6810. for ($ii=0; $ii<$total_vet; $ii++) {
  6811. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6812. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6813. }
  6814. $ret = $zip->close();
  6815. iassign_utils::download_file($full_path_zip_filename);
  6816. $filenameZip = $zip->filename;
  6817. return array($ret, $zip);
  6818. }
  6819. static function download_file ($zip_filename) {
  6820. header("Pragma: public");
  6821. header("Expires: 0");
  6822. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6823. header("Cache-Control: private", false);
  6824. header("Content-Type: application/zip");
  6825. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6826. header("Content-Transfer-Encoding: binary");
  6827. header("Content-Length: " . @filesize($zip_filename));
  6828. set_time_limit(0);
  6829. @readfile("$zip_filename") || die("File not found.");
  6830. unlink($zip_filename);
  6831. }
  6832. /// Function for format filename remove special caracters
  6833. // @param string $text String for clean
  6834. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6835. // @return string Return an string in clean format
  6836. static function format_filename ($text) {
  6837. if ($text != '.') {
  6838. //D $text = htmlspecialchars(urldecode($text));
  6839. //D echo "locallib.php: format_filename: $text<br/>";
  6840. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6841. $text = json_decode($text)->{current_language()};
  6842. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6843. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6844. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6845. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6846. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6847. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6848. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6849. // E.g. text = "exerc_midpoint.course.geo"
  6850. // 0123456789012345678901234
  6851. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6852. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6853. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6854. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6855. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6856. //$ext = strrpos($text, ".");
  6857. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6858. //$text = str_replace($array1, $array2, $text);
  6859. }
  6860. return $text;
  6861. }
  6862. /// Function to filter characters to the file name to iLM content
  6863. // @param string $text String for clean
  6864. // @param string $ext String ot the extension of the iLM
  6865. // @return string Return an string in clean format
  6866. static function filter_filename_extension ($filename, $ext) {
  6867. if ($filename != '.') {
  6868. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6869. $arrTo = array("_","","","","","","","","","","","","");
  6870. $filename = str_replace($arrFrom, $arrTo, $filename);
  6871. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6872. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6873. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6874. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6875. $index_lastposition = strlen($filenameF);
  6876. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6877. $text = str_replace(".", "_", $text); // erase all other "."
  6878. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6879. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6880. }
  6881. else
  6882. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6883. return $filenameF;
  6884. }
  6885. /// Function for format pathname remove special caracters
  6886. // @param string $text String for clean
  6887. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6888. // @return string Return an string in clean format
  6889. static function format_pathname ($text, $is_lowercase = true) {
  6890. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6891. $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", "-", "_", "", "", "");
  6892. $text = str_replace($array1, $array2, $text);
  6893. if ($is_lowercase)
  6894. $text = strtolower($text);
  6895. return $text;
  6896. }
  6897. /// Function for format file name from iLM original name
  6898. // @param string $text String to build the file neam
  6899. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6900. // @return string Return an string in clean format
  6901. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6902. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6903. $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", "-", "_", "", "", "");
  6904. $index_firstposition_blank = strpos($ilm_name, " ");
  6905. if ($index_firstposition_blank) { // truncate the name!
  6906. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6907. }
  6908. $index_firstposition_dots = strpos($ilm_name, ":");
  6909. if ($index_firstposition_dots) { // truncate the name!
  6910. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6911. }
  6912. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6913. if ($is_lowercase)
  6914. $namefiltered = strtolower($namefiltered);
  6915. return $namefiltered;
  6916. }
  6917. /// Function for insert version in the filename
  6918. // @param string $filename Name of file
  6919. // @return string Return the filename with version
  6920. static function version_filename ($filename) {
  6921. $array_filename = explode('.', $filename);
  6922. if (count($array_filename) > 1)
  6923. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6924. else
  6925. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6926. return $filename;
  6927. }
  6928. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6929. static function remove_code_message ($string) {
  6930. $array = explode("&lt;ia_uc&gt;", $string);
  6931. return $array[0];
  6932. }
  6933. }
  6934. // class iassign_utils
  6935. /// Class with language functions for plugin manage
  6936. class iassign_language {
  6937. /// Function for return text in language or get default language (en)
  6938. // @param string $lang Code of language
  6939. // @param string $description JSON text content all languages
  6940. // @return string Return an string in the language selected
  6941. static function get_description_lang ($lang, $descriptions) {
  6942. $description_lang = "";
  6943. $description = json_decode($descriptions);
  6944. if ($description == null) {
  6945. $description_lang = $descriptions;
  6946. }
  6947. else {
  6948. if (isset($description->{$lang}))
  6949. $description_lang = $description->{$lang};
  6950. else
  6951. if (isset($description->en)) //MOOC2014
  6952. $description_lang = $description->en;
  6953. else //MOOC2014
  6954. $description_lang = "en"; //MOOC2014
  6955. }
  6956. return $description_lang;
  6957. }
  6958. /// Function for return all language supported by iLM
  6959. // @param string $descriptions JSON text content all languages
  6960. // @return string Return as string with all languages
  6961. static function get_all_lang ($descriptions) {
  6962. $langs = "";
  6963. $description = json_decode($descriptions);
  6964. if ($description) {
  6965. foreach ($description as $key => $value) {
  6966. $langs .= $key . " ; ";
  6967. }
  6968. $langs = substr($langs, 0, strlen($langs) - 3);
  6969. }
  6970. return $langs;
  6971. }
  6972. /// Function for convert json in xml //MOOC2014
  6973. // @param string $json JSON text
  6974. // @return string Return as string with xml tags
  6975. static function json_to_xml ($json) {
  6976. $xml = "";
  6977. $json = json_decode($json);
  6978. foreach ($json as $key => $value) {
  6979. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6980. }
  6981. return $xml;
  6982. }
  6983. }
  6984. // class iassign_language
  6985. /// Class with log functions for plugin manage.
  6986. class iassign_log {
  6987. /// Function for insert log event
  6988. // @param string $action Code action of event
  6989. // @param string $information Text for describe action of event
  6990. // @param int $cmid Id of context module
  6991. // @param int $ilmid Id of iLM
  6992. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6993. global $COURSE, $CFG, $USER, $DB;
  6994. $newentry = new stdClass();
  6995. $newentry->time = time();
  6996. $newentry->userid = $USER->id;
  6997. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6998. $newentry->course = $COURSE->id;
  6999. $newentry->cmid = $cmid;
  7000. $newentry->ilmid = $ilmid;
  7001. $newentry->action = $action;
  7002. $newentry->info = $information;
  7003. $newentry->language = current_language();
  7004. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7005. if (ini_get("browscap") && function_exists('get_browse')) {
  7006. $browser = get_browse(null, true);
  7007. $newentry->javascript = $browser['javascript'];
  7008. $newentry->java = $browser['javaapplets'];
  7009. }
  7010. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7011. print_error('error_add_log', 'iassign');
  7012. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7013. } // class iassign_log