locallib.php 359 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716
  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->get_answer();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. 'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'get_student_submission' => '$this->get_student_submission();',
  278. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  279. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  280. );
  281. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  282. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  283. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  284. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  285. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  286. }
  287. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  288. eval($action_iassign_limit[$this->action]);
  289. }
  290. else { // Student reaches this point
  291. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  292. // Arrive here with: "get_answer"; "view"
  293. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  294. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  295. }
  296. } // function action()
  297. /// This method prints the student submission to a specific exercise
  298. function get_student_submission () {
  299. global $DB;
  300. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  301. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  302. if (!$student || !$exercise) exit;
  303. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  304. if ($iassign_submission)
  305. print($iassign_submission->answer);
  306. die();
  307. }
  308. /// This method prints the teacher exercise
  309. function get_teacher_exercise () {
  310. global $DB, $COURSE;
  311. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  312. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  314. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  315. foreach ($files as $file) {
  316. if ($file->get_filename() != ".") {
  317. print($file->get_content());
  318. }
  319. }
  320. die();
  321. }
  322. /// This method receives the data from auto_eval event
  323. /// @see auto_evaluate()
  324. function post_auto_eval_result () {
  325. global $COURSE, $CFG, $USER, $DB;
  326. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  327. exit;
  328. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  329. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  330. $student = optional_param('student', -1, PARAM_INT);
  331. $grade = optional_param('grade', 0, PARAM_FLOAT);
  332. // 1: Recuperar a nota atual:
  333. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  334. // 2: Atualizar a tabela:
  335. $update_entry = new stdClass();
  336. $update_entry->id = $actual->id;
  337. $update_entry->previous_grade = $actual->grade;
  338. $update_entry->grade = $grade;
  339. // Update the iassign_submission
  340. $DB->update_record("iassign_submission", $update_entry);
  341. }
  342. /// This method runs activities auto evaluation in teacher area
  343. function auto_evaluate () {
  344. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  345. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  346. exit;
  347. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  348. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  349. // Get list of exercises in the instance:
  350. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  351. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  352. // Get list of enrolled students:
  353. $params = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  359. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  360. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  361. print $OUTPUT->header();
  362. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  363. print '<ul style="list-style-type: none; margin: 1em;">';
  364. foreach ($exercises_list as $exercise) {
  365. $matches = [];
  366. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  367. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  368. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  369. if ($matches[0][0]) {
  370. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
  371. } else {
  372. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
  373. }
  374. } else {
  375. if ($matches[0][0]) {
  376. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>' . $exercise->name . '</li>';
  377. } else {
  378. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>(' . $exercise->id . ') - ' . $exercise->name . '</li>';
  379. }
  380. }
  381. }
  382. print '</ul>
  383. <center>
  384. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  385. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  386. <div id="evaluate_message" style="color: red"></div>
  387. <div id="evaluate_alerts"></div>
  388. <div>
  389. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  390. <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
  391. </div>
  392. </center>'; // close "
  393. print ' </div>' + "\n";
  394. print ' <script>';
  395. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  396. print ' var submissions = [';
  397. // Get list of student id have submit for each exercise:
  398. foreach ($exercises_list as $exercise) {
  399. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  400. print '
  401. {
  402. "exerciseid": "' . $exercise->id . '",
  403. "grade": ' . $exercise->grade . ',
  404. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  405. "submited": ['; // "
  406. $params = array('iassign_statementid' => $exercise->id);
  407. $submited = $DB->get_records_sql( // Get userid and his grade
  408. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  409. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  410. foreach ($submited as $ss) {
  411. print($ss->userid . ',');
  412. }
  413. print '],';
  414. print '"allgrades": [';
  415. foreach ($submited as $ss) {
  416. print( $ss->grade . ',');
  417. }
  418. print ']
  419. },'; // close "
  420. } // foreach ($exercises_list as $exercise)
  421. print " ];\n";
  422. print '
  423. var total_submissions = 0;
  424. var selected_exercises;
  425. var count_steps;
  426. var value_by_step;
  427. var stoped = false;
  428. var time_interval = 5000;
  429. var var_interval;
  430. function add_hover_th (id_th, id_li) {
  431. $("#" + id_th).hover(function() {
  432. $("#" + id_li).css("background-color", "#d9d8d8");
  433. $(this).css("background-color", "#d9d8d8");
  434. }, function() {
  435. $("#" + id_li).css("background-color", "");
  436. $(this).css("background-color", "");
  437. });
  438. }
  439. function start_evaluation () {
  440. stoped = false;
  441. $("#progress_bar").css("display", "none");
  442. $("#evaluate_message").text("");
  443. $("#evaluate_alerts").text("");
  444. $(".added-col").remove();
  445. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  446. selected_exercises = [];
  447. var c = 0;
  448. for (var i = 0; i < exercises.length; i++) {
  449. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  450. selected_exercises[c++] = exercises[i];
  451. }
  452. }
  453. if (selected_exercises.length == 0) {
  454. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  455. return;
  456. } else {
  457. $("input:checkbox").attr("disabled", true);
  458. for (var i = 0; i < selected_exercises.length; i++) {
  459. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  460. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  461. $("#table-results tbody tr").each(function(e) {
  462. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  463. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  464. });
  465. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  466. }
  467. $("#button_start").prop("disabled", true);
  468. $("#button_stop").prop("disabled", false);
  469. $("#progress_bar").css("display", "block");
  470. }
  471. total_submissions = selected_exercises.length * students.length;
  472. count_steps = 0;
  473. value_by_step = 100/total_submissions;
  474. actual_exercise = 0;
  475. actual_student = 0;
  476. actual_submission = 0;
  477. get_original_propositions();
  478. var_interval = setInterval(verifyBreak, time_interval);
  479. } // function start_evaluation()
  480. var actual_exercise;
  481. var actual_student;
  482. var actual_submission;
  483. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  484. function run_individual_evaluation () {
  485. if (stoped) return;
  486. // Verify if student really sent his answer
  487. var found = false;
  488. for (var j = 0; j < submissions.length; j++) {
  489. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  490. for (var k = 0; k < submissions[j].submited.length; k++) {
  491. if (students[actual_student] == submissions[j].submited[k]) {
  492. found = true;
  493. break;
  494. }
  495. }
  496. break;
  497. }
  498. }
  499. if (found == false) {
  500. postResultAutoEval();
  501. } else {
  502. // If it was sent, search it...
  503. var final_url = "";
  504. var student_answer = "' . $CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=" . $this->cm->id . '" + "&iassign_student=" + students[actual_student] + "&iassign_exercise=" + selected_exercises[actual_exercise];
  505. for (var j = 0; j < submissions.length; j++) {
  506. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  507. final_url = submissions[j].ilm;
  508. break;
  509. }
  510. }
  511. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  512. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  513. window.frames["ifrm"].location=final_url;
  514. }
  515. } // function run_individual_evaluation()
  516. var break_student = -1;
  517. var break_exercise = -1;
  518. function verifyBreak () {
  519. if (actual_student == break_student && actual_exercise == break_exercise) {
  520. postResultAutoEval(-6);
  521. break_student = -1;
  522. break_exercise = -1;
  523. return;
  524. } else {
  525. break_student = actual_student;
  526. break_exercise = actual_exercise;
  527. }
  528. }
  529. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  530. function getStudentAnswerURL () {
  531. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  532. }
  533. // This function is called by the iLM!!!
  534. function getAutoEvalOriginalData () {
  535. return original_propositions[actual_exercise];
  536. }
  537. function updateProgressBar () {
  538. if (stoped) return;
  539. var temp = (count_steps * value_by_step)|0;
  540. count_steps ++;
  541. temp = temp > 100 ? 100 : temp;
  542. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  543. if (temp >= 100) {
  544. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  545. $("#button_start").prop("disabled", false);
  546. $("#button_stop").prop("disabled", true);
  547. $("input:checkbox").attr("disabled", false);
  548. clearInterval(var_interval);
  549. }
  550. }
  551. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  552. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  553. function postResultAutoEval (grade = null) {
  554. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  555. if (grade == null) {
  556. $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
  557. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  558. } else {
  559. // Verify if the re-evaluation grade is the of that one registered:
  560. var actual_value = 0;
  561. var actual_student_grade = 0;
  562. for (var k = 0; k < submissions.length; k++) {
  563. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  564. actual_value = submissions[k].grade;
  565. for (var h = 0; h < submissions[k].submited.length; h++) {
  566. if (submissions[k].submited[h] == students[actual_student]) {
  567. actual_student_grade = submissions[k].allgrades[h];
  568. break;
  569. }
  570. }
  571. break;
  572. }
  573. }
  574. // @FeedbackConvention
  575. if (grade < 0) {
  576. switch (grade) {
  577. case -1:
  578. // Test-cases are empty:
  579. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
  580. var mm = actual_exercise;
  581. $("#"+id_t).find(".details-button").click(function(e) {
  582. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
  583. });
  584. break;
  585. case -2:
  586. // Test-cases were manually altered by the student (fraud!):
  587. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  588. var mm = actual_exercise;
  589. $("#"+id_t).find(".details-button").click(function(e) {
  590. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  591. });
  592. $.ajax({
  593. dataType: "html",
  594. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+selected_exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
  595. success: function(d) {}
  596. });
  597. break;
  598. case -5:
  599. // Execution failed:
  600. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
  601. var mm = actual_exercise;
  602. $("#"+id_t).find(".details-button").click(function(e) {
  603. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
  604. });
  605. break;
  606. case -6: // iLM not answering was detected in "verifyBreak()"
  607. // The iLM are not answering:
  608. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-clock-o fa-6" aria-hidden="true" style="color: orange; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_title_time', 'iassign').'"></i></i>\');
  609. $("#"+id_t).find(".details-button").click(function(e) {
  610. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  611. });
  612. break;
  613. }
  614. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  615. } else {
  616. console.log((grade), (actual_student_grade));
  617. if ((grade) == (actual_student_grade)) {
  618. $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
  619. } else { // Notas diferem:
  620. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
  621. var mm = actual_exercise;
  622. $("#"+id_t).find(".details-button").click(function(e) {
  623. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  624. });
  625. // Send to the endpoint the post_auto_eval_result to verify:
  626. $.ajax({
  627. dataType: "html",
  628. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=post_auto_eval_result&id=' . $this->cm->id . '&iassign_exercise=" + selected_exercises[actual_exercise] + "&student=" + students[actual_student] + "&grade=" + (grade),
  629. success: function(d) {}
  630. });
  631. }
  632. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  633. }
  634. }
  635. updateProgressBar();
  636. // Does it must continue in the same exercise or stop?
  637. if (actual_student < students.length) {
  638. actual_student ++;
  639. run_individual_evaluation();
  640. } else {
  641. actual_student = 0;
  642. // Does it go to next exercise or is it finished?
  643. if (actual_exercise < selected_exercises.length) {
  644. actual_exercise++;
  645. run_individual_evaluation();
  646. } else {
  647. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  648. }
  649. }
  650. }
  651. var original_propositions;
  652. function get_original_propositions () {
  653. original_propositions = [];
  654. var count = 0;
  655. for (var i = 0; i < exercises.length; i++) {
  656. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  657. $.ajax({
  658. dataType: "html",
  659. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  660. success: function(d) { // variable "d" has the iLM content
  661. original_propositions[count] = d; // exercise original content
  662. count ++;
  663. if (count == selected_exercises.length) {
  664. run_individual_evaluation();
  665. }
  666. }
  667. });
  668. }
  669. }
  670. }
  671. function stop_evaluation () {
  672. stoped = true;
  673. $("#button_start").prop("disabled", false);
  674. $("#button_stop").prop("disabled", true);
  675. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  676. $("input:checkbox").attr("disabled", false);
  677. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  678. clearInterval(var_interval);
  679. }
  680. var exercises = [ '; // '
  681. foreach ($exercises_list as $exercise) {
  682. print $exercise->id . ',';
  683. }
  684. print ' ];';
  685. print ' var students = [ ';
  686. foreach ($students_list as $student) {
  687. print $student->userid . ',';
  688. }
  689. print '];';
  690. print ' var ilms = [';
  691. foreach ($exercises_list as $exercise) {
  692. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  693. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  694. }
  695. print ']';
  696. print '</script>';
  697. print '
  698. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  699. <div class="modal-dialog modal-dialog-centered" role="document">
  700. <div class="modal-content">
  701. <div class="modal-header">
  702. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  703. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  704. <span aria-hidden="true">&times;</span>
  705. </button>
  706. </div>
  707. <div class="modal-body">
  708. ...
  709. </div>
  710. <div class="modal-footer">
  711. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  712. </div>
  713. </div>
  714. </div>
  715. </div>'; //
  716. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  717. print '<table id="table-results" class="table table-hover m-t-1">
  718. <thead>
  719. <tr id="cols-exercises">
  720. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  721. </tr>
  722. </thead>
  723. <tbody>'; // "
  724. foreach ($students_list as $student) {
  725. $user = $DB->get_record('user', array('id' => $student->userid));
  726. $avatar = new user_picture($user);
  727. $avatar->courseid = $COURSE->id;
  728. $avatar->link = true;
  729. print
  730. '<tr data-student="'.$student->userid.'">
  731. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  732. </tr>'; // "
  733. }
  734. print '</tbody>
  735. </table>'; // "
  736. print $OUTPUT->footer();
  737. } // function auto_evaluate()
  738. /// This method moves an iAssign activity
  739. function move_activity () {
  740. global $USER, $CFG, $DB, $COURSE;
  741. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  742. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  743. $update_entry_new_iassign = new stdClass();
  744. $update_entry_new_iassign->id = $iassign_id;
  745. $update_entry_new_iassign->iassignid = $iassign_destiny;
  746. // Update the iassign_statement
  747. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  748. // Update file context
  749. $c_i = context_module::instance($this->cm->id);
  750. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  751. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  752. $path_module = context_course::instance($COURSE->id);
  753. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  754. if ($context_file) {
  755. $id_context = $context_file->id;
  756. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  757. $fs = get_file_storage(); // Get reference to all files in Moodle data
  758. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  759. foreach ($files as $value) {
  760. if ($value->get_filename() != ".") {
  761. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  762. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  763. $updateentry = new stdClass();
  764. $updateentry->id = $iassign_id;
  765. $updateentry->file = $newfile->get_itemid();
  766. $DB->update_record("iassign_statement", $updateentry);
  767. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  768. break;
  769. }
  770. }
  771. }
  772. $this->return_home_course('moved_activity');
  773. exit;
  774. }
  775. /// This method duplicates an iAssign activity
  776. function duplicate_activity () {
  777. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  778. $id = $this->cm->id;
  779. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  780. $context = context_module::instance($this->cm->id);
  781. $contextuser = context_user::instance($USER->id);
  782. // Get the the iAssign acitivity to be duplicated
  783. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  784. // Remove the current id of activity
  785. $iassign_statement->id=0;
  786. // Get the information about current author, and add this information in author_modified field
  787. $author = $DB->get_record("user", array('id' => $USER->id));
  788. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  789. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  790. // Store the activity in the table
  791. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  792. // Duplicate activity file
  793. $fs = get_file_storage(); // Get reference to all files in Moodle data
  794. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  795. foreach ($files as $value) {
  796. if ($value->get_filename() != ".") {
  797. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  798. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  799. $updateentry = new stdClass();
  800. $updateentry->id = $id_;
  801. $updateentry->file = $newfile->get_itemid();
  802. // Update the duplicated iLM iAssign with new file id
  803. $DB->update_record("iassign_statement", $updateentry);
  804. }
  805. }
  806. }
  807. // log event --------------------------------------------------------------------------------------
  808. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  809. $this->return_home_course('duplicated_activity');
  810. exit;
  811. }
  812. /// This method gets the content from the iLM and register it
  813. // It could be the "exercise template" (teacher) or an answer (student)
  814. function get_answer () {
  815. global $USER, $CFG, $DB, $OUTPUT;
  816. $id = $this->cm->id;
  817. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  818. $comment = false;
  819. if ($submission_comment)
  820. $comment = $this->write_comment_submission();
  821. // receives data of iLM using the current activity
  822. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  823. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  824. // receives data of submission of current activity
  825. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  826. // receives post and get
  827. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  828. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  829. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  830. $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)
  831. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  832. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  833. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  834. $msg = '';
  835. // Feedback
  836. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  837. $str_action = "view"; // repeat
  838. if (strtolower($iassign_ilm->name) == "igeom") {
  839. }
  840. $title = get_string('evaluate_iassign', 'iassign');
  841. print $OUTPUT->header();
  842. print $OUTPUT->box_start();
  843. // Action = { view ; repeat ; viewsubmission }
  844. // * '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")
  845. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  846. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  847. $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;
  848. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  849. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  850. print '<table width=100% >';
  851. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  852. //TODO alterar aqui???
  853. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  854. // empty_answer_post = No solution was posted.
  855. if ($comment)
  856. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  857. else
  858. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  859. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  860. } else {
  861. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  862. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  863. // Correct answer!!
  864. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  865. $this->write_solution = 1; //
  866. $status = 3;
  867. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  868. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  869. // log record
  870. $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;
  871. // Trigger module viewed event.
  872. $event = \mod_iassign\event\submission_created::create(array(
  873. 'objectid' => $this->iassign->id,
  874. 'context' => $this->context,
  875. 'other' => $info
  876. ));
  877. $event->add_record_snapshot('course', $this->course);
  878. $event->trigger();
  879. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  880. // Wrong answer...: get_answer_incorrect
  881. $status = 2;
  882. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  883. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  884. // log record
  885. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  886. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  887. // Trigger module viewed event.
  888. $event = \mod_iassign\event\submission_created::create(array(
  889. 'objectid' => $this->iassign->id,
  890. 'context' => $this->context,
  891. 'other' => $info
  892. ));
  893. $event->add_record_snapshot('course', $this->course);
  894. $event->trigger();
  895. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  896. // Presents to the learner the result of the automatic evaluate?
  897. if ($this->activity->get_activity()->show_answer == 0) { // no...
  898. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  899. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  900. print '<tr>';
  901. // log record
  902. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  903. // Trigger module viewed event.
  904. $event = \mod_iassign\event\submission_created::create(array(
  905. 'objectid' => $this->iassign->id,
  906. 'context' => $this->context,
  907. 'other' => $info
  908. ));
  909. $event->add_record_snapshot('course', $this->course);
  910. $event->trigger();
  911. } else { // yes!!!
  912. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  913. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  914. print '<tr>';
  915. print $msg;
  916. }
  917. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  918. $status = 1;
  919. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  920. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  921. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  922. print '<tr>';
  923. // log record
  924. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  925. $event = \mod_iassign\event\submission_created::create(array(
  926. 'objectid' => $this->iassign->id,
  927. 'context' => $this->context,
  928. 'other' => $info
  929. ));
  930. $event->add_record_snapshot('course', $this->course);
  931. $event->trigger();
  932. } // if ($iassign_ilm->evaluate == 1)
  933. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  934. print '</tr></table>';
  935. print $OUTPUT->box_end();
  936. // add or update evaluate
  937. if ($this->write_solution == 1) {
  938. $timenow = time();
  939. // new record
  940. if (!$iassign_submission) {
  941. $newentry = new stdClass();
  942. $newentry->userid = $this->userid_iassign;
  943. // $newentry->userid = $USER->id;
  944. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  945. $newentry->timecreated = $timenow;
  946. $newentry->timemodified = $timenow;
  947. $newentry->answer = $iLM_PARAM_ArchiveContent;
  948. $newentry->grade = round($grade_student, 2);
  949. $newentry->status = $status;
  950. $newentry->experiment = 1;
  951. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  952. print_error('error_insert', 'iassign');
  953. } else {
  954. // Trigger module viewed event.
  955. $event = \mod_iassign\event\submission_created::create(array(
  956. 'objectid' => $this->iassign->id,
  957. 'context' => $this->context
  958. ));
  959. $event->add_record_snapshot('course', $this->course);
  960. $event->trigger();
  961. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  962. }
  963. } elseif ($iassign_submission->status != 3) {
  964. $newentry = new stdClass();
  965. $newentry->id = $iassign_submission->id;
  966. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  967. $newentry->userid = $iassign_submission->userid;
  968. $newentry->timecreated = $iassign_submission->timecreated;
  969. $newentry->timemodified = $timenow;
  970. $newentry->answer = $iLM_PARAM_ArchiveContent;
  971. $newentry->grade = round($grade_student, 2);
  972. $newentry->status = $status;
  973. $newentry->experiment = $iassign_submission->experiment + 1;
  974. if (!$DB->update_record("iassign_submission", $newentry)) {
  975. print_error('error_update', 'iassign');
  976. //D depurar...
  977. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  978. //D $fp = fopen("teste1.txt","w");
  979. //D fwrite($fp,$stringAux);
  980. } else {
  981. // Trigger module viewed event.
  982. $event = \mod_iassign\event\submission_updated::create(array(
  983. 'objectid' => $this->iassign->id,
  984. 'context' => $this->context
  985. ));
  986. $event->add_record_snapshot('course', $this->course);
  987. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  988. }
  989. } else {
  990. if ($return_get_answer == 1) {
  991. $newentry = new stdClass();
  992. $newentry->id = $iassign_submission->id;
  993. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  994. $newentry->userid = $iassign_submission->userid;
  995. $newentry->timecreated = $iassign_submission->timecreated;
  996. $newentry->timemodified = $timenow;
  997. $newentry->answer = $iLM_PARAM_ArchiveContent;
  998. $newentry->grade = round($grade_student, 2);
  999. $newentry->status = $status;
  1000. $newentry->experiment = $iassign_submission->experiment + 1;
  1001. if (!$DB->update_record("iassign_submission", $newentry))
  1002. print_error('error_update', 'iassign');
  1003. else {
  1004. $event = \mod_iassign\event\submission_updated::create(array(
  1005. 'objectid' => $this->iassign->id,
  1006. 'context' => $this->context
  1007. ));
  1008. $event->add_record_snapshot('course', $this->course);
  1009. $event->trigger();
  1010. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1011. print $OUTPUT->box_start();
  1012. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1013. print $OUTPUT->box_end();
  1014. }
  1015. } elseif ($return_get_answer == 2) {
  1016. print $OUTPUT->box_start();
  1017. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1018. print $OUTPUT->box_end();
  1019. } else {
  1020. print $OUTPUT->box_start();
  1021. print "
  1022. <script type='text/javascript'>
  1023. //<![CDATA[
  1024. function overwrite () {
  1025. document.formEnvio.return_get_answer.value = 1;
  1026. document.formEnvio.submit();
  1027. }
  1028. function nooverwrite () {
  1029. document.formEnvio.return_get_answer.value = 2;
  1030. document.formEnvio.submit();
  1031. }
  1032. //]]>
  1033. </script>";
  1034. $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;
  1035. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1036. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1037. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1038. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1039. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1040. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1041. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1042. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1043. <input type='hidden' name='return_get_answer'/> ";
  1044. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1045. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1046. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1047. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1048. print " </form>";
  1049. print $OUTPUT->box_end();
  1050. }
  1051. }
  1052. } // if ($this->write_solution == 1)
  1053. print $OUTPUT->footer();
  1054. die();
  1055. } // function get_answer()
  1056. /// Export in file the answer of student.
  1057. function export_file_answer () {
  1058. global $DB;
  1059. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1060. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1061. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1062. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1063. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1064. $extensions = explode(",", $iassign_ilm->extension);
  1065. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1066. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1067. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1068. header("Pragma: public");
  1069. header("Expires: 0");
  1070. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1071. header("Cache-Control: private", false);
  1072. header("Content-Type: document/unknown");
  1073. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1074. set_time_limit(0);
  1075. print($iassign_submission->answer);
  1076. exit;
  1077. } // function export_file_answer()
  1078. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1079. // @calledby $this->export_package_answer()
  1080. //TODO Precisa terminar! //TODO_HTML
  1081. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1082. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1083. <head>
  1084. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1085. $str_html .= " </head>
  1086. <body>\n";
  1087. $tam = sizeof($array_iassign_name);
  1088. for ($ii=0; $ii<$tam; $ii++) {
  1089. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1090. }
  1091. $str_html .= "
  1092. </body>\n</html>";
  1093. return $str_html;
  1094. }
  1095. /// Export an package (zip) with all answer of students
  1096. // @calledby $this->action()
  1097. function export_package_answer () {
  1098. global $DB, $CFG, $OUTPUT;
  1099. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1100. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1101. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1102. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1103. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1104. $userid = optional_param('userid', NULL, PARAM_INT);
  1105. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1106. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1107. //TODO_HTML echo "username=$username<br/>"; exit;
  1108. $current_date = date('Y_m_d_H');
  1109. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1110. // If temporary directory under Moodle data does not exists => create it
  1111. if (!is_dir($diretorio)) {
  1112. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1113. // created directory with permissions to be seen by everyone
  1114. }
  1115. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1116. if (!is_writable($diretorio)) { // send a highlighted message!
  1117. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1118. exit; // just in case
  1119. }
  1120. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1121. $zip = new zip_archive(); // create ZIP
  1122. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1123. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1124. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1125. $vet_student_filename = array();
  1126. $vet_student_content = array();
  1127. foreach ($iassign_statements as $iassign_statement) {
  1128. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1129. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1130. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1131. $extensions = explode(",", $iassign_ilm->extension);
  1132. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1133. if ($iassign_submission) {
  1134. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1135. $student_content = $iassign_submission->answer;
  1136. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1137. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1138. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1139. if ($resp) {
  1140. $vet_student_filename[] = $student_filename;
  1141. $vet_student_content[] = $student_content;
  1142. }
  1143. else { // send a highlighted message!
  1144. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1145. exit; // just in case
  1146. }
  1147. }
  1148. }
  1149. $zip->close(); // close the ZIP file
  1150. if (count($vet_student_filename)>0) {
  1151. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1152. $result_tf = $vet_result[0];
  1153. $filenameZip = $vet_result[1]->filename;
  1154. }
  1155. iassign_utils::download_file($zip_filename); // download the ZIP file
  1156. exit;
  1157. } // function export_package_answer()
  1158. /// Editing status of interactive activities
  1159. function edit_status () {
  1160. global $USER, $DB, $OUTPUT;
  1161. $newentry = new stdClass();
  1162. $newentry->id = $this->iassign_submission_current;
  1163. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1164. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1165. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1166. $newentry->status = $iassign_submission->status;
  1167. $newentry->teacher = $USER->id;
  1168. if (!$DB->update_record('iassign_submission', $newentry))
  1169. print_error('error_update', 'iassign');
  1170. else {
  1171. // Trigger module viewed event.
  1172. $event = \mod_iassign\event\submission_updated::create(array(
  1173. 'objectid' => $this->iassign->id,
  1174. 'context' => $this->context
  1175. ));
  1176. $event->add_record_snapshot('course', $this->course);
  1177. $event->trigger();
  1178. $this->action = 'viewsubmission';
  1179. $this->view_iassign_current();
  1180. } // if (!$DB->update_record('iassign_submission', $newentry))
  1181. } // function edit_status()
  1182. /// Editing grade of interactive activities
  1183. function edit_grade () {
  1184. global $USER, $DB, $OUTPUT;
  1185. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1186. if ($newgrade && $newgrade >= 0) {
  1187. $newentry = new stdClass();
  1188. $newentry->id = $this->iassign_submission_current;
  1189. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1190. $newentry->teacher = $USER->id;
  1191. if (!$DB->update_record('iassign_submission', $newentry))
  1192. print_error('error_update', 'iassign');
  1193. else {
  1194. // Trigger module viewed event.
  1195. $event = \mod_iassign\event\submission_updated::create(array(
  1196. 'objectid' => $this->iassign->id,
  1197. 'context' => $this->context
  1198. ));
  1199. $event->add_record_snapshot('course', $this->course);
  1200. $event->trigger();
  1201. }
  1202. } // if ($newgrade >= 0)
  1203. $this->action = 'viewsubmission';
  1204. $this->view_iassign_current();
  1205. }
  1206. /// Add or Edit interactive activities
  1207. // @calledby $this->action()
  1208. function add_edit_iassign () {
  1209. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1210. require_once('iassign_form.php');
  1211. $id = $this->cm->id;
  1212. $iassignid = $this->iassign->id;
  1213. $param = new stdClass();
  1214. $param->action = $this->action; // oculto
  1215. $param->id = $id; // oculto
  1216. $COURSE->cm = $id;
  1217. $COURSE->iassignid = $iassignid;
  1218. $COURSE->iassign_file_id = NULL;
  1219. $context = context_module::instance($this->cm->id);
  1220. $contextuser = context_user::instance($USER->id);
  1221. $component = 'mod_iassign';
  1222. $filearea = 'exercise';
  1223. if (!empty($this->iassign_current))
  1224. $COURSE->iassign_id = $this->iassign_current;
  1225. else
  1226. $COURSE->iassign_id = 0;
  1227. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1228. if ($this->action == 'add') {
  1229. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1230. $params = array('iassignid' => $iassignid);
  1231. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1232. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1233. $total_of_activities = count($iassign_statement);
  1234. $param->iassignid = $iassignid;
  1235. $param->name = "";
  1236. $param->oldname = "";
  1237. $param->type_iassign = 3;
  1238. $param->proposition = "";
  1239. $author = $DB->get_record("user", array("id" => $USER->id));
  1240. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1241. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1242. $param->author = $param->author_name;
  1243. $param->author_modified = $param->author_modified_name;
  1244. $COURSE->iassign_list = array();
  1245. $param->iassign_list = array();
  1246. if ($iassign_statement) {
  1247. foreach ($iassign_statement as $iassign) {
  1248. $iassignid = $iassign->id;
  1249. $param->iassign_list[$iassignid] = 0;
  1250. $COURSE->iassign_list[$iassignid] = new stdClass();
  1251. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1252. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1253. $COURSE->iassign_list[$iassignid]->enable = 1;
  1254. } // foreach ($iassign_statement as $iassign)
  1255. }
  1256. $param->iassign_ilmid = 0;
  1257. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1258. $param->file = 0;
  1259. $param->fileold = 0;
  1260. $param->filename = "";
  1261. $param->grade = $iassign_data->grade;
  1262. $param->timemodified = time();
  1263. $param->timecreated = time();
  1264. $param->timeavailable = $iassign_data->timeavailable;
  1265. $param->timedue = $iassign_data->timedue;
  1266. $param->preventlate = $iassign_data->preventlate;
  1267. $param->test = $iassign_data->test;
  1268. $param->special_param1 = 0;
  1269. $param->visible = 1;
  1270. $param->max_experiment = $iassign_data->max_experiment;
  1271. $param->dependency = 0;
  1272. $param->automatic_evaluate = 1;
  1273. $param->show_answer = 1;
  1274. } // if ($this->action == 'add')
  1275. elseif ($this->action == 'edit') {
  1276. $COURSE->iassign_list = array();
  1277. $this_activity = $this->activity->get_activity();
  1278. if ($this_activity != null) {
  1279. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1280. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1281. $param->iassign_id = $iassign_statement_current->id; // oculto
  1282. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1283. $param->name = $iassign_statement_current->name;
  1284. $param->oldname = $iassign_statement_current->name;
  1285. $param->type_iassign = $iassign_statement_current->type_iassign;
  1286. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1287. //2019 $param->proposition = $iassign_statement_current->proposition;
  1288. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1289. $param->author_name = $iassign_statement_current->author_name; // oculto
  1290. $param->author = $iassign_statement_current->author_name;
  1291. $author = $DB->get_record("user", array('id' => $USER->id));
  1292. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1293. $param->author_modified = $param->author_modified_name;
  1294. $dependency = explode(';', $iassign_statement_current->dependency);
  1295. $param->iassign_list = array();
  1296. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1297. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1298. $array_dependency = array();
  1299. $subdependency = "";
  1300. $sub_subdependency = "";
  1301. // dependent on this exercise
  1302. if ($iassign_statement_dependency) {
  1303. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1304. // to whom this exercise depends
  1305. foreach ($inter as $tmp)
  1306. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1307. $list_dependency = $subdependency . $sub_subdependency;
  1308. $array_dependency = explode(";", $list_dependency);
  1309. }
  1310. // Get all activity with the same iLM - iassignid
  1311. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  1312. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1313. $total_of_activities = count($all_others_iassign_statement) + 1;
  1314. $inter = array();
  1315. if ($all_others_iassign_statement) {
  1316. foreach ($all_others_iassign_statement as $iassign)
  1317. if (in_array($iassign->id, $dependency))
  1318. $inter[] = $iassign->id;
  1319. }
  1320. if ($all_others_iassign_statement) {
  1321. foreach ($all_others_iassign_statement as $iassign) {
  1322. $iassignid = $iassign->id;
  1323. $COURSE->iassign_list[$iassignid] = new stdClass();
  1324. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1325. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1326. if (in_array($iassignid, $dependency))
  1327. $param->iassign_list[$iassignid] = 1;
  1328. else
  1329. $param->iassign_list[$iassignid] = 0;
  1330. if (in_array($iassignid, $array_dependency))
  1331. $COURSE->iassign_list[$iassignid]->enable = 0;
  1332. else
  1333. $COURSE->iassign_list[$iassignid]->enable = 1;
  1334. } // foreach ($all_others_iassign_statement as $iassign)
  1335. }
  1336. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1337. $param->fileold = 0;
  1338. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1339. $param->filename = '';
  1340. $param->grade = $iassign_statement_current->grade;
  1341. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1342. $param->timeavailable = $iassign_statement_current->timeavailable;
  1343. $param->timedue = $iassign_statement_current->timedue;
  1344. $param->preventlate = $iassign_statement_current->preventlate;
  1345. $param->test = $iassign_statement_current->test;
  1346. $param->special_param1 = $iassign_statement_current->special_param1;
  1347. $param->position = $iassign_statement_current->position; // oculto
  1348. $param->visible = $iassign_statement_current->visible;
  1349. $param->max_experiment = $iassign_statement_current->max_experiment;
  1350. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1351. $param->show_answer = $iassign_statement_current->show_answer;
  1352. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1353. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1354. if ($files) {
  1355. foreach ($files as $file) {
  1356. if ($file->get_filename() != '.') {
  1357. $param->filename = $file->get_filename();
  1358. $param->file = $file->get_id();
  1359. $param->fileold = $file->get_id();
  1360. $COURSE->iassign_file_id = $file->get_id();
  1361. }
  1362. }
  1363. }
  1364. //TODO //MOOC2014 -- inicio
  1365. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1366. //D if ($iassign_ilm_configs) {
  1367. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1368. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1369. //D } //MOOC2014 -- fim
  1370. } // if ($this_activity != null)
  1371. } // elseif ($this->action == 'edit')
  1372. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1373. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1374. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1375. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1376. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1377. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1378. $param->position = $total_of_activities;
  1379. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1380. $mform->set_data($param);
  1381. if ($mform->is_cancelled()) {
  1382. $this->return_home_course('iassign_cancel');
  1383. exit;
  1384. }
  1385. else { // if ($mform->is_cancelled())
  1386. $result = $mform->get_data();
  1387. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1388. if ($result) {
  1389. $result->context = $context;
  1390. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1391. $result->grade = 0;
  1392. if ($result->type_iassign == 1) {
  1393. $result->automatic_evaluate = 0;
  1394. $result->show_answer = 0;
  1395. }
  1396. elseif ($result->automatic_evaluate == 0)
  1397. $result->show_answer = 0;
  1398. // $_POST['iassign_list']
  1399. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1400. if ($result->iassign_list) {
  1401. foreach ($result->iassign_list as $key => $value)
  1402. $result->dependency .= $key . ';';
  1403. }
  1404. else
  1405. $result->dependency = 0;
  1406. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1407. //TODO Then get it directly from the form data $_POST!
  1408. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1409. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1410. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1411. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1412. if ($this->action == 'add') {
  1413. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1414. if ($iassign_statement_name) {
  1415. $this->return_home_course('error_iassign_name');
  1416. die();
  1417. }
  1418. // Really insert the new iActivity in table '*_iassign_statement'
  1419. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1420. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1421. // Trigger module viewed event.
  1422. $event = \mod_iassign\event\iassign_created::create(array(
  1423. 'objectid' => $iassignid,
  1424. 'context' => $context
  1425. ));
  1426. $event->add_record_snapshot('course', $this->course);
  1427. $event->trigger();
  1428. $this->return_home_course('iassign_add');
  1429. } // if ($this->action == 'add')
  1430. elseif ($this->action == 'edit') {
  1431. $iassignid = $this->activity->update_iassign($result);
  1432. $this->activity->update_calendar($iassignid, $result->oldname);
  1433. // Trigger module viewed event.
  1434. $event = \mod_iassign\event\iassign_updated::create(array(
  1435. 'objectid' => $iassignid,
  1436. 'context' => $context
  1437. ));
  1438. $event->add_record_snapshot('course', $this->course);
  1439. $event->trigger();
  1440. $this->return_home_course('iassign_update');
  1441. } // elseif ($this->action == 'edit')
  1442. die();
  1443. } // if ($result)
  1444. } // else if ($mform->is_cancelled())
  1445. print $OUTPUT->header();
  1446. $mform->display();
  1447. print $OUTPUT->footer();
  1448. die();
  1449. } // function add_edit_iassign()
  1450. /// Search for dependencies
  1451. function search_dependency ($search_iassing_id, $iassign_statement) {
  1452. global $DB, $OUTPUT;
  1453. $dependency = "";
  1454. if ($iassign_statement)
  1455. foreach ($iassign_statement as $iassign) {
  1456. $inter_dependency = explode(';', $iassign->dependency);
  1457. if (in_array($search_iassing_id, $inter_dependency)) {
  1458. $dependency .= $iassign->id . ";";
  1459. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1460. } // if (in_array($search_iassing_id, $inter_dependency))
  1461. } // foreach ($iassign_statement as $iassign)
  1462. return $dependency;
  1463. }
  1464. /// Search for "sub"dependency
  1465. function search_sub_dependency ($search_iassing_id) {
  1466. global $DB, $OUTPUT;
  1467. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1468. $dependency = "";
  1469. if ($iassign_statement) {
  1470. $inter_dependency = explode(';', $iassign_statement->dependency);
  1471. foreach ($inter_dependency as $tmp) {
  1472. if ($tmp != 0)
  1473. $dependency .= $tmp . ";";
  1474. $dependency .= $this->search_sub_dependency($tmp);
  1475. } // foreach ($inter_dependency as $tmp)
  1476. } // if ($iassign_statement)
  1477. return $dependency;
  1478. }
  1479. // Warning message
  1480. static function warning_message_iassign ($strcode) {
  1481. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1482. }
  1483. /// Update grade of iAssign
  1484. // Called always any iAssign activity is created
  1485. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1486. static function update_grade_iassign ($iassignid) {
  1487. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1488. require_once($CFG->libdir . '/gradelib.php');
  1489. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1490. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1491. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1492. // Each iAssign item is associated with one item on the "gradebook"
  1493. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1494. //$sum_grade = 0;
  1495. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1496. //foreach($grade as $tmp) {
  1497. // $sum_grade += $tmp->grade;
  1498. // }
  1499. //1 Solution 1
  1500. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1501. //1 $sum_grade = 0; //1
  1502. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1503. //2 Solution 2
  1504. $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
  1505. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1506. if (key($array_sum_grade))
  1507. $sum_grade = key($array_sum_grade); //2
  1508. else
  1509. $sum_grade = 0; //2
  1510. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1511. $grades = NULL;
  1512. $params = array('itemname' => $grade_iassign->name);
  1513. $params['iteminstance'] = $iassignid;
  1514. $params['gradetype'] = GRADE_TYPE_VALUE;
  1515. //2016 if ($sum_grade != 0) {
  1516. $params['grademax'] = $sum_grade;
  1517. $params['rawgrademax'] = $sum_grade;
  1518. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1519. $params['grademin'] = 0;
  1520. // @calls /lib/gradelib.php: call to grade_item->insert()
  1521. //TODO: is there any error here in Moodle version 3.0?
  1522. //TODO: Incorrect property 'grademax' found when inserting grade object
  1523. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1524. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1525. }
  1526. /// Update grade of student
  1527. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1528. global $CFG, $DB, $OUTPUT;
  1529. require_once($CFG->libdir . '/gradelib.php');
  1530. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1531. // Review all the student submission for this iAssign activity
  1532. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1533. $total_grade = 0;
  1534. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1535. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1536. if ($iassign_submission)
  1537. $total_grade += $iassign_submission->grade;
  1538. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1539. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1540. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1541. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1542. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1543. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1544. $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
  1545. if (key($array_sum_grade))
  1546. $sum_grade = key($array_sum_grade); //2
  1547. else
  1548. $sum_grade = 0; //2
  1549. $grades['userid'] = $userid;
  1550. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1551. $params = array('itemname' => $grade_iassign->name);
  1552. $params['iteminstance'] = $iassignid;
  1553. $params['gradetype'] = GRADE_TYPE_VALUE;
  1554. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1555. $params['grademax'] = $sum_grade;
  1556. $params['rawgrademax'] = $sum_grade;
  1557. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1558. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1559. }
  1560. /// Display caption of icons
  1561. function view_legend_icons () {
  1562. global $USER, $CFG, $DB, $OUTPUT;
  1563. $id = $this->cm->id;
  1564. if ($this->action == 'print')
  1565. print '<table border=1 width=100%><tr>';
  1566. else
  1567. print '<table width=100%><tr>';
  1568. print '<td >';
  1569. if ($this->action != 'print')
  1570. print $OUTPUT->help_icon('legend', 'iassign');
  1571. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1572. // $imagetext = '');
  1573. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1574. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1575. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1576. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1577. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1578. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1579. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1580. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1581. print '</td>' . "\n";
  1582. if ($this->action != 'print') {
  1583. $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>";
  1584. $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>";
  1585. $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>";
  1586. $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>";
  1587. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1588. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1589. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1590. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1591. } // if ($this->action != 'print')
  1592. print '</tr></table>' . "\n";
  1593. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1594. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1595. $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>";
  1596. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1597. print '</tr></table>' . "\n";
  1598. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1599. else
  1600. print '</td></tr></table>' . "\n";
  1601. } // function view_legend_icons()
  1602. /// Display activity current
  1603. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1604. function view_iassign_current () {
  1605. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1606. $id = $this->cm->id;
  1607. $iassignid = $this->iassign->id;
  1608. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1609. $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
  1610. // 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 ...
  1611. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1612. if (!$iassign_statement_activity_item) {
  1613. print $OUTPUT->header();
  1614. \core\notification::error(get_string('activity_not_found', 'iassign'));
  1615. print $OUTPUT->footer();
  1616. exit;
  1617. }
  1618. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1619. $ilm_name = '';
  1620. if ($ilm->ilm)
  1621. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1622. // 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
  1623. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1624. // log record
  1625. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1626. //Trigger module viewed event.
  1627. $event = \mod_iassign\event\submission_viewed::create(array(
  1628. 'objectid' => $iassign->id,
  1629. 'context' => $this->context,
  1630. 'other' => $info
  1631. ));
  1632. $event->add_record_snapshot('course', $this->course);
  1633. $event->trigger();
  1634. // Search of iLM data used in the current activity
  1635. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1636. // Add actual activity to navbar:
  1637. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1638. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1639. print $OUTPUT->header();
  1640. if ($this->action == 'viewsubmission') {
  1641. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1642. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1643. else
  1644. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1645. } else {
  1646. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1647. }
  1648. if ($iassign_submission)
  1649. $this->update_comment($iassign_submission->id);
  1650. $file = $iassign_statement_activity_item->file;
  1651. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1652. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1653. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1654. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1655. $this->bottonPost = 0; // hide submit button
  1656. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1657. $this->view_iassign = false; // disable visualization of activity
  1658. $repeat = "";
  1659. $last_iassign = "";
  1660. $student_answer = "";
  1661. $comment = "";
  1662. // *** Teacher access (view learner's submission)
  1663. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1664. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1665. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1666. // ---> access teacher for test
  1667. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1668. $this->bottonPost = 1;
  1669. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1670. $this->activity->view_dates();
  1671. $USER->iassignEdit = $this->bottonPost;
  1672. $this->activity->show_info_iassign();
  1673. if ($iassign_submission) {
  1674. //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;
  1675. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1676. } else {
  1677. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1678. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1679. }
  1680. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1681. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1682. // Prepare tags to present the iLM
  1683. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1684. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1685. // *** (end) Teacher access (view the activity)
  1686. // *** Teacher access (view learner's submission to the activity)
  1687. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1688. // It is teacher or 'nonediting teacher' that can evaluate
  1689. // ----> area teacher evaluate
  1690. $row = optional_param('row', 0, PARAM_INT);
  1691. $column = optional_param('column', 0, PARAM_INT);
  1692. $link_next = iassign_icons::insert('right_disable');
  1693. $link_previous = iassign_icons::insert('left_disable');
  1694. $link_up = iassign_icons::insert('up_disable');
  1695. $link_down = iassign_icons::insert('down_disable');
  1696. // next_activity
  1697. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1698. $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);
  1699. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1700. }
  1701. // previous_activity
  1702. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1703. $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);
  1704. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1705. }
  1706. // previous_student
  1707. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1708. $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);
  1709. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1710. }
  1711. // next_student
  1712. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1713. $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);
  1714. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1715. }
  1716. if ($iassign_submission) {
  1717. $student_answer = $iassign_submission->answer;
  1718. }
  1719. $last_iassign = get_string('last_iassign', 'iassign');
  1720. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1721. // Messages related to due date (and user role)
  1722. $this->activity->view_dates();
  1723. print $OUTPUT->box_start();
  1724. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1725. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1726. print $OUTPUT->user_picture($user_data);
  1727. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1728. print '</td>' . "\n";
  1729. print '<td width=20% align=right>' . "\n";
  1730. print '<table width=50 cellpadding="0">';
  1731. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1732. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1733. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1734. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1735. print '</table>' . "\n";
  1736. print '</td></tr></table>' . "\n";
  1737. print $OUTPUT->box_end();
  1738. print $OUTPUT->box_start();
  1739. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1740. print '<td width=60% valign="top">' . "\n";
  1741. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1742. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1743. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1744. $resp = get_string('yes');
  1745. else
  1746. $resp = get_string('no');
  1747. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1748. if ($iassign_statement_activity_item->show_answer == 1)
  1749. $resp = get_string('yes');
  1750. else
  1751. $resp = get_string('no');
  1752. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1753. print '</td>';
  1754. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1755. print '<td width=40% valign="top" align="left">';
  1756. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1757. // check status of solution sent by the student
  1758. if ($iassign_submission) {
  1759. switch ($iassign_submission->status) {
  1760. case 3 :
  1761. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1762. break;
  1763. case 2 :
  1764. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1765. break;
  1766. case 1 :
  1767. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1768. break;
  1769. default :
  1770. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1771. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1772. } // switch ($iassign_submission->status)
  1773. }
  1774. else { // if ($iassign_submission)
  1775. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1776. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1777. }
  1778. // update_status
  1779. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1780. $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);
  1781. print " <script type='text/javascript'>
  1782. //<![CDATA[
  1783. function overwriteStatus (newstatus) {
  1784. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1785. document.formEditStatus.return_status.value=newstatus;
  1786. document.formEditStatus.submit();
  1787. }
  1788. else
  1789. document.formEditStatus.return_status.value=-1;
  1790. }
  1791. //]]>
  1792. </script>";
  1793. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1794. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1795. 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";
  1796. print " <input type='hidden' name='return_status'>\n";
  1797. print "</form>\n";
  1798. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1799. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1800. $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);
  1801. print "
  1802. <script type='text/javascript'>
  1803. //<![CDATA[
  1804. function overwriteGrade (newgrade,maxgrade) {
  1805. if (newgrade<0 || newgrade>maxgrade) {
  1806. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1807. document.formEditGrade.return_grade.value=-1;
  1808. document.formEditGrade.submit();
  1809. }
  1810. else {
  1811. document.formEditGrade.return_grade.value=newgrade;
  1812. document.formEditGrade.submit();
  1813. }
  1814. }
  1815. //]]>
  1816. </script>";
  1817. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1818. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1819. print " <input type='text' name='grade' size='6'>";
  1820. print " <input type='hidden' name='return_grade'> ";
  1821. 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";
  1822. print "</form>";
  1823. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1824. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1825. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1826. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1827. if ($teacher)
  1828. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1829. } // if ($iassign_submission->experiment > 0)
  1830. print '</td>';
  1831. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1832. print '</tr></table>';
  1833. print $OUTPUT->box_end();
  1834. $USER->iassignEdit = $this->bottonPost;
  1835. if ($iassign_submission && $allow_resubmission) {
  1836. // Put the iLM to
  1837. print $OUTPUT->box_start();
  1838. print '<p><strong>' . $last_iassign . '</strong></p>';
  1839. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1840. $enderecoPOST = "";
  1841. // Prepare tags to present the iLM
  1842. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1843. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1844. print $OUTPUT->box_end();
  1845. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1846. // ATTENTION: exception used by iGeom (exercise with "script")
  1847. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1848. if (substr($ilm_name, 0, 5)=="igeom") {
  1849. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1850. $loadTeacherActivity = true;
  1851. }
  1852. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1853. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1854. // Prepare tags to present the iLM
  1855. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1856. }
  1857. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1858. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1859. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1860. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1861. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1862. // *** (end) Teacher access (view learner's submission to the activity)
  1863. // *** Student access (view the activity)
  1864. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1865. // It could be the learner (he could send or resend the activity)
  1866. // ---> access student
  1867. $time_now = time();
  1868. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1869. // activity of type example - not submit button for submission
  1870. $this->view_iassign = true;
  1871. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1872. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1873. // activity of type test - iLM automatic evaluator - submit button for submission
  1874. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1875. $this->bottonPost = 1;
  1876. $this->view_iassign = true;
  1877. } else
  1878. $this->view_iassign = false;
  1879. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1880. // activity of type exercise (learner can send his answer, if yet open...)
  1881. $this->view_iassign = true;
  1882. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1883. $this->view_iassign = false;
  1884. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1885. $this->bottonPost = 1; // allow the submit button
  1886. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1887. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1888. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1889. if (!$iassign_submission) {
  1890. $str_iassign_submission_id = '';
  1891. $str_iassign_submission_answer = '';
  1892. }
  1893. else {
  1894. $str_iassign_submission_id = $iassign_submission->id;
  1895. $str_iassign_submission_answer = $iassign_submission->answer;
  1896. }
  1897. if ($this->action != 'repeat') {
  1898. $repeat = "<a href='view.php?action=repeat&id="
  1899. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1900. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1901. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1902. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1903. }
  1904. $this->bottonPost = 1;
  1905. $this->write_solution = 1; // can register his submission
  1906. $student_answer = $str_iassign_submission_answer;
  1907. }
  1908. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1909. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1910. $last_iassign = get_string('last_iassign', 'iassign');
  1911. if ($iassign_submission) {
  1912. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1913. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1914. $student_answer = $iassign_submission->answer;
  1915. } else {
  1916. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1917. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1918. }
  1919. }
  1920. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1921. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1922. $this->bottonPost = 1;
  1923. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1924. } else {
  1925. $last_iassign = get_string('last_iassign', 'iassign');
  1926. if ($iassign_submission) {
  1927. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1928. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1929. $student_answer = $iassign_submission->answer;
  1930. } else {
  1931. // Symbol of "redo activity"
  1932. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1933. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1934. }
  1935. }
  1936. } // elseif ($iassign_statement_activity_item->test == 1)
  1937. elseif ($iassign_statement_activity_item->test == 0)
  1938. $this->view_iassign = false;
  1939. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1940. if ($iassign_submission)
  1941. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1942. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1943. else
  1944. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1945. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1946. $this->activity->view_dates();
  1947. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1948. print $OUTPUT->box_start();
  1949. print '<table width=100% border=0 valign="top">' . "\n";
  1950. print '<tr><td width=60% valign="top">' . "\n";
  1951. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1952. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1953. $flag_dependency = true;
  1954. if ($iassign_statement_activity_item->type_iassign == 3) {
  1955. if ($iassign_statement_activity_item->dependency == 0) {
  1956. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1957. } else {
  1958. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1959. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1960. foreach ($dependencys as $dependency) {
  1961. if ($dependency) {
  1962. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1963. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1964. if ($dependencysubmissions) {
  1965. if ($dependencysubmissions->status == 3)
  1966. $icon = iassign_icons::insert('correct');
  1967. elseif ($dependencysubmissions->status == 2) {
  1968. $icon = iassign_icons::insert('incorrect');
  1969. $flag_dependency = false;
  1970. } elseif ($dependencysubmissions->status == 1) {
  1971. $icon = iassign_icons::insert('post');
  1972. $flag_dependency = false;
  1973. } elseif ($dependencysubmissions->status == 0) {
  1974. $icon = iassign_icons::insert('not_post');
  1975. $flag_dependency = false;
  1976. }
  1977. } else {
  1978. $icon = iassign_icons::insert('not_post');
  1979. $flag_dependency = false;
  1980. } // if ($dependencysubmissions)
  1981. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1982. } // if ($dependency)
  1983. } // foreach ($dependencys as $dependency)
  1984. } // if ($iassign_statement_activity_item->dependency == 0)
  1985. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1986. if ($flag_dependency == false) {
  1987. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1988. $this->view_iassign = false;
  1989. print '</tr></table>' . "\n";
  1990. }
  1991. else {
  1992. $this->view_iassign = true;
  1993. print '</td>' . "\n";
  1994. } // if ($flag_dependency == false)
  1995. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1996. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1997. // receiver=1 - message to teacher
  1998. // receiver=2 - message to student
  1999. if ($iassign_submission) {
  2000. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2001. if ($verify_message)
  2002. $comment = iassign_icons::insert('comment_unread');
  2003. }
  2004. print '<td width=40% valign="top" align="left">';
  2005. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2006. if ($iassign_statement_activity_item->show_answer == 1) {
  2007. // check status of solution sent by the student
  2008. if ($iassign_submission) {
  2009. switch ($iassign_submission->status) {
  2010. case 3 :
  2011. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2012. break;
  2013. case 2 :
  2014. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2015. break;
  2016. case 1 :
  2017. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2018. break;
  2019. default :
  2020. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2021. $repeat = "";
  2022. $last_iassign = "";
  2023. } // switch ($iassign_submission->status)
  2024. } else {
  2025. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2026. $repeat = "";
  2027. $last_iassign = "";
  2028. }
  2029. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2030. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2031. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2032. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2033. if ($iassign_statement_activity_item->max_experiment == 0)
  2034. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2035. else {
  2036. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2037. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2038. $repeat = "";
  2039. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2040. $this->bottonPost = 0;
  2041. $this->write_solution = 0;
  2042. }
  2043. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2044. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2045. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2046. if ($teacher)
  2047. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2048. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2049. } // if ($iassign_statement_activity_item->show_answer==1)
  2050. else {
  2051. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2052. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2053. $repeat = "";
  2054. $last_iassign = "";
  2055. } elseif ($iassign_submission->status == 1) {
  2056. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2057. }
  2058. }
  2059. print '</td>';
  2060. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2061. print '</tr></table>' . "\n";
  2062. // Presents the iLM
  2063. print '<table width=100% border=0 valign="top">' . "\n";
  2064. print '<td width=80% align="left">';
  2065. 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\".
  2066. print '<td width=20% align="rigth">';
  2067. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2068. print $repeat; // symbol of "redo activity"
  2069. print '</td></tr></table>' . "\n";
  2070. //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)'
  2071. $output = '';
  2072. if (!$iassign_ilm) {
  2073. $iassign_ilm = new stdClass();
  2074. $iassign_ilm->file_jar = "";
  2075. }
  2076. $output .= $OUTPUT->box_start();
  2077. $USER->iassignEdit = $this->bottonPost;
  2078. // ---
  2079. // Presents the iLM
  2080. // Prepare tags to present the iLM
  2081. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2082. $student_answer = ""; //?
  2083. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2084. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2085. $student_answer = "";
  2086. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2087. } else {
  2088. // When student is redoing his activity
  2089. // ATTENTION: exception used by iGeom (exercise with "script")
  2090. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2091. if (substr($ilm_name, 0, 5)=="igeom") {
  2092. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2093. $loadTeacherActivity = true;
  2094. }
  2095. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2096. }
  2097. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2098. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2099. //1 $history_comment = '';
  2100. //1 if ($iassign_submission) {
  2101. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2102. //1 }
  2103. //1 if (!empty($history_comment)) {
  2104. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2105. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2106. //1 $output .= $history_comment;
  2107. //1 $output .= "</table>\n";
  2108. //1 }
  2109. //1 $output .= "</form></center>\n";
  2110. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2111. //1 }
  2112. $output .= $OUTPUT->box_end();
  2113. print $output;
  2114. } // if ($this->view_iassign)
  2115. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2116. } // if ($this->view_iassign)
  2117. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2118. else
  2119. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2120. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2121. print '<table width=100% border=0 valign="top">' . "\n";
  2122. print '<tr><td width=60% valign="top">' . "\n";
  2123. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2124. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2125. print '</tr></table>' . "\n";
  2126. $student_answer = "";
  2127. $enderecoPOST = "";
  2128. // Prepare tags to present the iLM
  2129. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2130. print $output;
  2131. }
  2132. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2133. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2134. 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
  2135. // Put a block with area to sent/answer comments
  2136. $output = '';
  2137. $history_comment = '';
  2138. $row = optional_param('row', 0, PARAM_INT);
  2139. $column = optional_param('column', 0, PARAM_INT);
  2140. if ($iassign_submission) {
  2141. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2142. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2143. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2144. }
  2145. else {
  2146. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2147. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2148. }
  2149. $output .= $OUTPUT->box_start();
  2150. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  2151. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2152. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2153. $output .= "</form></center>\n";
  2154. if (!empty($history_comment)) {
  2155. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2156. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2157. $output .= $history_comment;
  2158. $output .= "</table>";
  2159. }
  2160. $output .= $OUTPUT->box_end();
  2161. print $output;
  2162. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2163. // final block 'studant'
  2164. print $OUTPUT->footer();
  2165. die();
  2166. } // function view_iassign_current()
  2167. /// Export the data from performance report into CSV file format
  2168. function export_csv () {
  2169. global $USER, $CFG, $DB, $OUTPUT;
  2170. $str = "";
  2171. $fields = "student_id, student_name";
  2172. // Finding all iassign activities for the iassign:
  2173. $id = $this->cm->id;
  2174. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2175. $c = 1;
  2176. foreach ($iassign_list as $iassign) {
  2177. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2178. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2179. $c ++;
  2180. }
  2181. // Finding enrolled students:
  2182. $params = array('shortname' => 'student');
  2183. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2184. $context = context_course::instance($this->course->id);
  2185. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2186. $students = $DB->get_records_sql(
  2187. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2188. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2189. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2190. foreach ($students as $student) {
  2191. $str .= $student->userid . ',';
  2192. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2193. foreach ($iassign_list as $iassign) {
  2194. $str .= ',' . $iassign->id . ',';
  2195. $str .= '"' . $iassign->name . '",';
  2196. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2197. if ($student_submissions) {
  2198. $str .= $student_submissions->experiment . ',';
  2199. $str .= $student_submissions->grade . ',';
  2200. switch ($student_submissions->status) {
  2201. case 3:
  2202. $str .= '"correct",';
  2203. break;
  2204. case 2:
  2205. $str .= '"incorrect",';
  2206. break;
  2207. case 1:
  2208. $str .= '"post",';
  2209. break;
  2210. case 0:
  2211. $str .= '"not_post",';
  2212. break;
  2213. }
  2214. } else {
  2215. $str .= ',,"not_post",';
  2216. }
  2217. $str .= $iassign->iassign_ilmid . ',';
  2218. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2219. $str .= '"' . $ilm_activity->name . '"';
  2220. }
  2221. $str .= "\n";
  2222. }
  2223. $str = $fields . "\n" . $str;
  2224. header("Content-type: text/csv");
  2225. header("Content-disposition: attachment; filename=report.csv");
  2226. header("Pragma: no-cache");
  2227. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2228. header('Content-Length: ' . strlen($str));
  2229. header('Connection: close');
  2230. print $str;
  2231. flush();
  2232. } // function export_csv()
  2233. /// Display report of performance
  2234. function report () {
  2235. global $USER, $CFG, $DB, $OUTPUT;
  2236. $id = $this->cm->id;
  2237. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2238. if ($this->action != 'print') {
  2239. $title = get_string('report', 'iassign');
  2240. print $OUTPUT->header();
  2241. } // if ($this->action != 'print')
  2242. print $OUTPUT->box_start();
  2243. $this->view_legend_icons();
  2244. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2245. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2246. print $OUTPUT->box_end();
  2247. if ($this->action == 'print')
  2248. print '<table border=1 width="100%">' . "\n";
  2249. else
  2250. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2251. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2252. // $num = array();
  2253. $i = 1;
  2254. $num = array();
  2255. foreach ($iassign_list as $iassign) {
  2256. $test_exercise = "";
  2257. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2258. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2259. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2260. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2261. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2262. $num[$i] = new stdClass();
  2263. $num[$i]->name = $iassign->name;
  2264. $num[$i]->id = $i;
  2265. $num[$i]->iassignid = $iassign->id;
  2266. print ' <tr >' . "\n";
  2267. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2268. print "<td class=\"cell c0 actvity\">";
  2269. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2270. print ' </tr>' . "\n";
  2271. $i ++;
  2272. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2273. } // foreach ($iassign_list as $iassign)
  2274. print "</table>";
  2275. print "<p></p>";
  2276. if ($this->action == 'print')
  2277. print '<table border=1 width="100%">' . "\n";
  2278. else
  2279. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2280. $context = context_course::instance($this->course->id);
  2281. if ($i > 1) {
  2282. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2283. $params = array('shortname' => 'student');
  2284. $role = $DB->get_record_sql(
  2285. "SELECT s.id, s.shortname FROM {role} s " .
  2286. " WHERE s.shortname = :shortname", $params);
  2287. // $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");
  2288. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2289. $students = $DB->get_records_sql(
  2290. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2291. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2292. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2293. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2294. for ($j = 1; $j < $i; $j ++) {
  2295. $sum_iassign_correct[$j] = 0;
  2296. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2297. }
  2298. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2299. $sum_iassign = $j - 1;
  2300. print '</tr>' . "\n";
  2301. $total = 0;
  2302. $sum_student = 0;
  2303. $comment = iassign_icons::insert('comment_read');
  2304. $sum_comment = 0;
  2305. $sum_correct_iassign = array();
  2306. $sum_correct_student = array();
  2307. $USER->matrix_iassign = array();
  2308. if ($students) {
  2309. $w = 0;
  2310. foreach ($students as $tmp) {
  2311. $users_array[$w] = $tmp;
  2312. $w ++;
  2313. }
  2314. for ($x = 0; $x < $w; $x ++) {
  2315. print '<tr>' . "\n";
  2316. $sum_student ++;
  2317. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2318. print ' <td >' . $name . '</td>' . "\n";
  2319. $total_student = 0;
  2320. $tentativas = 0;
  2321. for ($j = 1; $j < $i; $j ++) {
  2322. $sum_comment = 0;
  2323. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2324. print ' <td valign="bottom" align="center">' . "\n";
  2325. if ($student_submissions) {
  2326. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2327. $tentativas = $student_submissions->experiment;
  2328. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2329. $params = array('iassign_submissionid' => $student_submissions->id);
  2330. $student_submissions_comment = $DB->get_record_sql(
  2331. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2332. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2333. if ($student_submissions_comment)
  2334. foreach ($student_submissions_comment as $tmp)
  2335. $sum_comment = $tmp;
  2336. // informations to previous activities
  2337. if ($j - 1 < 1 || $j == $i)
  2338. $iassign_previous = "-1";
  2339. else
  2340. $iassign_previous = $num[$j - 1]->iassignid;
  2341. if ($x - 1 < 0 || $x == $w)
  2342. $user_previous = "-1";
  2343. else
  2344. $user_previous = $users_array[$x - 1]->userid;
  2345. // next
  2346. if ($i - 1 > $j)
  2347. $iassign_next = $num[$j + 1]->iassignid;
  2348. else
  2349. $iassign_next = "-1";
  2350. if ($w - 1 > $x)
  2351. $user_next = $users_array[$x + 1]->userid;
  2352. else
  2353. $user_next = "-1";
  2354. $position = "&row= $x&column=$j";
  2355. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2356. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2357. $url .= $position;
  2358. // receiver=1 - message to teacher
  2359. // receiver=2 - message to student
  2360. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2361. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2362. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2363. $verify_message = $DB->get_record_sql(
  2364. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2365. "WHERE iassign_submissionid = :iassign_submissionid " .
  2366. " AND return_status= :return_status " .
  2367. " AND receiver= :receiver", $params);
  2368. if ($verify_message)
  2369. foreach ($verify_message as $tmp)
  2370. $sum_verify_message = $tmp;
  2371. if ($sum_verify_message > 0)
  2372. $comment = iassign_icons::insert('comment_unread');
  2373. else
  2374. $comment = iassign_icons::insert('comment_read');
  2375. if ($student_submissions->status == 3) {
  2376. $sum_iassign_correct[$j] ++;
  2377. $total_student ++;
  2378. $feedback = iassign_icons::insert('correct');
  2379. }
  2380. elseif ($student_submissions->status == 2) {
  2381. $feedback = iassign_icons::insert('incorrect');
  2382. }
  2383. elseif ($student_submissions->status == 1) {
  2384. $feedback = iassign_icons::insert('post');
  2385. }
  2386. elseif ($student_submissions->status == 0) {
  2387. $feedback = iassign_icons::insert('not_post');
  2388. }
  2389. if ($this->action != 'print') {
  2390. print '<table><tr>';
  2391. if ($tentativas > 0)
  2392. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2393. else
  2394. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2395. print '<td> &nbsp; </td>';
  2396. print '</tr>' . "\n";
  2397. if ($sum_comment > 0 && $sum_verify_message > 0)
  2398. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2399. else if ($sum_comment > 0)
  2400. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2401. print '</table>' . "\n";
  2402. }
  2403. if ($this->action == 'print')
  2404. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2405. } // if ($student_submissions)
  2406. else { // if ($student_submissions)
  2407. // informations to browse previous activities
  2408. if ($j - 1 < 1 || $j == $i)
  2409. $iassign_previous = "-1";
  2410. else
  2411. $iassign_previous = $num[$j - 1]->iassignid;
  2412. if ($x - 1 < 0 || $x == $w)
  2413. $user_previous = "-1";
  2414. else
  2415. $user_previous = $users_array[$x - 1]->userid;
  2416. // next
  2417. if ($i - 1 > $j)
  2418. $iassign_next = $num[$j + 1]->iassignid;
  2419. else
  2420. $iassign_next = "-1";
  2421. if ($w - 1 > $x)
  2422. $user_next = $users_array[$x + 1]->userid;
  2423. else
  2424. $user_next = "-1";
  2425. $position = "&row= $x&column=$j";
  2426. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2427. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2428. $url .= $position;
  2429. $feedback = iassign_icons::insert('not_post');
  2430. if ($this->action == 'print')
  2431. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2432. else {
  2433. print '<table><tr>';
  2434. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2435. print '<td> &nbsp; </td>';
  2436. print '</tr><tr>' . "\n";
  2437. print '<td> &nbsp;</td>';
  2438. if ($sum_comment > 0)
  2439. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2440. else
  2441. print '<td> &nbsp;</td>';
  2442. print '</tr></table>';
  2443. }
  2444. } // else if ($student_submissions)
  2445. $USER->matrix_iassign[$x][$j] = new stdClass();
  2446. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2447. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2448. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2449. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2450. if ($student_submissions)
  2451. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2452. else
  2453. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2454. print '</td>' . "\n";
  2455. } // for ($j=1; $j<$i; $j++)
  2456. $total = $total + $total_student;
  2457. $porcentagem = ($total_student / ($j - 1)) * 100;
  2458. if ($tentativas != 0 && $tentativas != null) {
  2459. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2460. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2461. }
  2462. else {
  2463. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2464. }
  2465. print '</tr>' . "\n";
  2466. $sum_correct_student[$sum_student] = new stdClass();
  2467. $sum_correct_student[$sum_student]->name = $name;
  2468. $sum_correct_student[$sum_student]->sum = $total_student;
  2469. } // for ($x = 0; $x < $w; $x ++)
  2470. for ($i = 1; $i < $j; $i ++) {
  2471. if (is_null($sum_iassign_correct[$i]))
  2472. $sum_iassign_correct[$i] = 0;
  2473. $sum_correct_iassign[$i] = new stdClass();
  2474. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2475. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2476. }
  2477. // print '</tr></table>' . "\n";
  2478. }
  2479. } // if ($i>1)
  2480. else {
  2481. print_string('no_activity', 'iassign');
  2482. }
  2483. print "</table>\n";
  2484. if ($this->action != 'print')
  2485. print $OUTPUT->footer();
  2486. die();
  2487. } // function report()
  2488. /// Display graphics of performance
  2489. function stats () {
  2490. global $USER, $CFG, $DB, $OUTPUT;
  2491. $id = $this->cm->id;
  2492. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2493. if ($this->action != 'printstats')
  2494. $title = get_string('graphic', 'iassign');
  2495. $num = array();
  2496. $sum_correct_iassign = array();
  2497. $sum_correct_student = array();
  2498. $sum_student = 0;
  2499. $i = 1;
  2500. foreach ($iassign_list as $iassign) {
  2501. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2502. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2503. $sum_iassign_correct[$i] = 0;
  2504. $num[$i] = new stdClass();
  2505. $num[$i]->name = $iassign->name;
  2506. $num[$i]->id = $i;
  2507. $num[$i]->iassignid = $iassign->id;
  2508. $i ++;
  2509. } // if ($iassign->type_iassign == 3)
  2510. } // foreach ($iassign_list as $iassign)
  2511. $sum_iassign = $i - 1;
  2512. $context = context_course::instance($this->course->id);
  2513. if ($i > 1) {
  2514. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2515. $params = array('shortname' => 'student');
  2516. $role = $DB->get_record_sql(
  2517. "SELECT s.id, s.shortname FROM {role} s " .
  2518. " WHERE s.shortname = :shortname", $params);
  2519. // $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");
  2520. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2521. $students = $DB->get_records_sql(
  2522. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2523. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2524. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2525. $total = 0;
  2526. $sum_student = 0;
  2527. $j = 0;
  2528. $sum_correct_iassign = array();
  2529. $sum_correct_student = array();
  2530. $sum_experiment = array();
  2531. if ($students) {
  2532. foreach ($students as $users) {
  2533. $sum_student ++;
  2534. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2535. // rows
  2536. $total_student = 0;
  2537. for ($j = 1; $j < $i; $j ++) {
  2538. $total_experiment = 0;
  2539. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2540. if ($student_submissions) {
  2541. if ($student_submissions->status == 3) {
  2542. $sum_iassign_correct[$j] ++;
  2543. $total_student ++;
  2544. } // if ($student_submissions->status == 3)
  2545. $total_experiment += $student_submissions->experiment;
  2546. }
  2547. $sum_experiment[$j] = $total_experiment;
  2548. } // for ($j=1; $j<$i; $j++)
  2549. $total = $total + $total_student;
  2550. $sum_correct_student[$sum_student] = new stdClass();
  2551. $sum_correct_student[$sum_student]->name = $name;
  2552. $sum_correct_student[$sum_student]->sum = $total_student;
  2553. } // foreach ($students as $users)
  2554. }
  2555. for ($i = 1; $i < $j; $i ++) {
  2556. if (is_null($sum_iassign_correct[$i]))
  2557. $sum_iassign_correct[$i] = 0;
  2558. $sum_correct_iassign[$i] = new stdClass();
  2559. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2560. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2561. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2562. } // for ($i = 1; $i < $j; $i++)
  2563. } // if ($i > 1)
  2564. if ($this->action != 'printstats') {
  2565. $title = get_string('graphic', 'iassign');
  2566. print $OUTPUT->header();
  2567. $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>";
  2568. $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>";
  2569. print '<table width=100%><tr>';
  2570. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2571. print '<td width=15% align="right">' . $link_report . '</td>';
  2572. print '</td></tr></table>' . "\n";
  2573. print "<br><br>";
  2574. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2575. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2576. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2577. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2578. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2579. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2580. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2581. print '</tr>' . "\n";
  2582. $sum_correct = 0;
  2583. if ($sum_correct_iassign) {
  2584. foreach ($sum_correct_iassign as $iassign) {
  2585. if (is_null($iassign->experiment))
  2586. $iassign->experiment = 0;
  2587. $bar = "";
  2588. $sum = $iassign->sum;
  2589. $percent = ($sum / $sum_student) * 100;
  2590. $text = number_format($percent, 1) . '%';
  2591. $sum_correct += $sum;
  2592. if ($sum > 0) {
  2593. for ($i = 1; $i < $percent * 2; $i ++)
  2594. $bar .= iassign_icons::insert('hbar_blue');
  2595. $bar .= iassign_icons::insert('hbar_blue_r');
  2596. } // if ($sum > 0)
  2597. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2598. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2599. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2600. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2601. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2602. print '</tr>' . "\n";
  2603. } // foreach ($sum_correct_iassign as $iassign)
  2604. }
  2605. print "</table>";
  2606. print "<br><br>";
  2607. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2608. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2609. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2610. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2611. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2612. print '</tr>' . "\n";
  2613. $sum_correct = 0;
  2614. foreach ($sum_correct_student as $student) {
  2615. $bar = "";
  2616. $sum = $student->sum;
  2617. $percent = ($sum / $sum_iassign) * 100;
  2618. $text = number_format($percent, 1) . '%';
  2619. $sum_correct += $sum;
  2620. if ($sum > 0) {
  2621. for ($i = 1; $i < $percent * 2; $i ++)
  2622. $bar .= iassign_icons::insert('hbar_blue');
  2623. $bar .= iassign_icons::insert('hbar_blue_r');
  2624. } // if ($sum > 0)
  2625. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2626. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2627. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2628. print '</tr>' . "\n";
  2629. } // foreach ($sum_correct_student as $student)
  2630. print "</table>\n";
  2631. print "<br><br>\n";
  2632. $var = 0;
  2633. $cv = 0;
  2634. $dv = 0;
  2635. $avg = 0;
  2636. if ($sum_correct_student) {
  2637. $avg = $sum_correct / $sum_student;
  2638. if ($avg > 0) {
  2639. foreach ($sum_correct_student as $student)
  2640. $var += pow($student->sum - $avg, 2);
  2641. $var = $var / $sum_student;
  2642. $dv = sqrt($var);
  2643. $cv = ($dv / $avg) * 100;
  2644. }
  2645. }
  2646. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2647. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2648. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2649. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2650. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2651. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2652. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2653. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2654. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2655. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2656. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2657. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2658. print "</table>\n";
  2659. print $OUTPUT->footer();
  2660. } else {
  2661. print "<STYLE TYPE='text/css'>
  2662. <!--
  2663. .boldtable {
  2664. font-family:sans-serif;
  2665. font-size:10pt;
  2666. }
  2667. -->
  2668. </STYLE>\n";
  2669. print '<table border=1 width=100%>' . "\n";
  2670. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2671. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2672. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2673. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2674. print '</tr>' . "\n";
  2675. $sum_correct = 0;
  2676. foreach ($sum_correct_iassign as $iassign) {
  2677. $bar = "";
  2678. $sum = $iassign->sum;
  2679. $percent = ($sum / $sum_student) * 100;
  2680. $text = number_format($percent, 1) . '%';
  2681. $sum_correct += $sum;
  2682. if ($sum > 0) {
  2683. for ($i = 1; $i < $percent * 2; $i ++)
  2684. $bar .= iassign_icons::insert('hbar_blue');
  2685. $bar .= iassign_icons::insert('hbar_blue_r');
  2686. } // if ($sum > 0)
  2687. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2688. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2689. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2690. print '</tr>' . "\n";
  2691. } // foreach ($sum_correct_iassign as $iassign)
  2692. print "</table>";
  2693. print "<br><br>";
  2694. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2695. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2696. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2697. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2698. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2699. print '</tr>' . "\n";
  2700. $sum_correct = 0;
  2701. foreach ($sum_correct_student as $student) {
  2702. $bar = "";
  2703. $sum = $student->sum;
  2704. $percent = ($sum / $sum_iassign) * 100;
  2705. $text = number_format($percent, 1) . '%';
  2706. $sum_correct += $sum;
  2707. if ($sum > 0) {
  2708. for ($i = 1; $i < $percent * 2; $i ++)
  2709. $bar .= iassign_icons::insert('hbar_blue');
  2710. $bar .= iassign_icons::insert('hbar_blue_r');
  2711. } // if ($sum > 0)
  2712. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2713. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2714. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2715. print '</tr>' . "\n";
  2716. } // foreach ($sum_correct_student as $student)
  2717. print "</table>\n";
  2718. print "<br/><br/>\n";
  2719. $var = 0;
  2720. $cv = 0;
  2721. $dv = 0;
  2722. $avg = 0;
  2723. if ($sum_correct_student) {
  2724. $avg = $sum_correct / $sum_student;
  2725. if ($avg > 0) {
  2726. foreach ($sum_correct_student as $student)
  2727. $var += pow($student->sum - $avg, 2);
  2728. $var = $var / $sum_student;
  2729. $dv = sqrt($var);
  2730. $cv = ($dv / $avg) * 100;
  2731. }
  2732. }
  2733. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2734. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2735. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2736. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2737. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2738. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2739. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2740. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2741. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2742. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2743. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2744. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2745. print "</table>\n";
  2746. } // if ($this->action != 'printstats')
  2747. die();
  2748. }
  2749. /// Display graphics of performance for students
  2750. function stats_students () {
  2751. global $USER, $CFG, $DB, $OUTPUT;
  2752. $id = $this->cm->id;
  2753. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2754. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2755. $title = get_string('results', 'iassign');
  2756. $sum_correct = 0;
  2757. $sum_incorrect = 0;
  2758. $sum_post = 0;
  2759. $sum_nopost = 0;
  2760. $sum_iassign = count($iassign_statement_list);
  2761. $bar_nopost = "";
  2762. $bar_correct = "";
  2763. $bar_incorrect = "";
  2764. $bar_post = "";
  2765. $text_nopost = "";
  2766. $text_correct = "";
  2767. $text_incorrect = "";
  2768. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2769. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2770. if ($iassign_submission) {
  2771. if ($iassign_submission->status == 3)
  2772. $sum_correct ++;
  2773. elseif ($iassign_submission->status == 2)
  2774. $sum_incorrect ++;
  2775. elseif ($iassign_submission->status == 1)
  2776. $sum_post ++;
  2777. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2778. $sum_nopost ++;
  2779. } // if ($iassign_submission)
  2780. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2781. if ($sum_iassign > 0) {
  2782. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2783. $text_correct = number_format($percent_correct, 1) . '%';
  2784. }
  2785. if ($sum_correct > 0) {
  2786. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2787. $bar_correct .= iassign_icons::insert('hbar_green');
  2788. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2789. } // if ($sum_correct > 0)
  2790. if ($sum_iassign > 0) {
  2791. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2792. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2793. }
  2794. if ($sum_incorrect > 0) {
  2795. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2796. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2797. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2798. } // if ($sum_incorrect > 0)
  2799. if ($sum_iassign > 0) {
  2800. $percent_post = ($sum_post / $sum_iassign) * 100;
  2801. $text_post = number_format($percent_post, 1) . '%';
  2802. }
  2803. if ($sum_post > 0) {
  2804. for ($i = 1; $i < $percent_post * 2; $i ++)
  2805. $bar_post .= iassign_icons::insert('hbar_blue');
  2806. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2807. } // if ($sum_post > 0)
  2808. if ($sum_iassign > 0) {
  2809. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2810. $text_nopost = number_format($percent_nopost, 1) . '%';
  2811. }
  2812. if ($sum_nopost > 0) {
  2813. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2814. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2815. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2816. } // if ($sum_nopost > 0)
  2817. print $OUTPUT->header();
  2818. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2819. print '<table width=100%><tr>';
  2820. print '<td align="right">' . $link_return . '</td>' . "\n";
  2821. print '</td></tr></table>' . "\n";
  2822. print "<br/><br/>\n";
  2823. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2824. print '<tr><th colspan=3 class="header c1">' . "\n";
  2825. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2826. // $imagetext = '');
  2827. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2828. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2829. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2830. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2831. print '</tr>' . "\n";
  2832. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2833. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2834. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2835. print '</tr>' . "\n";
  2836. if ($sum_post) {
  2837. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2838. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2839. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2840. print '</tr>' . "\n";
  2841. } // if ($sum_post)
  2842. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2843. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2844. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2845. print '</tr>' . "\n";
  2846. print "</table>";
  2847. print "<br><br>";
  2848. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2849. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2850. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2851. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2852. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2853. $sum_grade = 0;
  2854. $sum_grade_student = 0;
  2855. $avg = 0;
  2856. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2857. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2858. if (!$iassign_submission) {
  2859. $iassign_submission = new stdClass();
  2860. $iassign_submission->grade = 0;
  2861. }
  2862. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2863. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2864. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2865. print '</tr>' . "\n";
  2866. $sum_grade += $iassign_statement_activity_item->grade;
  2867. $sum_grade_student += $iassign_submission->grade;
  2868. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2869. if ($sum_grade > 0)
  2870. $avg = $sum_grade_student / $sum_grade * 100;
  2871. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2872. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2873. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2874. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2875. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2876. print "</table>";
  2877. print $OUTPUT->footer();
  2878. die();
  2879. } // function stats_students()
  2880. /// Display page of iAssign's activity
  2881. function view_iassigns () {
  2882. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2883. $id = $this->cm->id;
  2884. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2885. $notice = optional_param('notice', '', PARAM_TEXT);
  2886. if (strpos($notice, 'error'))
  2887. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2888. else if ($notice != '')
  2889. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2890. print $OUTPUT->box_start();
  2891. print '<table width=100% border=0><tr>' . "\n";
  2892. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2893. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2894. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2895. $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>";
  2896. $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>";
  2897. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2898. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2899. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2900. // Has capability to see "report": teacher or up
  2901. print '<td width=10% align="left">' . "\n";
  2902. print $link_help;
  2903. print '</td>' . "\n";
  2904. print '<td width=10% align="left">' . "\n";
  2905. print $link_report;
  2906. print '</td>' . "\n";
  2907. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2908. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2909. print '<td width=15% align="left">' . "\n";
  2910. print $link_add;
  2911. print "</td>\n";
  2912. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2913. //print '</tr></table>' . "\n";
  2914. print '<div style="float: right;">';
  2915. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2916. if ($iassign_list) {
  2917. print '<td align="right">' . "\n";
  2918. // $USER->iassignEdit == 0 view 'Turn editing off'
  2919. // $USER->iassignEdit == 1 view 'Turn editing on'
  2920. if (!isset($USER->iassignEdit))
  2921. $USER->iassignEdit = 0;
  2922. if ($USER->iassignEdit == 0) {
  2923. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2924. $botton = 1;
  2925. } // if ($USER->iassignEdit == 0)
  2926. elseif ($USER->iassignEdit == 1) {
  2927. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2928. $botton = 0;
  2929. } // elseif ($USER->iassignEdit == 1)
  2930. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2931. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2932. print " <input type=submit value='$bottonEdit_message'/>\n";
  2933. print "</form>\n";
  2934. print "</td>\n";
  2935. } // if ($iassign_list)
  2936. }
  2937. print '</tr></table>' . "\n";
  2938. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2939. // $this->view_legend_icons();
  2940. print $OUTPUT->box_end();
  2941. $iassign_array_exercise = array();
  2942. $i_exercise = 0;
  2943. $iassign_array_test = array();
  2944. $i_test = 0;
  2945. $iassign_array_example = array();
  2946. $i_example = 0;
  2947. $iassign_array_general = array();
  2948. $i_general = 0;
  2949. if ($iassign_list) {
  2950. if ($this->iassign->activity_group == 0) {
  2951. foreach ($iassign_list as $iassign) {
  2952. $iassign_array_general[$i_general] = $iassign;
  2953. $i_general ++;
  2954. }
  2955. } // if ($this->iassign->activity_group == 0)
  2956. else {
  2957. foreach ($iassign_list as $iassign) {
  2958. if ($iassign->type_iassign == 3) {
  2959. $iassign_array_exercise[$i_exercise] = $iassign;
  2960. $i_exercise ++;
  2961. } // if ($iassign->type_iassign == 3)
  2962. if ($iassign->type_iassign == 2) {
  2963. $iassign_array_test[$i_test] = $iassign;
  2964. $i_test ++;
  2965. } // if ($iassign->type_iassign == 2)
  2966. if ($iassign->type_iassign == 1) {
  2967. $iassign_array_example[$i_example] = $iassign;
  2968. $i_example ++;
  2969. } // if ($iassign->type_iassign == 1)
  2970. }
  2971. }
  2972. if ($iassign_array_exercise) {
  2973. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2974. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2975. }
  2976. if ($iassign_array_test) {
  2977. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2978. $this->show_iassign($title, $iassign_array_test, $i_test);
  2979. }
  2980. if ($iassign_array_example) {
  2981. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2982. $this->show_iassign($title, $iassign_array_example, $i_example);
  2983. }
  2984. if ($iassign_array_general) {
  2985. $title = "";
  2986. $this->show_iassign($title, $iassign_array_general, $i_general);
  2987. }
  2988. } else { // if ($iassign_list)
  2989. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2990. }
  2991. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2992. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2993. print $OUTPUT->box_start();
  2994. print '<table width=100% border=0><tr>' . "\n";
  2995. print '<td width=10% align="left">' . "\n";
  2996. print $link_report;
  2997. print '</td>' . "\n";
  2998. print '</tr></table>' . "\n";
  2999. print $OUTPUT->box_end();
  3000. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3001. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3002. print $OUTPUT->box_start();
  3003. print '<table width=100% border=0><tr>' . "\n";
  3004. print '<td align="left">' . "\n";
  3005. print $link_add;
  3006. print '</td>' . "\n";
  3007. print '</tr></table>' . "\n";
  3008. print $OUTPUT->box_end();
  3009. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3010. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3011. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3012. $this->view_legend_icons();
  3013. } // function view_iassigns()
  3014. /// Display all iAssigns
  3015. function show_iassign ($title, $iassign_array, $i) {
  3016. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3017. $id = $this->cm->id;
  3018. print $OUTPUT->box_start();
  3019. print " <script type='text/javascript'>
  3020. //<![CDATA[
  3021. function validate_move () {
  3022. var radios = document.getElementsByName('iassign_destiny');
  3023. var formValid = false;
  3024. //alert('aqui validate_move()');
  3025. var i = 0;
  3026. while (!formValid && i < radios.length) {
  3027. if (radios[i].checked) formValid = true;
  3028. i++;
  3029. }
  3030. if (!formValid) {
  3031. document.getElementById('move_dest').classList.add('alert-danger');
  3032. }
  3033. return formValid;
  3034. }
  3035. var modal;
  3036. function load_move(id_ias) {
  3037. document.form_move_activity.iassign_current.value = id_ias;
  3038. modal.style.display = 'block';
  3039. var radios = document.getElementsByName('iassign_destiny');
  3040. var i = 0;
  3041. while (i < radios.length) {
  3042. radios[i].checked = false;
  3043. i++;
  3044. }
  3045. document.getElementById('move_dest').classList.remove('alert-danger');
  3046. }
  3047. function load_modal_elements() {
  3048. modal = document.getElementById('myModal');
  3049. var span = document.getElementById('close_modal');
  3050. span.onclick = function() {
  3051. modal.style.display = 'none';
  3052. }
  3053. window.onclick = function(event) {
  3054. if (event.target == modal) {
  3055. modal.style.display = 'none';
  3056. }
  3057. }
  3058. }
  3059. window.onload = load_modal_elements;
  3060. //]]>
  3061. </script>\n";
  3062. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3063. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3064. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3065. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3066. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3067. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3068. <input type='hidden' name='iassign_current' value='' />";
  3069. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3070. $section = $course_sections[0];
  3071. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3072. for ($k = 0; $k < count($ids_sections); $k++) {
  3073. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3074. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3075. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3076. if ($c_cm) {
  3077. if ($ccm->instance == $c_cm->instance) {
  3078. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3079. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3080. }
  3081. else {
  3082. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3083. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3084. }
  3085. }
  3086. }
  3087. $radio_buttons .= "</ul>";
  3088. }
  3089. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3090. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3091. </form>
  3092. </div></div> </div></div>\n";
  3093. print " <style>.modal {
  3094. display: none;
  3095. position: fixed;
  3096. z-index: 1;
  3097. left: 0;
  3098. top: 0;
  3099. width: 100%;
  3100. height: 100%;
  3101. overflow: scroll;
  3102. background-color: rgb(0,0,0);
  3103. background-color: rgba(0,0,0,0.4);
  3104. }
  3105. .modal-content {
  3106. background-color: #fefefe;
  3107. margin: 15% auto;
  3108. padding: 10px 10px;
  3109. border: 1px solid #888;
  3110. width: 50%;
  3111. }
  3112. #close_modal {
  3113. color: #aaa;
  3114. float: right;
  3115. font-size: 28px;
  3116. font-weight: bold;
  3117. margin-top: -15px;
  3118. margin-right: -3px;
  3119. }
  3120. #close_modal:hover,
  3121. #close_modal:focus {
  3122. color: black;
  3123. text-decoration: none;
  3124. cursor: pointer;
  3125. }
  3126. #modal_title {
  3127. min-height: 3rem;
  3128. color: initial;
  3129. background: initial;
  3130. font-size: 1.5rem;
  3131. line-height: 1.5;
  3132. padding: 15px;
  3133. border-bottom: 1px solid #e5e5e5;
  3134. }
  3135. .input_move {
  3136. width: 90%;
  3137. padding: 2px;
  3138. }
  3139. .input_move:hover {
  3140. background: #eff0ef;
  3141. }
  3142. </style>";
  3143. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3144. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3145. for ($j = 0; $j < $i; $j ++) {
  3146. $iassign_current = $iassign_array[$j]->id;
  3147. // receiver=1 - message to teacher
  3148. // receiver=2 - message to student
  3149. $sum_comment = 0;
  3150. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3151. foreach ($iassign_submissions as $iassign_submission) {
  3152. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3153. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3154. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3155. if ($verify_message)
  3156. foreach ($verify_message as $tmp)
  3157. $sum_comment += $tmp;
  3158. } // foreach ($iassign_submissions as $iassign_submission)
  3159. if ($sum_comment == 0)
  3160. $comment_unread = "";
  3161. else {
  3162. $comment_unread_message = get_string('comment_unread', 'iassign');
  3163. if ($sum_comment == 1)
  3164. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3165. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3166. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3167. }
  3168. if ($j == $i - 1)
  3169. $iassign_down = $iassign_array[$j]->id;
  3170. else
  3171. $iassign_down = $iassign_array[$j + 1]->id;
  3172. if ($j > 0)
  3173. $iassign_up = $iassign_array[$j - 1]->id;
  3174. else
  3175. $iassign_up = $iassign_array[$j]->id;
  3176. if ($iassign_array[$j]->visible == 0)
  3177. $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>";
  3178. else
  3179. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3180. $links .= $comment_unread;
  3181. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3182. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3183. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3184. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3185. if ($j==0) // first activity
  3186. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3187. else
  3188. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3189. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3190. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3191. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3192. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3193. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3194. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3195. if (count($iassign_array) > 1) {
  3196. if ($j == 0)
  3197. $links .= $link_down;
  3198. elseif ($j == $i - 1)
  3199. $links .= $link_up;
  3200. else
  3201. $links .= $link_up . $link_down;
  3202. } // if (count($iassign_array) > 1)
  3203. $links .= $link_edit . $link_delete;
  3204. if ($iassign_array[$j]->visible == 0)
  3205. $links .= $link_visible_show;
  3206. else
  3207. $links .= $link_visible_hide;
  3208. $links .= $link_duplicate_activity . $link_move_activity;
  3209. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3210. print '<p>' . $links . '</p>' . "\n";
  3211. }
  3212. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3213. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3214. print '<table width=100% ><tr>' . "\n";
  3215. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3216. print '</tr></table>' . "\n";
  3217. for ($j = 0; $j < $i; $j ++) {
  3218. $icon_status = "";
  3219. $icon_comment = "";
  3220. if ($iassign_array[$j]->visible == 1) {
  3221. $iassign_current = $iassign_array[$j]->id;
  3222. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3223. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3224. $icon_status = "";
  3225. $icon_comment = "";
  3226. if ($iassign_submission) {
  3227. // receiver=1 - message to teacher
  3228. // receiver=2 - message to student
  3229. // $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");
  3230. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3231. $verify_message = $DB->get_record_sql(
  3232. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3233. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3234. if ($verify_message)
  3235. foreach ($verify_message as $tmp)
  3236. $sum_comment = $tmp;
  3237. if ($sum_comment > 0) {
  3238. $comment_unread_message = get_string('comment_unread', 'iassign');
  3239. if ($sum_comment == 1)
  3240. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3241. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3242. }
  3243. // $icon_comment = iassign_icons::insert('comment_unread');
  3244. if ($iassign_array[$j]->type_iassign == 3) {
  3245. if ($iassign_array[$j]->show_answer == 1) {
  3246. if ($iassign_submission->status == 3)
  3247. $icon_status = iassign_icons::insert('correct');
  3248. elseif ($iassign_submission->status == 2)
  3249. $icon_status = iassign_icons::insert('incorrect');
  3250. elseif ($iassign_submission->status == 1)
  3251. $icon_status = iassign_icons::insert('post');
  3252. elseif ($iassign_submission->status == 0)
  3253. $icon_status = iassign_icons::insert('not_post');
  3254. } // if ($iassign_array[$j]->show_answer==1)
  3255. else {
  3256. if ($iassign_submission->status == 0)
  3257. $icon_status = iassign_icons::insert('not_post');
  3258. else
  3259. $icon_status = iassign_icons::insert('post');
  3260. }
  3261. } // if ($iassign_array[$j]->type_iassign == 3)
  3262. } // if ($iassign_submission)
  3263. elseif ($iassign_array[$j]->type_iassign == 3) {
  3264. $icon_status = iassign_icons::insert('not_post');
  3265. } // if ($iassign_array[$j]->type_iassign == 3)
  3266. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3267. } // if ($iassign_array[$j]->visible == 1)
  3268. } // for ($j = 0; $j < $i; $j++)
  3269. } else if (isguestuser()) {
  3270. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3271. print '<table width=100% ><tr>' . "\n";
  3272. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3273. print '</tr></table>' . "\n";
  3274. for ($j = 0; $j < $i; $j ++) {
  3275. $icon_status = "";
  3276. $icon_comment = "";
  3277. if ($iassign_array[$j]->visible == 1) {
  3278. $iassign_current = $iassign_array[$j]->id;
  3279. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3280. print '<p>' . $links . '</p>' . "\n";
  3281. } // if ($iassign_array[$j]->visible == 1)
  3282. }
  3283. }
  3284. print $OUTPUT->box_end();
  3285. } // function show_iassign($title, $iassign_array, $i)
  3286. /// Show message of return
  3287. function return_home_course ($message) {
  3288. //D global $DB, $OUTPUT;
  3289. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3290. //D echo $OUTPUT->box_start();
  3291. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3292. //D echo '<tr><td align="left"><strong>' . "\n";
  3293. //D print_string($message, 'iassign');
  3294. //D echo '</strong></td>' . "\n";
  3295. //D echo '<td width=20% align="right">' . "\n";
  3296. //D echo $link_return;
  3297. //D echo '</td></tr></table>' . "\n";
  3298. //D echo $OUTPUT->box_end();
  3299. //D // echo $OUTPUT->footer();
  3300. redirect(new moodle_url($this->return . '&notice=' . $message));
  3301. exit;
  3302. }
  3303. /// Search comment of activity
  3304. function search_comment_submission ($iassign_submissionid) {
  3305. global $USER, $DB, $OUTPUT, $COURSE;
  3306. // $context = context_course::instance($COURSE->id);
  3307. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3308. $colorEdit2 = "#b7ceee";
  3309. $has_capability = 0;
  3310. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3311. $text = "";
  3312. if ($comments) {
  3313. $even = 1;
  3314. foreach ($comments as $tmp) {
  3315. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3316. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3317. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3318. // $text .= $tmp->comment . "</td></tr>";
  3319. //} else {
  3320. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3321. if ($even) {
  3322. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3323. $even = 0;
  3324. } else {
  3325. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3326. $even = 1;
  3327. }
  3328. $text .= $tmp->comment . "</td></tr>\n";
  3329. } // foreach ($comments as $tmp)
  3330. }
  3331. return $text;
  3332. }
  3333. /// Update comment of activity
  3334. function update_comment ($iassign_submissionid) {
  3335. global $USER, $DB, $OUTPUT;
  3336. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3337. $receiver = 1; // student message to teacher
  3338. else
  3339. $receiver = 2; // teacher message to student
  3340. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3341. if ($verify_message) {
  3342. foreach ($verify_message as $message) {
  3343. if ($message->receiver == $receiver) {
  3344. $newentry = new stdClass();
  3345. $newentry->id = $message->id;
  3346. $newentry->return_status = 1;
  3347. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3348. print_error('error_update', 'iassign');
  3349. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3350. } // if ($message->receiver == $receiver)
  3351. // Trigger module viewed event.
  3352. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3353. 'objectid' => $this->iassign->id,
  3354. 'context' => $this->context
  3355. ));
  3356. $event->add_record_snapshot('course', $this->course);
  3357. $event->trigger();
  3358. } // foreach ($verify_message as $message)
  3359. }
  3360. }
  3361. /// Record comment of activity
  3362. function write_comment_submission () {
  3363. global $USER, $CFG, $DB;
  3364. $id = $this->cm->id;
  3365. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3366. $row = optional_param('row', 0, PARAM_INT);
  3367. $column = optional_param('column', 0, PARAM_INT);
  3368. $sum_comment = 0;
  3369. $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);
  3370. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3371. $str1 = trim($submission_comment);
  3372. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3373. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3374. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3375. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3376. $receiver = 1; // student message to teacher
  3377. $this->action = 'view';
  3378. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3379. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3380. } else {
  3381. $receiver = 2; // teacher message to student
  3382. $this->action = 'viewsubmission';
  3383. //D $tousers = array(); //MOOC 2016
  3384. //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
  3385. }
  3386. //MOOC 2016: foi p/ 15 linhas acima:
  3387. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3388. if (!$iassign_submission) {
  3389. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3390. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3391. $this->iassign_submission_current = $id_submission;
  3392. } else {
  3393. $id_submission = $iassign_submission->id;
  3394. } // if (!$iassign_submission)
  3395. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3396. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3397. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3398. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3399. $comments = $DB->get_record_sql(
  3400. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3401. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3402. if ($comments)
  3403. foreach ($comments as $tmp)
  3404. $sum_comment = $tmp;
  3405. if ($sum_comment == 0) {
  3406. $newentry = new stdClass();
  3407. $newentry->iassign_submissionid = $id_submission;
  3408. $newentry->comment_authorid = $USER->id;
  3409. $newentry->timecreated = time();
  3410. $newentry->comment = $submission_comment;
  3411. $newentry->receiver = $receiver;
  3412. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3413. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3414. //T $eventdata = new stdClass();
  3415. //T $eventdata->component = 'mod_iassign'; //your component name
  3416. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3417. //T $eventdata->userfrom = $USER;
  3418. //T $eventdata->userto = $touser;
  3419. //T $eventdata->subject = "Teste de Subject";
  3420. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3421. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3422. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3423. //T $eventdata->smallmessage = "Teste de Mensagem";
  3424. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3425. //T // alteracao tulio faria
  3426. //T //message_send($eventdata);
  3427. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3428. // Trigger module viewed event.
  3429. $event = \mod_iassign\event\submission_comment_created::create(array(
  3430. 'objectid' => $this->iassign->id,
  3431. 'context' => $this->context
  3432. ));
  3433. $event->add_record_snapshot('course', $this->course);
  3434. $event->trigger();
  3435. }
  3436. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3437. // if ($this->action=='viewsubmission') {
  3438. // echo $OUTPUT->header();
  3439. // $this->return_last('confirm_add_comment', $link_return);
  3440. // die;
  3441. // }
  3442. return true;
  3443. } // function write_comment_submission()
  3444. /// Writes a new submission
  3445. // The first student answer is under 'function get_answer()'
  3446. function new_submission ($iassignid, $id_user, $receiver) {
  3447. global $USER, $DB, $OUTPUT;
  3448. $newentry = new stdClass();
  3449. $newentry->iassign_statementid = $iassignid;
  3450. $newentry->userid = $id_user;
  3451. $newentry->timecreated = time();
  3452. $newentry->timemodified = time();
  3453. $newentry->answer = 0; // student only submit message
  3454. if ($receiver == 2) // teacher message to student (write id teacher)
  3455. $newentry->teacher = $USER->id;
  3456. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3457. return_home_course('error_insert_submissions');
  3458. else {
  3459. // Trigger module view event
  3460. $event = \mod_iassign\event\submission_created::create(array(
  3461. 'objectid' => $this->iassign->id,
  3462. 'context' => $this->context
  3463. ));
  3464. $event->add_record_snapshot('course', $this->course);
  3465. $event->trigger();
  3466. }
  3467. return $newentry->id;
  3468. }
  3469. /// Return to a specific address of page
  3470. function return_last ($message, $link_return) {
  3471. global $DB, $OUTPUT;
  3472. print $OUTPUT->box_start();
  3473. print '<table width=100% border=0 valign="top">' . "\n";
  3474. print '<tr><td align="left"><strong>' . "\n";
  3475. print_string($message, 'iassign');
  3476. print '</strong></td>' . "\n";
  3477. print '<td width=20% align="right">' . "\n";
  3478. print $link_return;
  3479. print '</td></tr></table>' . "\n";
  3480. print $OUTPUT->box_end();
  3481. print $OUTPUT->footer();
  3482. die();
  3483. } // function return_last($message, $link_return)
  3484. } // class iassign
  3485. /// Class for manage activities
  3486. class activity {
  3487. var $activity;
  3488. /// Constructor of class.
  3489. // @param int $id Id of activity
  3490. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3491. //D public function activity($id) { self::__construct($id); }
  3492. function __construct ($id) {
  3493. global $DB;
  3494. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3495. if (empty($this->activity))
  3496. $this->activity = null;
  3497. }
  3498. /// Get an activity
  3499. // @return NULL
  3500. function get_activity () {
  3501. if ($this->activity != null)
  3502. return $this->activity;
  3503. else
  3504. return null;
  3505. }
  3506. /// Delete interactive activities
  3507. function delete ($return) {
  3508. global $USER, $CFG, $DB, $OUTPUT;
  3509. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3510. $output = $OUTPUT->header();
  3511. $output .= $OUTPUT->box_start();
  3512. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3513. if ($iassign_submission_currents) {
  3514. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3515. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3516. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3517. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3518. $output .= $OUTPUT->box_end();
  3519. $output .= $OUTPUT->footer();
  3520. print $output;
  3521. die();
  3522. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3523. } // if ($iassign_submission_currents)
  3524. else
  3525. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3526. $output .= '<table width=50% border=0>';
  3527. $output .= '<tr valign="top"><td>';
  3528. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3529. $output .= '</td><td>';
  3530. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3531. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3532. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3533. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3534. $output .= "</form>\n";
  3535. $output .= '</td><td>';
  3536. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3537. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3538. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3539. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3540. $output .= "</form>\n";
  3541. $output .= '</td></tr></table>' . "\n";
  3542. $output .= $OUTPUT->box_end();
  3543. $output .= $OUTPUT->footer();
  3544. print $output;
  3545. } // function delete($return)
  3546. /// Function for confirm the delete of activity
  3547. // @param String $return Url of return
  3548. // @param Object $iassign Object content an activity
  3549. function deleteyes ($return, $iassign) {
  3550. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3551. $msg = '';
  3552. if (!empty($this->activity->id)) {
  3553. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3554. if ($iassign_submission_currents) {
  3555. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3556. foreach ($iassign_submission_currents as $iassign_submission)
  3557. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3558. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3559. } // if ($iassign_submission_currents)
  3560. }
  3561. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3562. // Remove all files associated to this activity:
  3563. $fs = get_file_storage();
  3564. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3565. $this->delete_calendar($this->activity->id);
  3566. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3567. iassign::update_grade_iassign($this->activity->iassignid);
  3568. if ($delete_iassign_current) {
  3569. $iassign->return_home_course('confirm_delete_iassign');
  3570. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3571. } else {
  3572. $iassign->return_home_course('error_confirm_delete_iassign');
  3573. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3574. }
  3575. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3576. }
  3577. }
  3578. /// Changes position of activities (between those inside a group of interactive activities)
  3579. // @param $move_action = must be "up" or "down"
  3580. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3581. function move_iassign ($move_action, $target, $return) {
  3582. global $DB, $OUTPUT;
  3583. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3584. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3585. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3586. if ($move_action=="firstdown") {
  3587. $final_position_source = 2;
  3588. $final_position_target = 1;
  3589. }
  3590. else
  3591. if ($move_action=="down") {
  3592. $final_position_target = $this->activity->position;
  3593. $final_position_source = $final_position_target + 1;
  3594. }
  3595. else
  3596. if ($move_action=="up") {
  3597. $final_position_target = $this->activity->position;
  3598. $final_position_source = $final_position_target - 1;
  3599. }
  3600. else { // error:
  3601. print_error('error_update_move_iassign', 'iassign');
  3602. exit;
  3603. }
  3604. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3605. $newentry->id = $this->activity->id; // ID of the "source activity"
  3606. $newentry->position = $final_position_source;
  3607. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3608. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3609. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3610. print_error('error_update_move_iassign', 'iassign');
  3611. }
  3612. else { // first update performed successfully
  3613. $newentry->id = $iassign_target->id;
  3614. $newentry->position = $final_position_target;
  3615. if (!$DB->update_record('iassign_statement', $newentry))
  3616. print_error('error_update_move_iassign', 'iassign');
  3617. }
  3618. redirect($return);
  3619. }
  3620. /// Enable or disable the display of interactive activities
  3621. function visible_iassign ($return) {
  3622. global $DB;
  3623. $newentry = new stdClass();
  3624. $newentry->id = $this->activity->id;
  3625. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3626. if (!$DB->update_record('iassign_statement', $newentry))
  3627. print_error('error_update_visible_iassign', 'iassign');
  3628. redirect($return);
  3629. }
  3630. /// Add news interactive activities (register in table 'iassign_statement')
  3631. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3632. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3633. function new_iassign ($param) {
  3634. global $DB;
  3635. $newentry = new stdClass();
  3636. $newentry->iassignid = $param->iassignid;
  3637. $newentry->name = $param->name;
  3638. $newentry->type_iassign = $param->type_iassign;
  3639. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3640. $proposition = $param->proposition;
  3641. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3642. else $proposition_text = $proposition;
  3643. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3644. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3645. //TODO Then get it directly from the form data $_POST!
  3646. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3647. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3648. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3649. $newentry->author_name = $param->author_name;
  3650. $newentry->author_modified_name = $param->author_modified_name;
  3651. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3652. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3653. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3654. $newentry->grade = $param->grade;
  3655. $newentry->timemodified = time();
  3656. $newentry->timecreated = time();
  3657. if ($param->type_iassign == 1) {
  3658. $newentry->timedue = 0;
  3659. $newentry->timeavailable = 0;
  3660. } // if ($param->type_iassign == 1)
  3661. else {
  3662. $newentry->timedue = $param->timedue;
  3663. $newentry->timeavailable = $param->timeavailable;
  3664. }
  3665. $newentry->preventlate = $param->preventlate;
  3666. $newentry->test = $param->test;
  3667. $newentry->special_param1 = $param->special_param1;
  3668. $newentry->visible = $param->visible;
  3669. $newentry->position = $param->position;
  3670. $newentry->max_experiment = $param->max_experiment;
  3671. $newentry->dependency = $param->dependency;
  3672. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3673. $newentry->show_answer = $param->show_answer;
  3674. $id = $DB->insert_record("iassign_statement", $newentry);
  3675. if ($id) {
  3676. $component = 'mod_iassign';
  3677. $filearea = 'exercise';
  3678. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3679. $file = $fs->get_file_by_id($param->file);
  3680. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3681. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  3682. //$itemid = $id;
  3683. // File already inserted in other context!
  3684. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3685. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3686. $updateentry = new stdClass();
  3687. $updateentry->id = $id;
  3688. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3689. $updateentry->file = $newfile->get_itemid();
  3690. if (!$DB->update_record("iassign_statement", $updateentry))
  3691. print_error('error_add', 'iassign');
  3692. if ($param->type_iassign == 3)
  3693. iassign::update_grade_iassign($param->iassignid);
  3694. //TODO iLM_HTML5 :: //MOOC2014
  3695. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3696. //D if ($iassign_ilm_configs) {
  3697. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3698. //D if ($iassign_ilm_config->param_type != 'static') {
  3699. //D $newentry = new stdClass();
  3700. //D $newentry->iassign_statementid = $id;
  3701. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3702. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3703. //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});
  3704. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3705. //D print_error('error_add_param', 'iassign');
  3706. //D }
  3707. //D }
  3708. //D }
  3709. // log event --------------------------------------------------------------------------------------
  3710. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3711. // log event --------------------------------------------------------------------------------------
  3712. return $id;
  3713. }
  3714. else
  3715. print_error('error_add', 'iassign');
  3716. } // function new_iassign($param)
  3717. /// Add the calendar entries for this iassign
  3718. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3719. // @return bool
  3720. static function add_calendar ($iassignid) {
  3721. global $DB, $CFG;
  3722. require_once($CFG->dirroot . '/calendar/lib.php');
  3723. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3724. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3725. $event = new stdClass();
  3726. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3727. $event->description = $iassign_statement_activity_item->name;
  3728. $event->courseid = $iassign->course;
  3729. $event->groupid = 0;
  3730. $event->userid = 0;
  3731. $event->modulename = 'iassign';
  3732. $event->instance = $iassign->id;
  3733. $event->eventtype = 'due';
  3734. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3735. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3736. calendar_event::create($event);
  3737. }
  3738. /// Update the calendar entries for this iassign
  3739. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3740. // @return bool
  3741. function update_calendar ($iassignid, $olddescription) {
  3742. global $DB, $CFG;
  3743. require_once($CFG->dirroot . '/calendar/lib.php');
  3744. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3745. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3746. $event = new stdClass();
  3747. $event->id = 0;
  3748. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3749. if ($events) {
  3750. foreach ($events as $value) {
  3751. if ($value->description == $olddescription) {
  3752. $event->id = $value->id;
  3753. }
  3754. }
  3755. }
  3756. if ($event->id != 0) {
  3757. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3758. $event->description = $iassign_statement_activity_item->name;
  3759. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3760. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3761. $calendarevent = calendar_event::load($event->id);
  3762. $calendarevent->update($event);
  3763. } else
  3764. $this->add_calendar($iassignid);
  3765. }
  3766. /// Update the calendar entries for this iassign
  3767. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3768. // @return bool
  3769. function delete_calendar ($iassignid) {
  3770. global $DB, $CFG;
  3771. require_once($CFG->dirroot . '/calendar/lib.php');
  3772. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3773. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3774. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3775. if ($events) {
  3776. foreach ($events as $value) {
  3777. if ($value->description == $iassign_statement_activity_item->name) {
  3778. $DB->delete_records('event', array('id' => $value->id));
  3779. }
  3780. }
  3781. }
  3782. }
  3783. /// Update interactive activities
  3784. function update_iassign ($param) {
  3785. global $DB;
  3786. $component = 'mod_iassign';
  3787. $filearea = 'exercise';
  3788. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3789. $file = $fs->get_file_by_id($param->file);
  3790. $fileold = $fs->get_file_by_id($param->fileold);
  3791. if ($param->file != $param->fileold) {
  3792. if ($fileold) {
  3793. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3794. foreach ($fileoldarea as $value) {
  3795. $value->delete();
  3796. }
  3797. }
  3798. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3799. $itemid = $file->get_itemid() + $param->iassign_id;
  3800. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3801. $param->file = $newfile->get_itemid();
  3802. } else
  3803. $param->file = $file->get_itemid();
  3804. } else {
  3805. $param->file = $file->get_itemid();
  3806. }
  3807. $newentry = new stdClass();
  3808. $newentry->id = $param->iassign_id;
  3809. $newentry->name = $param->name;
  3810. $newentry->type_iassign = $param->type_iassign;
  3811. //2019 $newentry->proposition = $param->proposition;
  3812. $proposition = $param->proposition;
  3813. if (is_array($proposition))
  3814. $proposition_text = $proposition['text'];
  3815. else
  3816. $proposition_text = $proposition;
  3817. $newentry->proposition = $proposition_text;
  3818. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3819. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3820. $newentry->grade = $param->grade;
  3821. $newentry->author_modified_name = $param->author_modified_name;
  3822. $newentry->timemodified = time();
  3823. if ($param->type_iassign == 1) {
  3824. $newentry->timedue = 0;
  3825. $newentry->timeavailable = 0;
  3826. } // if ($param->type_iassign == 1)
  3827. else {
  3828. $newentry->timedue = $param->timedue;
  3829. $newentry->timeavailable = $param->timeavailable;
  3830. }
  3831. $newentry->preventlate = $param->preventlate;
  3832. $newentry->test = $param->test;
  3833. $newentry->special_param1 = $param->special_param1;
  3834. $newentry->visible = $param->visible;
  3835. $newentry->max_experiment = $param->max_experiment;
  3836. $newentry->dependency = $param->dependency;
  3837. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3838. $newentry->show_answer = $param->show_answer;
  3839. if (!$DB->update_record("iassign_statement", $newentry))
  3840. print_error('error_update', 'iassign');
  3841. if ($param->type_iassign == 3) {
  3842. iassign::update_grade_iassign($param->iassignid);
  3843. }
  3844. //$id = $newentry->id; // MOOC 2016 --- inicio
  3845. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3846. //if ($iassign_activity_item_configs) {
  3847. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3848. // $newentry = new stdClass();
  3849. // $newentry->id = $iassign_activity_item_config->id;
  3850. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3851. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3852. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3853. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3854. // print_error('error_edit_param', 'iassign');
  3855. // }
  3856. // } // MOOC 2016 --- final
  3857. // log event --------------------------------------------------------------------------------------
  3858. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3859. // log event --------------------------------------------------------------------------------------
  3860. return $newentry->id;
  3861. // if ($param->type_iassign==3)
  3862. // $this->update_grade_iassign($param->iassignid);
  3863. } // function update_iassign($param)
  3864. /// Show information of activity
  3865. function show_info_iassign () {
  3866. global $DB, $OUTPUT;
  3867. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3868. if ($this->activity->type_iassign == 3) {
  3869. if ($this->activity->dependency == 0) {
  3870. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3871. } else {
  3872. $dependencys = explode(';', $this->activity->dependency);
  3873. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3874. foreach ($dependencys as $dependency) {
  3875. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3876. if ($dependencyiassign)
  3877. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3878. } // foreach ($dependencys as $dependency)
  3879. } // if ($iassign_statement_activity_item->dependency == 0)
  3880. if ($this->activity->max_experiment == 0)
  3881. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3882. else
  3883. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3884. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3885. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3886. print $OUTPUT->box($output);
  3887. } // function show_info_iassign()
  3888. /// Shows date of opening and closing activities
  3889. function view_dates () {
  3890. global $USER, $CFG, $DB, $OUTPUT;
  3891. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3892. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3893. $status_iassign = "";
  3894. $status_iassign1 = "";
  3895. $status_iassign2 = "";
  3896. if ($this->activity->type_iassign == 1) // activity of type example
  3897. $type_iassign = get_string('example_iassign', 'iassign');
  3898. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3899. $type_iassign = get_string('test_iassign', 'iassign');
  3900. if ($this->activity->timeavailable > time()) {
  3901. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3902. } elseif ($this->activity->timedue < time()) {
  3903. $status_iassign = get_string('last_timedue', 'iassign');
  3904. }
  3905. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3906. $type_iassign = get_string('exercise_iassign', 'iassign');
  3907. if ($this->activity->timeavailable > time()) {
  3908. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3909. } elseif ($this->activity->timedue < time()) { // after delivery
  3910. $status_iassign = get_string('last_timedue', 'iassign');
  3911. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3912. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3913. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3914. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3915. if ($this->activity->test == 1) // allowed to test after of deadline
  3916. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3917. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3918. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3919. } // elseif ($iassign_statement_activity_item->test == 0)
  3920. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3921. } // elseif ($iassign_statement_activity_item->timedue < time())
  3922. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3923. $output = '<table width=100% >' . "\n";
  3924. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3925. $output .= '<tr>' . "\n";
  3926. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3927. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3928. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3929. // leo $output .= '<td width=80%>' . $type_iassign;
  3930. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3931. // $output .= '</td>' . "\n";
  3932. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3933. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3934. $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>";
  3935. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3936. } else {
  3937. $link_next = "";
  3938. $link_previous = "";
  3939. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3940. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3941. // previous_activity
  3942. if ($iassign_previous) {
  3943. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3944. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3945. } // next_activity
  3946. if ($iassign_next) {
  3947. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3948. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3949. }
  3950. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3951. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3952. $output .= '</tr></table>' . "\n";
  3953. $output .= '<table width=100% >' . "\n";
  3954. if ($this->activity->type_iassign > 1) {
  3955. if ($this->activity->timeavailable)
  3956. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3957. if ($this->activity->timedue)
  3958. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3959. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3960. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3961. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3962. $output .= '</table>' . "\n";
  3963. print $OUTPUT->box($output);
  3964. } // function view_dates()
  3965. } // class activity
  3966. /// Class to manage Interactive Learning Module (iLM)
  3967. class ilm {
  3968. var $ilm;
  3969. /// Constructor of class
  3970. // @param int $id Id of iLM
  3971. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3972. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3973. function __construct ($id) {
  3974. global $DB;
  3975. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3976. if (empty($this->ilm))
  3977. $this->ilm = null;
  3978. }
  3979. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  3980. // @calledby view_iassign_current()
  3981. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3982. global $USER, $CFG, $DB;
  3983. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3984. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3985. $typec = strtolower($iassign_ilm->type);
  3986. require_once 'ilm_handlers/' . $typec . '.php';
  3987. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  3988. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3989. return $retorno;
  3990. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3991. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3992. // @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);
  3993. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3994. // @param Object $file File in use in activity
  3995. // @return int Return the id of log
  3996. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3997. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3998. $newentry = new stdClass();
  3999. $newentry->iassign_statementid = $iassign_activity_itemid;
  4000. $newentry->userid = $USER->id;
  4001. $newentry->file = $content_or_id_from_ilm_security;
  4002. $newentry->timecreated = time();
  4003. $newentry->view = 1;
  4004. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4005. if (!$id_iLM_security) {
  4006. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4007. } // from (!$DB->insert_record("iassign_security", $newentry))
  4008. return $id_iLM_security;
  4009. }
  4010. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4011. // @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);
  4012. // @param int $userid
  4013. // @param int $iassign_activity_itemid Id of iassign statement
  4014. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4015. global $DB;
  4016. // 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")
  4017. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4018. }
  4019. } // class ilm
  4020. /// Class to manage settings of iLM.
  4021. class ilm_settings {
  4022. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4023. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4024. // @param int $ilm_id Id of iLM
  4025. // @param array $options An array with options for create dynamic tag html APPLET
  4026. // @return string Return with a tag html APPLET created
  4027. static function build_ilm_tags ($ilm_id, $options = array()) {
  4028. global $DB;
  4029. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4030. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4031. $typec = strtolower($iassign_ilm->type);
  4032. require_once 'ilm_handlers/' . $typec . '.php';
  4033. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4034. return $retorno;
  4035. } // static function build_ilm_tags($ilm_id, $options = array())
  4036. /// Function for get modified date of iLM file
  4037. // @param string $file_jar String with Ids of iLM files
  4038. // @return string Return with the filenames and modified date
  4039. static function applet_filetime ($file_jar) {
  4040. $filetime = "";
  4041. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4042. $files_jar = explode(",", $file_jar);
  4043. foreach ($files_jar as $one_file) {
  4044. $file = $fs->get_file_by_id($one_file);
  4045. if ($file)
  4046. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4047. }
  4048. return $filetime;
  4049. }
  4050. /// Function for verify an default applet
  4051. // @param String $file_jar String containing an list de ids of applet files
  4052. // @return boolean Return true or fale if applet is default
  4053. static function applet_default ($file_jar) {
  4054. $is_default = true;
  4055. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4056. $files_jar = explode(",", $file_jar);
  4057. foreach ($files_jar as $one_file) {
  4058. $file = $fs->get_file_by_id($one_file);
  4059. if ($file)
  4060. $is_default &= ($file->get_itemid() == 0);
  4061. }
  4062. return $is_default;
  4063. }
  4064. /// Function for get form variables for add, edit, or copy iLM
  4065. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4066. // @see settings_form.php
  4067. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4068. // @param int $ilm_id Id of iLM
  4069. // @param string $action String with the action
  4070. // @return object Return an object with forms variables
  4071. static function add_edit_copy_ilm ($ilm_id, $action) {
  4072. global $USER, $DB, $CFG;
  4073. require_once('settings_form.php'); // put the form
  4074. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4075. $param = new stdClass();
  4076. $param->action = $action;
  4077. $param->ilm_id = $ilm_id;
  4078. $CFG->action_ilm = $action;
  4079. $CFG->ilm_id = $ilm_id;
  4080. if ($action == 'add') {
  4081. $param->title = get_string('add_ilm', 'iassign');
  4082. $param->name = "";
  4083. $param->version = "";
  4084. $param->url = "";
  4085. $param->description = "";
  4086. $param->extension = "";
  4087. $param->author = $USER->id;
  4088. $param->file_jar = "";
  4089. $param->file_jar_static = "";
  4090. $param->file_class = "";
  4091. $param->width = 800;
  4092. $param->height = 600;
  4093. $param->enable = 0; // 0 - hide / 1 - show
  4094. $param->timecreated = time();
  4095. $param->timemodified = time();
  4096. $param->evaluate = 0;
  4097. $param->parent = 0;
  4098. }
  4099. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4100. if ($iassign_ilm) {
  4101. $description = json_decode($iassign_ilm->description);
  4102. $param->title = get_string('edit_ilm', 'iassign');
  4103. $param->id = $iassign_ilm->id;
  4104. $param->name_ilm = $iassign_ilm->name;
  4105. $param->name = $iassign_ilm->name;
  4106. $param->version = $iassign_ilm->version;
  4107. $param->ilm_type = $iassign_ilm->type;
  4108. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4109. $param->url = $iassign_ilm->url;
  4110. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4111. if (!isset($description->{current_language()})) {
  4112. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4113. else
  4114. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4115. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4116. }
  4117. else
  4118. $param->description = $description->{current_language()};
  4119. $param->description_lang = $iassign_ilm->description;
  4120. $param->extension = $iassign_ilm->extension;
  4121. $param->author = $iassign_ilm->author;
  4122. $param->file_jar = $iassign_ilm->file_jar;
  4123. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4124. $param->file_class = $iassign_ilm->file_class;
  4125. $param->width = $iassign_ilm->width;
  4126. $param->height = $iassign_ilm->height;
  4127. $param->enable = $iassign_ilm->enable;
  4128. $param->timecreated = $iassign_ilm->timecreated;
  4129. $param->timemodified = time();
  4130. $param->evaluate = $iassign_ilm->evaluate;
  4131. $param->parent = $iassign_ilm->parent;
  4132. }
  4133. }
  4134. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4135. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4136. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4137. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4138. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4139. // echo "Sem dados<br/>"; exit;
  4140. return;
  4141. }
  4142. $description = json_decode($iassign_ilm->description);
  4143. if ($iassign_ilm) {
  4144. if ($iassign_ilm->parent == 0)
  4145. $iassign_ilm->parent = $ilm_id;
  4146. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4147. $param->title = get_string('new_version_ilm', 'iassign');
  4148. $param->name_ilm = $iassign_ilm->name;
  4149. $param->name = $iassign_ilm->name;
  4150. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4151. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4152. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4153. $param->ilm_type = $iassign_ilm->type;
  4154. $param->url = $iassign_ilm->url;
  4155. $param->description = $description->{current_language()};
  4156. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4157. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4158. $param->extension = $iassign_ilm->extension;
  4159. $param->author = $USER->id;
  4160. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4161. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4162. $param->file_jar_static = '';
  4163. $param->file_class = $iassign_ilm->file_class;
  4164. $param->width = $iassign_ilm->width;
  4165. $param->height = $iassign_ilm->height;
  4166. $param->enable = 0;
  4167. $param->timecreated = time();
  4168. $param->timemodified = time();
  4169. $param->evaluate = $iassign_ilm->evaluate;
  4170. $param->parent = $iassign_ilm->parent;
  4171. }
  4172. }
  4173. elseif ($action == 'copy') {
  4174. $description = json_decode($iassign_ilm->description);
  4175. if ($iassign_ilm) {
  4176. if ($iassign_ilm->parent == 0)
  4177. $iassign_ilm->parent = $ilm_id;
  4178. $param->title = get_string('copy_ilm', 'iassign');
  4179. $param->id = $iassign_ilm->id;
  4180. $param->name_ilm = $iassign_ilm->name;
  4181. $param->name = $iassign_ilm->name;
  4182. $param->version = "";
  4183. $param->ilm_type = $iassign_ilm->type;
  4184. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4185. $param->url = $iassign_ilm->url;
  4186. $param->description = $description->{current_language()};
  4187. $param->description_lang = $iassign_ilm->description;
  4188. $param->extension = $iassign_ilm->extension;
  4189. $param->author = $USER->id;
  4190. $param->file_jar = '';
  4191. $param->file_jar_static = '';
  4192. $param->file_class = $iassign_ilm->file_class;
  4193. $param->width = $iassign_ilm->width;
  4194. $param->height = $iassign_ilm->height;
  4195. $param->enable = 0;
  4196. $param->timecreated = time();
  4197. $param->timemodified = time();
  4198. $param->evaluate = $iassign_ilm->evaluate;
  4199. $param->parent = $iassign_ilm->parent;
  4200. }
  4201. }
  4202. return $param;
  4203. } // static function add_edit_copy_ilm($ilm_id, $action)
  4204. /// Function for save iLM file in moodledata
  4205. // @param int $itemid Itemid of file save in draft (upload file)
  4206. // @param int $ilm_id Id of iLM
  4207. // @return string Return an string with ids of iLM files
  4208. static function new_file_ilm ($itemid, $iassign_ilm) {
  4209. global $CFG, $USER, $DB;
  4210. $return = null;
  4211. $file_jar = array();
  4212. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4213. $contextuser = context_user::instance($USER->id);
  4214. $contextsystem = context_system::instance();
  4215. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4216. if ($files_ilm) {
  4217. foreach ($files_ilm as $value) {
  4218. // CHECK IF file is HTML type
  4219. if ($iassign_ilm->type == 1) {
  4220. // Check if the file extension is ZIP
  4221. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4222. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4223. if ((strtolower($ext) == 'zip')) {
  4224. // Coping...:
  4225. $destination = 'ilm_debug/' . $value->get_filename();
  4226. $value->copy_content_to($destination);
  4227. // Extracting content...:
  4228. $zip = new ZipArchive();
  4229. $extracted = './ilm';
  4230. $dir = "";
  4231. if ($zip->open($destination) === TRUE) {
  4232. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4233. if (is_dir($dir)) {
  4234. $i = 1;
  4235. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4236. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4237. $i ++;
  4238. }
  4239. $name = $previous . "_" . $i;
  4240. $dir = './ilm/' . $name . "/";
  4241. $j = 0;
  4242. while ($item_name = $zip->getNameIndex($j)) {
  4243. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4244. $j++;
  4245. }
  4246. $zip->close();
  4247. }
  4248. $zip->open($destination);
  4249. $zip->extractTo($extracted);
  4250. $zip->close();
  4251. // After the extraction, remove it from DEBUG
  4252. unlink($destination);
  4253. } else { // Error trying to open destination...
  4254. // After the extraction error, also remove it from DEBUG
  4255. unlink($destination);
  4256. print_error('error_add_ilm_zip', 'iassign');
  4257. }
  4258. return $dir;
  4259. }
  4260. } // if ($iassign_ilm->type == 1)
  4261. if ($value->get_filename() != '.') {
  4262. $file_ilm = array(
  4263. 'userid' => $USER->id,
  4264. 'contextid' => $contextsystem->id,
  4265. 'component' => 'mod_iassign',
  4266. 'filearea' => 'ilm',
  4267. 'itemid' => rand(1, 999999999),
  4268. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4269. 'filename' => $value->get_filename());
  4270. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4271. array_push($file_jar, $file_ilm->get_id());
  4272. }
  4273. }
  4274. if (!empty($file_jar)) {
  4275. $return = implode(",", $file_jar);
  4276. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4277. foreach ($old_file_jar as $value) {
  4278. $file = $fs->get_file_by_id($value);
  4279. if ($file)
  4280. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4281. }
  4282. }
  4283. }
  4284. else // if ($files_ilm)
  4285. $return = $iassign_ilm->file_jar;
  4286. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4287. return $return;
  4288. } // static function new_file_ilm($itemid, $iassign_ilm)
  4289. /// Function for save in database an new iLM
  4290. // @param object $param An object with iLM params
  4291. static function new_ilm ($itemid) {
  4292. global $CFG, $USER, $OUTPUT;
  4293. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4294. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4295. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4296. }
  4297. $pathtemp = $CFG->dataroot . '/temp/';
  4298. $contextuser = context_user::instance($USER->id);
  4299. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4300. $zip = new zip_packer();
  4301. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4302. foreach ($files as $file) {
  4303. if (!$file->is_directory())
  4304. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4305. }
  4306. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4307. // Verifica se o pacote possui o XML
  4308. if (!$application_xml) {
  4309. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4310. return;
  4311. } else {
  4312. $missing = "";
  4313. if (!isset($application_xml->name)) {
  4314. $missing .= "name";
  4315. }
  4316. if (!isset($application_xml->version)) {
  4317. $missing .= ", version";
  4318. }
  4319. if (!isset($application_xml->type)) {
  4320. $missing .= ", type";
  4321. }
  4322. if (!isset($application_xml->extension)) {
  4323. $missing .= ", extension";
  4324. }
  4325. if (!isset($application_xml->file_jar)) {
  4326. $missing .= ", file_jar";
  4327. }
  4328. if (!isset($application_xml->file_class)) {
  4329. $missing .= ", file_class";
  4330. }
  4331. if (!isset($application_xml->width)) {
  4332. $missing .= ", width";
  4333. }
  4334. if (!isset($application_xml->height)) {
  4335. $missing .= ", height";
  4336. }
  4337. if (!isset($application_xml->evaluate)) {
  4338. $missing .= ", evaluate";
  4339. }
  4340. if (strlen($missing) > 2) {
  4341. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4342. return;
  4343. }
  4344. }
  4345. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4346. $typec = strtolower($application_xml->type);
  4347. require_once 'ilm_handlers/' . $typec . '.php';
  4348. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4349. return $retorno;
  4350. } // static function new_ilm($itemid)
  4351. /// Function for save in database an iLM edit
  4352. // @param object $param An object with iLM params
  4353. static function edit_ilm ($param, $itemid) {
  4354. // Descobrir o tipo de iLM:
  4355. global $DB, $USER, $CFG;
  4356. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4357. $pathtemp = $CFG->dataroot . '/temp/';
  4358. $contextuser = context_user::instance($USER->id);
  4359. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4360. $zip = new zip_packer();
  4361. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4362. $files_extract = null;
  4363. foreach ($files as $file) {
  4364. if (!$file->is_directory())
  4365. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4366. }
  4367. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4368. $typec = strtolower($iassign_t->type);
  4369. require_once 'ilm_handlers/' . $typec . '.php';
  4370. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4371. }
  4372. /// Function for register the new iLM (in database and in the directory)
  4373. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4374. // @param object $param An object with iLM params
  4375. static function copy_new_version_ilm ($param) {
  4376. global $DB, $CFG, $USER;
  4377. $itemid = $param->file;
  4378. $pathtemp = $CFG->dataroot . '/temp/';
  4379. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4380. //D echo "pathtemp=$pathtemp<br/>";
  4381. $contextuser = context_user::instance($USER->id);
  4382. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4383. $zip = new zip_packer();
  4384. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4385. $files_extract = null;
  4386. foreach ($files as $file) {
  4387. if (!$file->is_directory())
  4388. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4389. }
  4390. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4391. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4392. $typec = strtolower($iassign_t->type);
  4393. require_once 'ilm_handlers/' . $typec . '.php';
  4394. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4395. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4396. } // static function copy_new_version_ilm($param)
  4397. //VER::
  4398. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4399. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4400. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4401. /// Function for change visibility of iLM
  4402. // @param int $ilm_id Id of iLM
  4403. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4404. static function visible_ilm ($ilm_id, $status) {
  4405. global $DB;
  4406. if ($status == 0)
  4407. $visible = 1;
  4408. else
  4409. $visible = 0;
  4410. $newentry = new stdClass();
  4411. $newentry->id = $ilm_id;
  4412. $newentry->enable = $visible;
  4413. if (!$DB->update_record("iassign_ilm", $newentry))
  4414. error(get_string('error_edit_ilm', 'iassign'));
  4415. }
  4416. /// Function for confirm change default iLM
  4417. // @param int $ilm_id Id of iLM
  4418. // @param int $ilm_parent Id of parent iLM
  4419. // @return string Return with an string for create default page confirmation
  4420. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4421. global $OUTPUT, $DB;
  4422. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4423. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4424. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4425. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4426. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4427. return $return;
  4428. }
  4429. /// Function for change the default iLM
  4430. // @see settings_ilm.php
  4431. // @param int $ilm_id Id of iLM
  4432. // @return int Return Id of default iLM
  4433. static function default_ilm ($ilm_id) {
  4434. global $DB;
  4435. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4436. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4437. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4438. $iassign_ilm_default->id = $iassign_ilm->id;
  4439. $iassign_ilm_default->parent = 0;
  4440. $iassign_ilm->parent = $iassign_ilm_default->id;
  4441. $iassign_ilm->id = 0;
  4442. $iassign_ilm_default->enable = 1;
  4443. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4444. print_error('error_edit_ilm', 'iassign');
  4445. }
  4446. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4447. if (!$inserted) {
  4448. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4449. print_error($msg_error);
  4450. //xx print_error('error_add_ilm', 'iassign');
  4451. }
  4452. return $iassign_ilm_default->id;
  4453. } // static function default_ilm ($ilm_id)
  4454. /// Function for confirm delete iLM
  4455. // @param int $ilm_id Id of iLM
  4456. // @param int $ilm_parent Id of parent iLM
  4457. // @return string Return with an string for create delete page confirmation
  4458. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4459. global $OUTPUT, $DB;
  4460. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4461. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4462. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4463. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4464. }
  4465. /// Function for delete directory where the iLM is allocated.
  4466. // @param string $dirPath
  4467. // @throws InvalidArgumentException
  4468. public static function delete_dir ($dirPath) {
  4469. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4470. $dirPath .= '/';
  4471. }
  4472. $files = glob($dirPath . '*', GLOB_MARK);
  4473. foreach ($files as $file) {
  4474. if (is_dir($file)) {
  4475. ilm_settings::delete_dir($file);
  4476. } else {
  4477. unlink($file);
  4478. }
  4479. }
  4480. rmdir($dirPath);
  4481. }
  4482. /// Function for delete iLM
  4483. // @param int $ilm_id Id of iLM
  4484. // @return int Return Id of parent iLM
  4485. static function delete_ilm ($ilm_id) {
  4486. global $DB;
  4487. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4488. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4489. $typec = strtolower($iassign_ilm->type);
  4490. require_once 'ilm_handlers/' . $typec . '.php';
  4491. $retorno = $typec::delete_ilm($ilm_id);
  4492. return $retorno;
  4493. }
  4494. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4495. // @param int $ilm_id Id of iLM
  4496. static function export_ilm ($ilm_id) {
  4497. global $DB;
  4498. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4499. if (!$iassign_ilm) return; // security debug...
  4500. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4501. $typec = strtolower($iassign_ilm->type);
  4502. if (!$typec) $typec = "html5"; // security debug...
  4503. require_once 'ilm_handlers/' . $typec . '.php';
  4504. $typec::export_ilm($ilm_id);
  4505. } // static function export_ilm($ilm_id)
  4506. //TODO iLM_HTML5 :: //MOOC 2016
  4507. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4508. // @param int $ilm_id Id of iLM
  4509. static function export_update_ilm ($ilm_id) {
  4510. global $DB, $CFG;
  4511. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4512. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4513. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4514. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4515. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4516. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4517. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4518. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4519. $upgrade_descriptor .= '</upgrade>' . "\n";
  4520. file_put_contents($xml_filename, $upgrade_descriptor);
  4521. header("Pragma: public");
  4522. header("Expires: 0");
  4523. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4524. header("Cache-Control: private", false);
  4525. header('Content-Type: application/xml; charset=utf-8');
  4526. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4527. header("Content-Length: " . @filesize($xml_filename));
  4528. set_time_limit(0);
  4529. @readfile("$xml_filename") || die("File not found.");
  4530. unlink($xml_filename);
  4531. exit;
  4532. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4533. /// Function for save iLM from XML descriptor
  4534. // @param array $application_xml Data of XML descriptor
  4535. // @param array $files_extract Filenames of extract files
  4536. // @return array Return an array content id of JAR files
  4537. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4538. global $CFG, $USER;
  4539. // Tratamento diferenciado se for do tipo HTML5:
  4540. $source = "";
  4541. $diretorio = "";
  4542. if (strtolower($application_xml->type) == 'html5') {
  4543. $i = 0;
  4544. foreach ($files_extract as $key => $value) {
  4545. $file = $CFG->dataroot . '/temp/' . $key;
  4546. // Verifica se já existe a pasta no diretório dos iLM:
  4547. if ($i == 0) {
  4548. $source = $file;
  4549. if (file_exists("ilm/" . basename($file))) {
  4550. $j = 1;
  4551. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4552. $j ++;
  4553. }
  4554. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4555. // mkdir($diretorio, 0777, true);
  4556. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4557. }
  4558. else {
  4559. $diretorio = 'ilm/' . basename($file);
  4560. // mkdir($diretorio, 0777, true);
  4561. mkdir($diretorio, 0755, true);
  4562. }
  4563. break;
  4564. }
  4565. $i ++;
  4566. }
  4567. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4568. if ($item->isDir()) {
  4569. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4570. }
  4571. else {
  4572. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4573. }
  4574. }
  4575. ilm_settings::delete_dir($source);
  4576. return "./" . $diretorio;
  4577. }
  4578. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4579. $file_jar = array();
  4580. $files_ilm = explode(",", $application_xml->file_jar);
  4581. $contextsystem = context_system::instance();
  4582. foreach ($files_ilm as $value) {
  4583. $file_ilm = array(
  4584. 'userid' => $USER->id,
  4585. 'contextid' => $contextsystem->id,
  4586. 'component' => 'mod_iassign',
  4587. 'filearea' => 'ilm',
  4588. 'itemid' => rand(1, 999999999),
  4589. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4590. 'filename' => $value);
  4591. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4592. array_push($file_jar, $file_ilm->get_id());
  4593. }
  4594. foreach ($files_extract as $key => $value) {
  4595. $file = $CFG->dataroot . '/temp/' . $key;
  4596. if (file_exists($file))
  4597. unlink($file);
  4598. }
  4599. return $file_jar;
  4600. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4601. /// Function for import the iLM from an package
  4602. // @param int $itemid Itemid of zip file
  4603. static function import_ilm ($itemid) {
  4604. global $CFG, $USER, $OUTPUT;
  4605. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4606. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4607. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4608. }
  4609. $pathtemp = $CFG->dataroot . '/temp/';
  4610. $contextuser = context_user::instance($USER->id);
  4611. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4612. $zip = new zip_packer();
  4613. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4614. foreach ($files as $file) {
  4615. if (!$file->is_directory())
  4616. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4617. }
  4618. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4619. // Verifica se o pacote possui o XML
  4620. if (!$application_xml) {
  4621. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4622. return;
  4623. } else {
  4624. $missing = "";
  4625. if (!isset($application_xml->name)) {
  4626. $missing .= "name";
  4627. }
  4628. if (!isset($application_xml->version)) {
  4629. $missing .= ", version";
  4630. }
  4631. if (!isset($application_xml->type)) {
  4632. $missing .= ", type";
  4633. }
  4634. if (!isset($application_xml->extension)) {
  4635. $missing .= ", extension";
  4636. }
  4637. if (!isset($application_xml->file_jar)) {
  4638. $missing .= ", file_jar";
  4639. }
  4640. if (!isset($application_xml->file_class)) {
  4641. $missing .= ", file_class";
  4642. }
  4643. if (!isset($application_xml->width)) {
  4644. $missing .= ", width";
  4645. }
  4646. if (!isset($application_xml->height)) {
  4647. $missing .= ", height";
  4648. }
  4649. if (!isset($application_xml->evaluate)) {
  4650. $missing .= ", evaluate";
  4651. }
  4652. if (strlen($missing) > 2) {
  4653. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4654. return;
  4655. }
  4656. }
  4657. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4658. $typec = strtolower($application_xml->type);
  4659. require_once 'ilm_handlers/' . $typec . '.php';
  4660. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4661. } // static function import_ilm($itemid)
  4662. /// Function for list iLM defaults
  4663. // @return string Return an string with a table of iLM
  4664. static function list_ilm () {
  4665. global $DB, $OUTPUT;
  4666. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4667. $str = '';
  4668. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4669. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4670. if ($iassign_ilm) {
  4671. foreach ($iassign_ilm as $ilm) {
  4672. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4673. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4674. $str .= '<tr><td>';
  4675. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4676. $str .= '<tr>';
  4677. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4678. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4679. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4680. $str .= '</tr>';
  4681. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4682. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4683. $str .= '</table>';
  4684. $str .= '</td></tr>';
  4685. }
  4686. }
  4687. $str .= '</table>';
  4688. return $str;
  4689. }
  4690. /// Function for download and install an upgrade of an iLM
  4691. // @param int $ilm_id Id of iLM
  4692. static function upgrade_ilm ($ilm_id) {
  4693. global $DB, $CFG, $USER;
  4694. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4695. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4696. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4697. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4698. if (!$result)
  4699. print_error('error_upgrade_ilm', 'iassign');
  4700. else {
  4701. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4702. $extension = explode(".", $zip_filename);
  4703. if ($extension[count($extension) - 1] != 'ipz') {
  4704. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4705. die;
  4706. }
  4707. $zip = new zip_packer();
  4708. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4709. $contextuser = context_user::instance($USER->id);
  4710. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4711. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4712. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4713. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4714. if (file_exists($zip_filename))
  4715. unlink($zip_filename);
  4716. if (empty($file_jar)) {
  4717. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4718. print_error($msg_error);
  4719. //xx print_error('error_add_ilm', 'iassign');
  4720. }
  4721. else {
  4722. $newentry = new stdClass();
  4723. $newentry->name = (String) $application_xml->name;
  4724. $newentry->version = (String) $application_xml->version;
  4725. $newentry->url = (String) $application_xml->url;
  4726. $newentry->description = $description_str;
  4727. $newentry->extension = strtolower((String) $application_xml->extension);
  4728. $newentry->file_jar = implode(",", $file_jar);
  4729. $newentry->file_class = (String) $application_xml->file_class;
  4730. $newentry->width = (String) $application_xml->width;
  4731. $newentry->height = (String) $application_xml->height;
  4732. $newentry->enable = 0;
  4733. $newentry->timemodified = time();
  4734. $newentry->author = $USER->id;
  4735. $newentry->timecreated = time();
  4736. $newentry->evaluate = (String) $application_xml->evaluate;
  4737. $newentry->parent = $ilm_id;
  4738. }
  4739. }
  4740. return $iassign_ilm->id;
  4741. } // static function upgrade_ilm($ilm_id)
  4742. //MOOC2014 -- inicio
  4743. //TODO: REVIEW
  4744. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4745. // static function move_iassign($ilm_id)
  4746. //MOOC2014 -- final
  4747. /// Function for list iLM versions with all informations
  4748. // @return string Return an string with a table of iLM
  4749. static function view_ilm ($ilmid, $from) {
  4750. global $DB;
  4751. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4752. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4753. $typec = strtolower($iassign_ilm->type);
  4754. require_once 'ilm_handlers/' . $typec . '.php';
  4755. $retorno = $typec::view_ilm($ilmid, $from);
  4756. return $retorno;
  4757. }
  4758. /// Function for get form variables for add, edit, or copy iLM params
  4759. // @param int $ilm_param_id Id of iLM param
  4760. // @param string $action String with the action
  4761. // @return object Return an object with forms variables
  4762. static function add_edit_copy_param ($ilm_param_id, $action) {
  4763. global $DB;
  4764. require_once('params_form.php');
  4765. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4766. $param = new stdClass();
  4767. $param->action = $action;
  4768. $param->ilm_param_id = $ilm_param_id;
  4769. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4770. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4771. $type = $iassign_ilm_config->param_type;
  4772. if ($action == 'add') {
  4773. $param->title = get_string('add_ilm', 'iassign');
  4774. $param->iassign_ilmid = $ilm_param_id;
  4775. $param->param_name = "";
  4776. $param->param_value = "";
  4777. $param->description = "";
  4778. $param->visible = 1;
  4779. }
  4780. elseif ($action == 'edit') {
  4781. if ($iassign_ilm_config) {
  4782. $param->title = get_string('edit_ilm', 'iassign');
  4783. $param->id = $iassign_ilm_config->id;
  4784. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4785. $param->param_type = $type; //MOOC2014
  4786. $param->param_name = $iassign_ilm_config->param_name;
  4787. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4788. $param->param_value = $iassign_ilm_config->param_value;
  4789. else //MOOC2014
  4790. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4791. $param->param_value = $iassign_ilm_config->param_value;
  4792. $param->description = $iassign_ilm_config->description;
  4793. $param->visible = $iassign_ilm_config->visible;
  4794. }
  4795. }
  4796. elseif ($action == 'copy') {
  4797. if ($iassign_ilm_config) {
  4798. $param->title = get_string('copy_ilm', 'iassign');
  4799. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4800. $param->param_type = $type; //MOOC2014
  4801. $param->param_name = $iassign_ilm_config->param_name;
  4802. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4803. $param->param_value = $iassign_ilm_config->param_value;
  4804. else //MOOC2014
  4805. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4806. $param->description = $iassign_ilm_config->description;
  4807. $param->visible = $iassign_ilm_config->visible;
  4808. }
  4809. }
  4810. return $param;
  4811. } // static function add_edit_copy_param($ilm_param_id, $action)
  4812. /// Function for change visibility of iLM param
  4813. // @param int $ilm_param_id Id of iLM param
  4814. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4815. static function visible_param ($ilm_param_id, $status) {
  4816. global $DB, $CFG;
  4817. if ($status == 0)
  4818. $visible = 1;
  4819. else
  4820. $visible = 0;
  4821. $newentry = new stdClass();
  4822. $newentry->id = $ilm_param_id;
  4823. $newentry->visible = $visible;
  4824. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4825. error(get_string('error_edit_param', 'iassign'));
  4826. }
  4827. /// Function for save in database an new iLM param
  4828. // @param object $param An object with iLM params
  4829. static function add_param ($param) {
  4830. global $DB;
  4831. $newentry = new stdClass();
  4832. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4833. //MOOC2014 $newentry->param_name = $param->param_name;
  4834. $newentry->param_type = $param->param_type; //MOOC2014
  4835. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4836. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4837. $newentry->param_value = $param->param_value;
  4838. else //MOOC2014
  4839. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4840. $newentry->description = $param->description;
  4841. $newentry->visible = $param->visible;
  4842. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4843. if (!$newentry->id) {
  4844. print_error('error_add_param', 'iassign');
  4845. }
  4846. }
  4847. /// Function for save in database a iLM param edit
  4848. // @param object $param An object with iLM params
  4849. static function edit_param ($param) {
  4850. global $DB;
  4851. $updentry = new stdClass();
  4852. $updentry->id = $param->id;
  4853. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4854. $updentry->param_type = $param->param_type; //MOOC2014
  4855. // $updentry->param_name = $param->param_name;
  4856. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4857. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4858. $updentry->param_value = $param->param_value;
  4859. else //MOOC2014
  4860. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4861. $updentry->description = $param->description;
  4862. $updentry->visible = $param->visible;
  4863. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4864. error(get_string('error_edit_param', 'iassign'));
  4865. }
  4866. }
  4867. /// Function for save in database a iLM param copy
  4868. // @param object $param An object with iLM params
  4869. static function copy_param ($param) {
  4870. global $DB;
  4871. $newentry = new stdClass();
  4872. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4873. //$newentry->param_name = $param->param_name;
  4874. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4875. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4876. $newentry->param_value = $param->param_value;
  4877. else //MOOC2014
  4878. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4879. $newentry->description = $param->description;
  4880. $newentry->visible = $param->visible;
  4881. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4882. if (!$newentry->id) {
  4883. print_error('error_add_param', 'iassign');
  4884. }
  4885. }
  4886. /// Function for delete iLM param of database
  4887. // @param int $param_id Id of iLM param
  4888. static function delete_param ($param_id) {
  4889. global $DB;
  4890. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4891. print_error('error_delete_param', 'iassign');
  4892. }
  4893. }
  4894. } // class ilm_settings
  4895. /// Class for manage iLM files (editor).
  4896. class ilm_manager {
  4897. var $id; // course id
  4898. var $url;
  4899. var $from;
  4900. /// Constructor for the base ilm_manager class
  4901. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4902. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4903. function __construct ($id, $url, $from) {
  4904. $this->id = $id; // course id
  4905. $this->url = $url;
  4906. $this->from = $from;
  4907. }
  4908. /// Function to get iAssign content file in Moodle data (exercise)
  4909. // @calledby x function preview_ilm($iassign_ilm) :
  4910. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4911. function get_file_ilm () {
  4912. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4913. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4914. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4915. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4916. $md_file = $fs->get_file_by_id($fileid);
  4917. $ilm_content_file = $md_file->get_content();
  4918. return $ilm_content_file;
  4919. }
  4920. /// Function for creating a new file from the iLM online editor
  4921. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4922. function ilm_editor_new () {
  4923. global $CFG, $DB, $OUTPUT, $PAGE;
  4924. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4925. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4926. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4927. $context = context_course::instance($this->id);
  4928. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4929. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4930. if (!$iassign) {
  4931. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4932. die();
  4933. }
  4934. $temp = explode(",", $iassign->extension);
  4935. $extension = $temp[0]; // default extension for this iLM
  4936. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4937. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4938. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4939. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4940. if ($stringArchiveContent != NULL) {
  4941. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4942. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4943. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4944. $filename = optional_param('filename', NULL, PARAM_RAW);
  4945. //Leo $filename = iassign_utils::format_filename($filename); //
  4946. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4947. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4948. //2019/02 $arrayfilename = explode(".", $filename);
  4949. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4950. //2019/02 $count_dots = count($arrayfilename);
  4951. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4952. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4953. //2019/02 if ($last_name != $extension)
  4954. //2019/02 $filename = $filename . '.' . $extension;
  4955. //2019/02 }
  4956. //2019/02 else { // no extension...
  4957. //2019/02 $filename = $filename . '.' . $extension;
  4958. //2019/02 }
  4959. // Store the name of recent created file
  4960. $_SESSION['file_name'] = $filename;
  4961. //$this->write_file_iassign($string, $filename);
  4962. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4963. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4964. die();
  4965. }
  4966. else { // if ($stringArchiveContent != NULL)
  4967. // iLM On-line editor
  4968. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4969. $str_get_iLM = "window.frames.iLM";
  4970. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4971. }
  4972. else { // otherwise it is JAR named 'iLM'
  4973. $str_get_iLM = "document.iLM";
  4974. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4975. }
  4976. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4977. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4978. $files_array = '';
  4979. foreach ($files as $value) {
  4980. if ($value->get_filename() != ".")
  4981. $files_array .= "'" . $value->get_filename() . "',";
  4982. }
  4983. $files_array .= "''";
  4984. $file = null;
  4985. $ia_content = "";
  4986. $filename = "";
  4987. $error_files_exists = get_string('error_file_exists', 'iassign');
  4988. $output = "<script type='text/javascript'>
  4989. //<![CDATA[
  4990. //D alert('locallib.php: ilm_editor_new');
  4991. function submit_iLM_Answer () {
  4992. var docFormOnLineEditor = document.formEnvio;
  4993. var resposta_exerc = new Array(3);
  4994. var valor_resposta = new Array(3);
  4995. var sessao = new Array(3);
  4996. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4997. resposta_exerc[0] = doc_iLM.getAnswer();
  4998. valor_resposta[0] = doc_iLM.getEvaluation();
  4999. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5000. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5001. var files = new Array(" . $files_array . ");
  5002. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5003. if (docFormOnLineEditor.filename.value=='') {
  5004. // ERROR: the file name is empty
  5005. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5006. return false;
  5007. }
  5008. // }
  5009. for (i=0; i<files.length; i++) {
  5010. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5011. alert('" . $error_files_exists . "');
  5012. return false;
  5013. }
  5014. }
  5015. docFormOnLineEditor.submit();
  5016. return true;
  5017. }
  5018. //]]>
  5019. </script>\n";
  5020. $output .= "
  5021. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5022. $output .= $OUTPUT->box_start();
  5023. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5024. $output .= "
  5025. <table width='100%' cellpadding='20'>
  5026. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5027. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5028. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5029. </tr>
  5030. </table>\n";
  5031. $output .= $OUTPUT->box_end();
  5032. $output .= "<center>\n";
  5033. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5034. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5035. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5036. $output .= $output_ilm;
  5037. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5038. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5039. </center>
  5040. </form>\n";
  5041. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5042. $PAGE->navbar->add($title);
  5043. $PAGE->set_title($title);
  5044. $PAGE->set_heading($title); // insert title above the navigation bar
  5045. print $OUTPUT->header();
  5046. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5047. print $output;
  5048. print $OUTPUT->footer();
  5049. }
  5050. die();
  5051. } // function ilm_editor_new()
  5052. /// Function for editing an file in online editor
  5053. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5054. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5055. global $CFG, $DB, $OUTPUT, $PAGE;
  5056. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5057. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5058. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5059. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5060. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5061. // If iLM is not registered, error!
  5062. if (!$iassign) {
  5063. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5064. die;
  5065. }
  5066. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5067. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5068. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5069. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5070. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5071. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5072. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5073. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5074. if ($stringArchiveContent != NULL) {
  5075. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5076. die();
  5077. } else { // if ($stringArchiveContent != NULL)
  5078. $end_file = '';
  5079. if ($content_file) {
  5080. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5081. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5082. }
  5083. $temp = explode(",", $iassign->extension);
  5084. $extension = $temp[0]; // default extension for this iLM
  5085. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5086. $str_get_iLM = "window.frames.iLM";
  5087. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5088. } else { // otherwise it is JAR named 'iLM'
  5089. $str_get_iLM = "document.iLM";
  5090. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5091. }
  5092. $output = "<script type='text/javascript'>
  5093. //<![CDATA[
  5094. function submit_iLM_Answer () {
  5095. var docFormEditor = document.formEnvio;
  5096. var activityAnswer; // to get activity answer (text)
  5097. var activityValue; // to get activity answer value (float)
  5098. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5099. //activityAnswer = doc_iLM.getAnswer();
  5100. //activityValue = doc_iLM.getEvaluation();
  5101. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5102. activityValue = " . $str_get_iLM . ".getEvaluation();
  5103. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5104. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5105. docFormEditor.submit();
  5106. return true;
  5107. }
  5108. //]]>
  5109. </script>\n";
  5110. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5111. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5112. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5113. // return true;
  5114. // }
  5115. $output .= "
  5116. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5117. $output .= $OUTPUT->box_start();
  5118. $output .= "
  5119. <table width='100%' cellpadding='20'>
  5120. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5121. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5122. <input type='hidden' name='filename' value='$filename'/></td>
  5123. <td>
  5124. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5125. </tr>
  5126. </table>\n";
  5127. $output .= $OUTPUT->box_end();
  5128. $output .= " <center>\n";
  5129. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5130. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5131. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5132. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5133. </center>
  5134. </form>\n";
  5135. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5136. $PAGE->navbar->add($title);
  5137. $PAGE->set_title($title);
  5138. $PAGE->set_heading($title); // insert title above the navigation bar
  5139. print $OUTPUT->header();
  5140. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5141. print $output;
  5142. print $OUTPUT->footer();
  5143. } // else if ($stringArchiveContent != NULL)
  5144. die();
  5145. } // function ilm_editor_update()
  5146. /// Function for write iAssign file in Moodle data (exercise)
  5147. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5148. // @param string $stringArchiveContent Content of iassign file
  5149. // @param string $filename Filename of iassign file
  5150. function write_file_iassign ($stringArchiveContent, $filename) {
  5151. global $USER;
  5152. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5153. $context = context_course::instance($this->id);
  5154. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5155. $dirid = $this->get_dir_ilm('dirid');
  5156. $dir = $fs->get_file_by_id($dirid);
  5157. $fileinfo = array('contextid' => $context->id, // ID of course
  5158. 'component' => 'mod_iassign', // usually = table name
  5159. 'filearea' => 'activity', // usually = table name
  5160. 'itemid' => 0, // usually = ID of row in table
  5161. 'filepath' => '/', // any path beginning and ending whith '/'
  5162. 'userid' => $USER->id,
  5163. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5164. 'filename' => $filename); // any filename
  5165. // Create file containing text. '$stringArchiveContent'
  5166. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5167. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5168. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5169. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5170. // 'Activité interactive enregistrée avec succès sous le nom:';
  5171. // 'Atividade interativa gravada com sucesso sob o nome:'
  5172. $output = "
  5173. <script type='text/javascript'>
  5174. //<![CDATA[
  5175. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5176. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5177. //]]>
  5178. </script>";
  5179. print $output;
  5180. die();
  5181. }
  5182. /// Function for write iAssign file in Moodle data (exercise)
  5183. // @param string $stringArchiveContent Content of iassign file
  5184. // @param string $filename Filename of iassign file
  5185. // @param int $itemid Itemid of iassign file
  5186. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5187. global $OUTPUT, $USER;
  5188. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5189. $context = context_course::instance($this->id);
  5190. $dirid = $this->get_dir_ilm('dirid');
  5191. if ($stringArchiveContent != (-1)) {
  5192. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5193. $file = $fs->get_file_by_id($fileid);
  5194. if (!$file) {
  5195. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5196. die;
  5197. }
  5198. $fileinfo = array('contextid' => $context->id, // ID of context
  5199. 'component' => 'mod_iassign', // usually = table name
  5200. 'filearea' => 'activity', // usually = table name
  5201. 'itemid' => 0, // usually = ID of row in table
  5202. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5203. 'userid' => $USER->id,
  5204. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5205. 'license' => 'allrightsreserved', // allrightsreserved
  5206. 'timecreated' => $file->get_timecreated(),
  5207. 'filename' => $file->get_filename()); // any filename
  5208. $file->delete();
  5209. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5210. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5211. }
  5212. $output = "<script type='text/javascript'>
  5213. //<![CDATA[
  5214. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5215. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5216. //]]>
  5217. </script>";
  5218. print $output;
  5219. die();
  5220. }
  5221. /// Function for create an tag for iAssign filter
  5222. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5223. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5224. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5225. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5226. // @param int $fileid Id of file
  5227. // @return string Return an string with an tag of iassign filter
  5228. function tag_ilm ($fileid) {
  5229. global $DB;
  5230. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5231. $width = '600';
  5232. $height = '400';
  5233. $file = $fs->get_file_by_id($fileid);
  5234. $filetype = explode(".", $file->get_filename());
  5235. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5236. foreach ($iassign_ilm as $value) {
  5237. $extensions = explode(",", $value->extension);
  5238. if (in_array($filetype[1], $extensions)) {
  5239. $width = $value->width;
  5240. $height = $value->height;
  5241. }
  5242. }
  5243. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5244. }
  5245. /// Function for delete iAssign file in Moodle data (exercise)
  5246. function delete_file_ilm () {
  5247. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5248. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5249. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5250. $file = $fs->get_file_by_id($fileid);
  5251. if ($file)
  5252. $file->delete();
  5253. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5254. die();
  5255. }
  5256. /// Function for delete selected iAssign file in Moodle data (exercise)
  5257. function delete_selected_ilm () {
  5258. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5259. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5260. $context = context_course::instance($this->id);
  5261. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5262. $dirid = $this->get_dir_ilm('dirid');
  5263. foreach ($files_id as $file_id) {
  5264. $file = $fs->get_file_by_id($file_id);
  5265. if ($file) {
  5266. if (!$file->is_directory())
  5267. $file->delete();
  5268. else {
  5269. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5270. foreach ($files_delete as $value)
  5271. $value->delete();
  5272. $file->delete();
  5273. }
  5274. }
  5275. }
  5276. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5277. die();
  5278. }
  5279. /// Function for duplicate iAssign file from "online" edition
  5280. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5281. function duplicate_file_ilm () {
  5282. global $USER, $COURSE;
  5283. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5284. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5285. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5286. $filename = optional_param('filename', NULL, PARAM_RAW);
  5287. $file = $fs->get_file_by_id($fileid);
  5288. $context = context_course::instance($this->id);
  5289. $fileinfo = array(
  5290. 'contextid' => $context->id, // ID of context
  5291. 'component' => 'mod_iassign', // usually = table name
  5292. 'filearea' => 'activity', // usually = table name
  5293. 'itemid' => 0, // usually = ID of row in table
  5294. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5295. 'userid' => $USER->id,
  5296. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5297. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5298. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5299. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5300. die();
  5301. }
  5302. /// Function for rename iAssign file
  5303. function rename_file_ilm () {
  5304. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5305. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5306. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5307. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5308. $file = $fs->get_file_by_id($fileid);
  5309. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5310. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5311. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5312. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5313. die();
  5314. }
  5315. /// Function for get iassign file for iassign form
  5316. function add_ilm () {
  5317. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5318. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5319. $output = "
  5320. <script type='text/javascript'>
  5321. //<![CDATA[
  5322. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5323. iassign_file_link.innerHTML = '$filename';
  5324. window.opener.document.forms['mform1'].file.value='$fileid';
  5325. window.opener.document.forms['mform1'].filename.value='$filename';
  5326. window.close();
  5327. //]]>
  5328. </script>";
  5329. print $output;
  5330. die();
  5331. }
  5332. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5333. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5334. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5335. function preview_ilm ($courseid, $iassign_ilm) {
  5336. global $OUTPUT, $CFG, $USER;
  5337. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5338. $title = get_string('modulename', 'iassign'); // iAssign
  5339. print $OUTPUT->header();
  5340. print $OUTPUT->box_start();
  5341. $javascript = "
  5342. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5343. <script type='text/javascript'>
  5344. //<![CDATA[
  5345. function submit_close () {
  5346. window.opener.location.reload();
  5347. window.close();
  5348. }
  5349. //]]>
  5350. </script>\n";
  5351. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5352. // to the complete "applet" tag
  5353. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5354. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5355. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5356. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5357. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5358. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5359. if ($ilm_name != "ivprog") {
  5360. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5361. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5362. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5363. } else {
  5364. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5365. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5366. $timecreated = time();
  5367. $token = md5($timecreated);
  5368. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5369. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5370. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5371. $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)
  5372. }
  5373. $html = "
  5374. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5375. <table border='1'>
  5376. <tr><td>
  5377. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5378. <!-- iLM calls : end -->
  5379. </td></tr>
  5380. </table>
  5381. <table>
  5382. <tr>
  5383. <td align='center'>
  5384. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5385. </td></tr>
  5386. </table>
  5387. </form>\n";
  5388. print $javascript . $html;
  5389. print $OUTPUT->box_end();
  5390. //NAO echo format_string($html); // Moodle 3.X
  5391. die();
  5392. } // function preview_ilm($courseid, $iassign_ilm)
  5393. //r_ function preview_ilm ($iassign_ilm)
  5394. //r_ /// Function for preview iassign file from iassign filter.
  5395. //r_ function preview_ilm() {
  5396. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5397. //r_ $tag_filter = $this->tag_ilm($fileid);
  5398. //r_ $javascript = "<script type='text/javascript'>
  5399. //r_ //<![CDATA[
  5400. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5401. //r_ //]]>
  5402. //r_ </script>";
  5403. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5404. //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>
  5405. //r_ </table></form></body></html>";
  5406. //r_ echo $javascript . format_text($html);
  5407. //r_ die;
  5408. //r_ }
  5409. /// Function for export an package (zip) of iassign files
  5410. function export_files_ilm () {
  5411. global $CFG;
  5412. $context = context_course::instance($this->id);
  5413. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5414. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5415. $zip = new zip_archive();
  5416. $zip->open($zip_filename);
  5417. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5418. foreach ($files_id as $file_id) {
  5419. $file = $fs->get_file_by_id($file_id);
  5420. if (!$file->is_directory())
  5421. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5422. else {
  5423. $zip->add_directory($file->get_filepath());
  5424. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5425. foreach ($files_zip as $value) {
  5426. if (!$value->is_directory())
  5427. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5428. else
  5429. $zip->add_directory($value->get_filepath());
  5430. }
  5431. }
  5432. }
  5433. $zip->close();
  5434. header("Pragma: public");
  5435. header("Expires: 0");
  5436. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5437. header("Cache-Control: private", false);
  5438. header("Content-Type: application/zip");
  5439. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5440. header("Content-Transfer-Encoding: binary");
  5441. header("Content-Length: " . @filesize($zip_filename));
  5442. set_time_limit(0);
  5443. @readfile("$zip_filename") || die("File not found.");
  5444. unlink($zip_filename);
  5445. exit;
  5446. }
  5447. /// Function of execute a command in button editor tinymce
  5448. // @param int $fileid Id of file
  5449. function tinymce_ilm ($fileid) {
  5450. $tag_filter = $this->tag_ilm($fileid);
  5451. $output = "<script type='text/javascript'>
  5452. //<![CDATA[
  5453. var tag_filter = '$tag_filter';
  5454. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5455. // all right, insert it
  5456. } else {
  5457. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5458. }
  5459. // window.close();
  5460. //]]>
  5461. </script>\n";
  5462. print $output;
  5463. die();
  5464. }
  5465. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5466. /// Function to add content to the Editor Window
  5467. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5468. // @param int $fileid Id of file
  5469. function editor_ilm ($fileid, $editor) {
  5470. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5471. $output1 = "<script type='text/javascript'>
  5472. //<![CDATA[
  5473. var tag_filter = '$tag_filter';\n";
  5474. if ($editor == 'atto') {
  5475. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5476. } elseif ($editor == 'tinyMCE') {
  5477. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5478. } else
  5479. $output2 = "";
  5480. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5481. window.close();
  5482. //]]>
  5483. </script>\n";
  5484. //D var_dump($output);
  5485. print $output1 . $output2 . $output3;
  5486. die();
  5487. }
  5488. /// Function to add content to the Atto Editor Window
  5489. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5490. // @param int $fileid Id of file
  5491. function atto_ilm ($fileid) {
  5492. global $CFG, $DB;
  5493. $tag_filter = $this->tag_ilm($fileid);
  5494. $output = "<script type='text/javascript'>
  5495. //<![CDATA[
  5496. var tag_filter = '$tag_filter';
  5497. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5498. // all right, insert iLM tag to this editor
  5499. } else {
  5500. // error trying to insert
  5501. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5502. }
  5503. //window.close();
  5504. //]]>
  5505. </script>\n";
  5506. print $output;
  5507. die();
  5508. }
  5509. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5510. // @param string $key Key for return information
  5511. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5512. function get_dir_ilm ($key) {
  5513. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5514. $context = context_course::instance($this->id);
  5515. $dirid = optional_param('dirid', 0, PARAM_INT);
  5516. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5517. if ($dirid == 0) {
  5518. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5519. $dirid = $dir->get_id();
  5520. }
  5521. else {
  5522. $dir = $fs->get_file_by_id($dirid);
  5523. $dir_base = $dir->get_filepath();
  5524. }
  5525. $dir_parent = $dir->get_parent_directory();
  5526. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5527. return $data[$key];
  5528. }
  5529. /// Function for create an new dir
  5530. function new_dir_ilm () {
  5531. global $USER;
  5532. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5533. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5534. $dir_base = $this->get_dir_ilm('dir_base');
  5535. $context = context_course::instance($this->id);
  5536. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5537. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5538. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5539. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5540. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5541. }
  5542. /// Function for delete an dir
  5543. function delete_dir_ilm () { //
  5544. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5545. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5546. $context = context_course::instance($this->id);
  5547. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5548. $dir_parent = $this->get_dir_ilm('dir_parent');
  5549. if ($dir) {
  5550. if ($dir->is_directory()) {
  5551. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5552. foreach ($files_delete as $value)
  5553. $value->delete();
  5554. $dir->delete();
  5555. }
  5556. }
  5557. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5558. die();
  5559. }
  5560. /// Function for rename an dir
  5561. function rename_dir_ilm () {
  5562. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5563. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5564. $context = context_course::instance($this->id);
  5565. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5566. $dir_parent = $this->get_dir_ilm('dir_parent');
  5567. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5568. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5569. if ($dir->is_directory()) {
  5570. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5571. foreach ($files_rename_path as $value)
  5572. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5573. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5574. }
  5575. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5576. die();
  5577. }
  5578. /// Function for move an dir and your content for other dir
  5579. function selected_move_ilm () {
  5580. global $PAGE, $OUTPUT, $CFG;
  5581. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5582. $context = context_course::instance($this->id);
  5583. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5584. $dirid = $this->get_dir_ilm('dirid');
  5585. $dir_base = $this->get_dir_ilm('dir_base');
  5586. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5587. $code_javascript_ilm = "
  5588. <script type='text/javascript'>
  5589. //<![CDATA[
  5590. function getRadiobutton () {
  5591. var radioButtons = document.getElementsByTagName('input');
  5592. var param = '';
  5593. for (var counter=0; counter < radioButtons.length; counter++) {
  5594. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5595. param = radioButtons[counter].value;
  5596. }
  5597. return param;
  5598. }
  5599. function move_selected_ilm () {
  5600. var msgAnswer;
  5601. if (getRadiobutton() != '') {
  5602. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5603. if (msgAnswer)
  5604. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5605. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5606. }
  5607. else
  5608. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5609. }
  5610. function cancel_selected_ilm () {
  5611. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5612. }
  5613. //]]>
  5614. </script>\n";
  5615. $title = get_string('move_files', 'iassign');
  5616. $PAGE->set_title($title);
  5617. $PAGE->set_pagelayout('base');
  5618. print $OUTPUT->header();
  5619. print $OUTPUT->heading($title);
  5620. $dir_paths = array();
  5621. print $OUTPUT->box_start();
  5622. print "<center>";
  5623. foreach ($files_id as $file_id) {
  5624. $file = $fs->get_file_by_id($file_id);
  5625. if ($file) {
  5626. if (!$file->is_directory())
  5627. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5628. else {
  5629. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5630. array_push($dir_paths, $file->get_filepath());
  5631. }
  5632. }
  5633. }
  5634. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5635. if ($dir_base != '/') {
  5636. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5637. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5638. }
  5639. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5640. foreach ($files_tree as $file) {
  5641. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5642. $is_parent = false;
  5643. foreach ($dir_paths as $dir) {
  5644. $path = explode("/", $dir);
  5645. array_pop($path);
  5646. $path[count($path) - 1] = '';
  5647. $path = implode("/", $path);
  5648. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5649. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5650. }
  5651. if ($is_parent == false) {
  5652. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5653. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5654. }
  5655. }
  5656. }
  5657. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5658. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5659. print "</center>";
  5660. print $OUTPUT->box_end();
  5661. print $OUTPUT->footer();
  5662. print $code_javascript_ilm;
  5663. die;
  5664. }
  5665. /// Function for move files for an dir
  5666. function move_files_ilm () {
  5667. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5668. $context = context_course::instance($this->id);
  5669. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5670. $dirid = $this->get_dir_ilm('dirid');
  5671. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5672. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5673. foreach ($files_id as $file_id) {
  5674. $file = $fs->get_file_by_id($file_id);
  5675. if ($file) {
  5676. if ($file->is_directory()) {
  5677. $pathname = explode("/", $file->get_filepath());
  5678. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5679. foreach ($files_move_path as $value) {
  5680. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5681. $value->rename($path_move, $value->get_filename());
  5682. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5683. }
  5684. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5685. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5686. $file->rename($path_move, $file->get_filename());
  5687. } else {
  5688. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5689. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5690. }
  5691. }
  5692. }
  5693. //die;
  5694. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5695. die();
  5696. } // function move_files_ilm()
  5697. /// Function for recover files in use on all activities of a course
  5698. function recover_files_ilm () {
  5699. global $DB, $USER;
  5700. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5701. $courseid = optional_param('id', NULL, PARAM_INT);
  5702. $dirid = $this->get_dir_ilm('dirid');
  5703. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5704. $contextfile = context_course::instance($this->id);
  5705. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5706. foreach ($iassigns as $iassign) {
  5707. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5708. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5709. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5710. $context = context_module::instance($cm->id);
  5711. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5712. if ($files) {
  5713. foreach ($files as $value) {
  5714. $extension = explode(".", $value->get_filename());
  5715. if (!$value->is_directory()) {
  5716. $fileinfo = array('contextid' => $contextfile->id,
  5717. 'component' => 'mod_iassign',
  5718. 'filearea' => 'activity',
  5719. 'itemid' => 0,
  5720. 'filepath' => $this->get_dir_ilm('dir_base'),
  5721. 'userid' => $USER->id,
  5722. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5723. 'license' => 'allrightsreserved',
  5724. 'timecreated' => time(),
  5725. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5726. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5727. }
  5728. }
  5729. } // if ($files)
  5730. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5731. } // foreach ($iassigns as $iassign)
  5732. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5733. die();
  5734. } // function recover_files_ilm()
  5735. /// Auxiliary function the get all files in a given context
  5736. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5737. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5738. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5739. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5740. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5741. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5742. // (NAO s_iassign_statement.file = s_files.id)
  5743. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5744. $dir_base = $this->get_dir_ilm('dir_base');
  5745. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5746. $countf = 0;
  5747. $array_files_id = array(); // all files from this context
  5748. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5749. //$filename = $item_fc->get_filename();
  5750. //$filepath = $item_fc->get_filepath();
  5751. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5752. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5753. // $array_files_aux[] = $item_fc;
  5754. $itemid = $item_fc->get_id();
  5755. if (!in_array($itemid, $array_files_id)) {
  5756. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5757. if ($fileuserid == $userid)
  5758. $filesfrommine[] = $item_fc;
  5759. else
  5760. $filesfromothers[] = $item_fc;
  5761. $array_files_id[] = $itemid;
  5762. $countf++;
  5763. }
  5764. }
  5765. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5766. return $countf;
  5767. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5768. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5769. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5770. function get_all_ilm_files_by_fileid ($fileid) {
  5771. global $DB, $USER;
  5772. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5773. //TODO Criar coluna 'authorid'
  5774. $str_query = "SELECT * FROM {iassign_statement} " .
  5775. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5776. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5777. return $array_iassign_ilm;
  5778. }
  5779. //NN
  5780. //NN
  5781. // Build string with JavaScript code with function to edit/remove/double iLM files
  5782. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5783. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5784. global $CFG;
  5785. $error_files_exists = get_string('error_file_exists', 'iassign');
  5786. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5787. $code_javascript_ilm = "
  5788. <script type='text/javascript'>
  5789. //<![CDATA[
  5790. function preview_ilm (fileid, ilmid) { //JavaScript function
  5791. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5792. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5793. }
  5794. function update_ilm (ilmid, fileid) { //JavaScript function
  5795. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5796. }
  5797. function delete_ilm (ilmid, fileid) { //JavaScript function
  5798. var msgAnswer;
  5799. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5800. if (msgAnswer) {
  5801. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5802. }
  5803. }
  5804. function delete_selected_ilm () { //JavaScript function
  5805. var msgAnswer;
  5806. var param = getCheckbox();
  5807. if (param.join() != '') {
  5808. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5809. if (msgAnswer)
  5810. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5811. }
  5812. else
  5813. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5814. }
  5815. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5816. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5817. }
  5818. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5819. var filenamecopy;
  5820. var i;
  5821. var files = new Array(" . $files_array . ");
  5822. do {
  5823. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5824. } while (filenamecopy == '');
  5825. if (filenamecopy == null)
  5826. return false;\n
  5827. else {
  5828. for (i=0;i<files.length;i++) {
  5829. if (files[i]==filenamecopy) {
  5830. alert('" . $error_files_exists . "');
  5831. return false;\n
  5832. }
  5833. }\n" .
  5834. // @see: function 'duplicate_file_ilm()' above
  5835. "
  5836. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5837. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5838. } // else
  5839. }
  5840. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5841. var filenamecopy;
  5842. var i;
  5843. var files = new Array($files_array);
  5844. do {
  5845. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5846. } while (filenamecopy == '');
  5847. if (filenamecopy == null)
  5848. return false;
  5849. else {
  5850. for (i=0;i<files.length;i++) {
  5851. if (files[i]==filenamecopy) {
  5852. alert('" . $error_files_exists . "');
  5853. return false;
  5854. }
  5855. }
  5856. 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;
  5857. }
  5858. }
  5859. function export_files_ilm () { //JavaScript function
  5860. var param = getCheckbox();
  5861. if (param.join() != '')
  5862. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5863. else
  5864. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5865. }
  5866. function select_all_ilm () { //JavaScript function
  5867. var checkBoxes = document.getElementsByTagName('input');
  5868. var selectAll = document.getElementById('select_all');
  5869. for (var counter=0; counter < checkBoxes.length; counter++) {
  5870. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5871. checkBoxes[counter].checked = selectAll.checked;
  5872. }
  5873. }
  5874. function getCheckbox () { //JavaScript function
  5875. var checkBoxes = document.getElementsByTagName('input');
  5876. var param = new Array();
  5877. for (var counter=0; counter < checkBoxes.length; counter++) {
  5878. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5879. param.push(checkBoxes[counter].value);
  5880. }
  5881. return param;
  5882. }
  5883. function new_dir_ilm () { //JavaScript function
  5884. var dirname = '';
  5885. var i;
  5886. var dirs = new Array(" . $dirs_array . ");
  5887. do {
  5888. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5889. } while (dirname == '');
  5890. if (dirname == null)
  5891. return false;\n
  5892. else {
  5893. for (i=0;i<dirs.length;i++) {
  5894. if (dirs[i]==dirname) {
  5895. alert('" . $error_dir_exists . "');
  5896. return false;\n
  5897. }
  5898. }
  5899. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5900. }
  5901. }
  5902. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5903. var msgAnswer;
  5904. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5905. if (msgAnswer) {
  5906. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5907. }
  5908. }
  5909. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5910. var dirnamecopy;
  5911. var i;
  5912. var dirs = new Array($dirs_array);
  5913. do {
  5914. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5915. } while (dirnamecopy == '');
  5916. if (dirnamecopy == null)
  5917. return false;\n
  5918. else {
  5919. for (i=0;i<dirs.length;i++) {
  5920. if (dirs[i]==dirnamecopy) {
  5921. alert('" . $error_dir_exists . "');
  5922. return false;\n
  5923. }
  5924. }
  5925. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5926. }
  5927. }
  5928. function move_selected_ilm (ilmid) { //JavaScript function
  5929. var param = getCheckbox();
  5930. if (param.join() != '')
  5931. 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();
  5932. else
  5933. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5934. }
  5935. function recover_files_ilm () { //JavaScript function
  5936. var msgAnswer;
  5937. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5938. if (msgAnswer) {
  5939. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5940. }
  5941. }
  5942. window.onload = function() { //JavaScript function
  5943. var xPosition = 0;
  5944. var yPosition = 0;
  5945. element=document.getElementById('new_file');
  5946. while(element) {
  5947. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5948. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5949. element = element.offsetParent;
  5950. }
  5951. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5952. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5953. location.hash = '#new_file';
  5954. };
  5955. //]]>
  5956. </script>\n"; // end of $code_javascript_ilm
  5957. return $code_javascript_ilm;
  5958. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5959. /// List iassign files from course directory
  5960. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5961. function view_files_ilm ($iassign_ilm_class, $extension) {
  5962. global $CFG, $DB, $USER, $OUTPUT;
  5963. $fs = get_file_storage();
  5964. $context = context_course::instance($this->id);
  5965. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5966. $dirid = $this->get_dir_ilm('dirid');
  5967. $dir_base = $this->get_dir_ilm('dir_base');
  5968. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5969. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  5970. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  5971. $files_array = '';
  5972. foreach ($files_course as $value) {
  5973. if (!$value->is_directory())
  5974. $files_array .= "'" . $value->get_filename() . "',";
  5975. }
  5976. $files_array .= "''";
  5977. $error_files_exists = get_string('error_file_exists', 'iassign');
  5978. $dirs_array = '';
  5979. foreach ($files_course as $value) {
  5980. if ($value->is_directory()) {
  5981. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5982. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5983. }
  5984. }
  5985. $dirs_array .= "''";
  5986. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5987. // TODO Rever o preview pois só deixar ver uma vez.
  5988. $code_javascript_ilm = "
  5989. <script type='text/javascript'>
  5990. //<![CDATA[
  5991. function preview_ilm (fileid, ilmid) {
  5992. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5993. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5994. }
  5995. function update_ilm (ilmid, fileid) {
  5996. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5997. }
  5998. function delete_ilm (ilmid, fileid) {
  5999. var msgAnswer;
  6000. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6001. if (msgAnswer) {
  6002. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6003. }
  6004. }
  6005. function delete_selected_ilm () {
  6006. var msgAnswer;
  6007. var param = getCheckbox();
  6008. if (param.join() != '') {
  6009. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6010. if (msgAnswer)
  6011. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6012. }
  6013. else
  6014. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6015. }
  6016. function add_ilm_iassign (ilmid, filename, fileid) {
  6017. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6018. }
  6019. function duplicate_ilm (ilmid, filename, fileid) {
  6020. var filenamecopy;
  6021. var i;
  6022. var files = new Array($files_array);
  6023. do {
  6024. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6025. } while (filenamecopy == '');
  6026. if (filenamecopy == null)
  6027. return false;\n
  6028. else {
  6029. for (i=0;i<files.length;i++) {
  6030. if (files[i]==filenamecopy) {
  6031. alert('$error_files_exists');
  6032. return false;\n
  6033. }
  6034. }\n" .
  6035. // @see: function 'duplicate_file_ilm()' above
  6036. "
  6037. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6038. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6039. } // else
  6040. }
  6041. function rename_ilm (ilmid, filename, fileid) {
  6042. var filenamecopy;
  6043. var i;
  6044. var files = new Array($files_array);
  6045. do {
  6046. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6047. } while (filenamecopy == '');
  6048. if (filenamecopy == null)
  6049. return false;
  6050. else {
  6051. for (i=0;i<files.length;i++) {
  6052. if (files[i]==filenamecopy) {
  6053. alert('$error_files_exists');
  6054. return false;
  6055. }
  6056. }
  6057. 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;
  6058. }
  6059. }
  6060. function export_files_ilm () {
  6061. var param = getCheckbox();
  6062. if (param.join() != '')
  6063. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6064. else
  6065. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6066. }
  6067. function select_all_ilm () {
  6068. var checkBoxes = document.getElementsByTagName('input');
  6069. var selectAll = document.getElementById('select_all');
  6070. for (var counter=0; counter < checkBoxes.length; counter++) {
  6071. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6072. checkBoxes[counter].checked = selectAll.checked;
  6073. }
  6074. }
  6075. function getCheckbox () {
  6076. var checkBoxes = document.getElementsByTagName('input');
  6077. var param = new Array();
  6078. for (var counter=0; counter < checkBoxes.length; counter++) {
  6079. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6080. param.push(checkBoxes[counter].value);
  6081. }
  6082. return param;
  6083. }
  6084. function new_dir_ilm () {
  6085. var dirname = '';
  6086. var i;
  6087. var dirs = new Array($dirs_array);
  6088. do {
  6089. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6090. } while (dirname == '');
  6091. if (dirname == null)
  6092. return false;\n
  6093. else {
  6094. for (i=0;i<dirs.length;i++) {
  6095. if (dirs[i]==dirname) {
  6096. alert('$error_dir_exists');
  6097. return false;\n
  6098. }
  6099. }
  6100. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6101. }
  6102. }
  6103. function delete_dir_ilm (ilmid, dirid) {
  6104. var msgAnswer;
  6105. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6106. if (msgAnswer) {
  6107. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6108. }
  6109. }
  6110. function rename_dir_ilm (ilmid, dirname, dirid) {
  6111. var dirnamecopy;
  6112. var i;
  6113. var dirs = new Array($dirs_array);
  6114. do {
  6115. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6116. } while (dirnamecopy == '');
  6117. if (dirnamecopy == null)
  6118. return false;\n
  6119. else {
  6120. for (i=0;i<dirs.length;i++) {
  6121. if (dirs[i]==dirnamecopy) {
  6122. alert('$error_dir_exists');
  6123. return false;\n
  6124. }
  6125. }
  6126. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6127. }
  6128. }
  6129. function move_selected_ilm (ilmid) {
  6130. var param = getCheckbox();
  6131. if (param.join() != '')
  6132. 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();
  6133. else
  6134. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6135. }
  6136. function recover_files_ilm () {
  6137. var msgAnswer;
  6138. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6139. if (msgAnswer) {
  6140. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6141. }
  6142. }
  6143. window.onload = function() {
  6144. var xPosition = 0;
  6145. var yPosition = 0;
  6146. element=document.getElementById('new_file');
  6147. while(element) {
  6148. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6149. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6150. element = element.offsetParent;
  6151. }
  6152. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6153. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6154. location.hash = '#new_file';
  6155. };
  6156. //]]>
  6157. </script>\n";
  6158. $output = "";
  6159. $select_all = "";
  6160. $count_files = 0;
  6161. $extensions_allow = array();
  6162. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6163. foreach ($iassign_ilm as $item_iassign_ilm)
  6164. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6165. foreach ($files_course as $value) {
  6166. $filename = $value->get_filename();
  6167. $filepath = $value->get_filepath();
  6168. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6169. $pathname = $pathname[count($pathname) - 1];
  6170. $fileid = $value->get_id();
  6171. $tmp = explode(".", $filename);
  6172. if (count($tmp)>1) // avoid error if the file has no extension
  6173. $filetype = $tmp[1];
  6174. else // probably error...
  6175. $filetype = '';
  6176. $author = $value->get_author();
  6177. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6178. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6179. $extensions = explode(",", $extension);
  6180. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6181. $count_files ++;
  6182. // buscar fileid nas tabelas do iassign
  6183. $list_filein_use = "";
  6184. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6185. if ($iassign_statement_activity_list) {
  6186. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6187. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6188. }
  6189. }
  6190. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6191. if (!$iassign_ilm) {
  6192. $iassign_ilm = new stdClass();
  6193. $iassign_ilm->id = $ilmid;
  6194. }
  6195. // Do not use $var inside "..." - problem with some "unusual" operational system
  6196. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6197. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6198. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6199. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6200. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6201. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6202. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6203. $check_select = "";
  6204. $link_rename = "";
  6205. $link_delete = "";
  6206. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6207. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6208. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6209. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6210. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6211. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6212. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6213. if ($value->get_userid() == $USER->id) {
  6214. if ($iassign_statement_activity_list) {
  6215. $check_select = "";
  6216. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6217. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6218. $link_rename = "";
  6219. } else {
  6220. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6221. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6222. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6223. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6224. }
  6225. }
  6226. if (!in_array($filetype, $extensions_allow)) {
  6227. $link_edit = "";
  6228. $link_add_ilm_iassign = "";
  6229. $link_add_ilm_tinymce = "";
  6230. $link_add_ilm_atto = "";
  6231. $link_filter = "";
  6232. }
  6233. if ($value->is_directory()) {
  6234. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6235. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6236. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6237. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6238. <td><center>$author</center></td>
  6239. <td><center>$timecreated</center></td>
  6240. <td><center>$timemodified</center></td></tr>\n";
  6241. }
  6242. else if ($this->from == 'iassign') {
  6243. $new_id = "";
  6244. $new_class = "";
  6245. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6246. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6247. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6248. }
  6249. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6250. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6251. <td><center>$author</center></td>
  6252. <td><center>$timecreated</center></td>
  6253. <td><center>$timemodified</center></td></tr>\n";
  6254. }
  6255. else if ($this->from == 'block') {
  6256. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6257. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6258. <td><center>$author</center></td>
  6259. <td><center>$timecreated</center></td>
  6260. <td><center>$timemodified</center></td></tr>\n";
  6261. }
  6262. else if ($this->from == 'tinymce') {
  6263. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6264. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6265. <td><center>$author</center></td>
  6266. <td><center>$timecreated</center></td>
  6267. <td><center>$timemodified</center></td></tr>\n";
  6268. }
  6269. else if ($this->from == 'atto') {
  6270. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6271. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6272. <td><center>$author</center></td>
  6273. <td><center>$timecreated</center></td>
  6274. <td><center>$timemodified</center></td></tr>\n";
  6275. }
  6276. }
  6277. }
  6278. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6279. $dir_base = "";
  6280. $header = "";
  6281. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6282. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6283. foreach ($basename as $value) {
  6284. $dir_base .= $value . "/";
  6285. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6286. if ($dir_id) {
  6287. if ($value == "") {
  6288. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6289. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6290. } else {
  6291. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6292. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6293. }
  6294. }
  6295. } // foreach ($basename as $value)
  6296. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6297. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6298. $html .= "
  6299. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6300. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6301. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6302. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6303. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6304. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6305. </table>\n";
  6306. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6307. $html .= "<table width='100%'><tr>\n";
  6308. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6309. if ($count_files != 0) {
  6310. $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";
  6311. $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";
  6312. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6313. }
  6314. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6315. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6316. $html .= "</form>\n";
  6317. print $code_javascript_ilm;
  6318. print $html;
  6319. } // function view_files_ilm($extension)
  6320. } // class ilm_manager
  6321. /// Class to insert of icons
  6322. class iassign_icons {
  6323. static function insert ($icon) {
  6324. global $CFG;
  6325. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6326. return $string;
  6327. }
  6328. }
  6329. /// Class with util functions for plugin manage
  6330. class iassign_utils {
  6331. /// Function to return the filename extension
  6332. // @param string The $filename as an string
  6333. // @return string Return an string (last group after '.')
  6334. static function filename_extension ($filename) {
  6335. if ($filename == null || $filename == '') {
  6336. return null;
  6337. }
  6338. $itens = explode('.', $filename);
  6339. $num = count($itens);
  6340. if ($num < 2) {
  6341. return null;
  6342. }
  6343. return $itens[$num - 1];
  6344. }
  6345. /// Use the PHP class/package ZipArchive to create a Zip file
  6346. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6347. // 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
  6348. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6349. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6350. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6351. $zip = new zip_archive(); //2
  6352. $res = $zip->open($full_path_zip_filename);
  6353. $total_vet = count($vet_student_filename);
  6354. for ($ii=0; $ii<$total_vet; $ii++) {
  6355. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6356. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6357. }
  6358. $ret = $zip->close();
  6359. iassign_utils::download_file($full_path_zip_filename);
  6360. $filenameZip = $zip->filename;
  6361. return array($ret, $zip);
  6362. }
  6363. static function download_file ($zip_filename) {
  6364. header("Pragma: public");
  6365. header("Expires: 0");
  6366. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6367. header("Cache-Control: private", false);
  6368. header("Content-Type: application/zip");
  6369. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6370. header("Content-Transfer-Encoding: binary");
  6371. header("Content-Length: " . @filesize($zip_filename));
  6372. set_time_limit(0);
  6373. @readfile("$zip_filename") || die("File not found.");
  6374. unlink($zip_filename);
  6375. }
  6376. /// Function for format filename remove special caracters
  6377. // @param string $text String for clean
  6378. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6379. // @return string Return an string in clean format
  6380. static function format_filename ($text) {
  6381. if ($text != '.') {
  6382. //D $text = htmlspecialchars(urldecode($text));
  6383. //D echo "locallib.php: format_filename: $text<br/>";
  6384. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6385. $text = json_decode($text)->{current_language()};
  6386. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6387. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6388. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6389. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6390. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6391. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6392. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6393. // E.g. text = "exerc_midpoint.course.geo"
  6394. // 0123456789012345678901234
  6395. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6396. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6397. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6398. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6399. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6400. //$ext = strrpos($text, ".");
  6401. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6402. //$text = str_replace($array1, $array2, $text);
  6403. }
  6404. return $text;
  6405. }
  6406. /// Function to filter characters to the file name to iLM content
  6407. // @param string $text String for clean
  6408. // @param string $ext String ot the extension of the iLM
  6409. // @return string Return an string in clean format
  6410. static function filter_filename_extension ($filename, $ext) {
  6411. if ($filename != '.') {
  6412. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6413. $arrTo = array("_","","","","","","","","","","","","");
  6414. $filename = str_replace($arrFrom, $arrTo, $filename);
  6415. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6416. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6417. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6418. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6419. $index_lastposition = strlen($filenameF);
  6420. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6421. $text = str_replace(".", "_", $text); // erase all other "."
  6422. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6423. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6424. }
  6425. else
  6426. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6427. return $filenameF;
  6428. }
  6429. /// Function for format pathname remove special caracters
  6430. // @param string $text String for clean
  6431. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6432. // @return string Return an string in clean format
  6433. static function format_pathname ($text, $is_lowercase = true) {
  6434. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6435. $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", "-", "_", "", "", "");
  6436. $text = str_replace($array1, $array2, $text);
  6437. if ($is_lowercase)
  6438. $text = strtolower($text);
  6439. return $text;
  6440. }
  6441. /// Function for format file name from iLM original name
  6442. // @param string $text String to build the file neam
  6443. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6444. // @return string Return an string in clean format
  6445. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6446. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6447. $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", "-", "_", "", "", "");
  6448. $index_firstposition_blank = strpos($ilm_name, " ");
  6449. if ($index_firstposition_blank) { // truncate the name!
  6450. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6451. }
  6452. $index_firstposition_dots = strpos($ilm_name, ":");
  6453. if ($index_firstposition_dots) { // truncate the name!
  6454. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6455. }
  6456. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6457. if ($is_lowercase)
  6458. $namefiltered = strtolower($namefiltered);
  6459. return $namefiltered;
  6460. }
  6461. /// Function for insert version in the filename
  6462. // @param string $filename Name of file
  6463. // @return string Return the filename with version
  6464. static function version_filename ($filename) {
  6465. $array_filename = explode('.', $filename);
  6466. if (count($array_filename) > 1)
  6467. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6468. else
  6469. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6470. return $filename;
  6471. }
  6472. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6473. static function remove_code_message ($string) {
  6474. $array = explode("&lt;ia_uc&gt;", $string);
  6475. return $array[0];
  6476. }
  6477. }
  6478. // class iassign_utils
  6479. /// Class with language functions for plugin manage
  6480. class iassign_language {
  6481. /// Function for return text in language or get default language (en)
  6482. // @param string $lang Code of language
  6483. // @param string $description JSON text content all languages
  6484. // @return string Return an string in the language selected
  6485. static function get_description_lang ($lang, $descriptions) {
  6486. $description_lang = "";
  6487. $description = json_decode($descriptions);
  6488. if ($description == null) {
  6489. $description_lang = $descriptions;
  6490. }
  6491. else {
  6492. if (isset($description->{$lang}))
  6493. $description_lang = $description->{$lang};
  6494. else
  6495. if (isset($description->en)) //MOOC2014
  6496. $description_lang = $description->en;
  6497. else //MOOC2014
  6498. $description_lang = "en"; //MOOC2014
  6499. }
  6500. return $description_lang;
  6501. }
  6502. /// Function for return all language supported by iLM
  6503. // @param string $descriptions JSON text content all languages
  6504. // @return string Return as string with all languages
  6505. static function get_all_lang ($descriptions) {
  6506. $langs = "";
  6507. $description = json_decode($descriptions);
  6508. if ($description) {
  6509. foreach ($description as $key => $value) {
  6510. $langs .= $key . " ; ";
  6511. }
  6512. $langs = substr($langs, 0, strlen($langs) - 3);
  6513. }
  6514. return $langs;
  6515. }
  6516. /// Function for convert json in xml //MOOC2014
  6517. // @param string $json JSON text
  6518. // @return string Return as string with xml tags
  6519. static function json_to_xml ($json) {
  6520. $xml = "";
  6521. $json = json_decode($json);
  6522. foreach ($json as $key => $value) {
  6523. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6524. }
  6525. return $xml;
  6526. }
  6527. }
  6528. // class iassign_language
  6529. /// Class with log functions for plugin manage.
  6530. class iassign_log {
  6531. /// Function for insert log event
  6532. // @param string $action Code action of event
  6533. // @param string $information Text for describe action of event
  6534. // @param int $cmid Id of context module
  6535. // @param int $ilmid Id of iLM
  6536. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6537. global $COURSE, $CFG, $USER, $DB;
  6538. $newentry = new stdClass();
  6539. $newentry->time = time();
  6540. $newentry->userid = $USER->id;
  6541. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6542. $newentry->course = $COURSE->id;
  6543. $newentry->cmid = $cmid;
  6544. $newentry->ilmid = $ilmid;
  6545. $newentry->action = $action;
  6546. $newentry->info = $information;
  6547. $newentry->language = current_language();
  6548. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6549. if (ini_get("browscap") && function_exists('get_browse')) {
  6550. $browser = get_browse(null, true);
  6551. $newentry->javascript = $browser['javascript'];
  6552. $newentry->java = $browser['javaapplets'];
  6553. }
  6554. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6555. print_error('error_add_log', 'iassign');
  6556. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6557. } // class iassign_log