locallib.php 357 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686
  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,
  315. 'mod_iassign',
  316. 'exercise',
  317. $iassign_statement->file);
  318. foreach ($files as $file) {
  319. if ($file->get_filename() != ".") {
  320. print($file->get_content());
  321. }
  322. }
  323. die();
  324. }
  325. /// This method receives the data from auto_eval event
  326. /// @see auto_evaluate()
  327. function post_auto_eval_result () {
  328. global $COURSE, $CFG, $USER, $DB;
  329. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  330. exit;
  331. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  332. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  333. $student = optional_param('student', -1, PARAM_INT);
  334. $grade = optional_param('grade', 0, PARAM_FLOAT);
  335. // 1: Recuperar a nota atual:
  336. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  337. // 2: Atualizar a tabela:
  338. $update_entry = new stdClass();
  339. $update_entry->id = $actual->id;
  340. $update_entry->previous_grade = $actual->grade;
  341. $update_entry->grade = $grade;
  342. // Update the iassign_submission
  343. $DB->update_record("iassign_submission", $update_entry);
  344. }
  345. /// This method runs activities auto evaluation in teacher area
  346. function auto_evaluate () {
  347. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  348. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  349. exit;
  350. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  351. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  352. // Get list of exercises in the instance:
  353. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  354. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  355. // Get list of enrolled students:
  356. $params = array('shortname' => 'student');
  357. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  358. $context = context_course::instance($this->course->id);
  359. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  360. $students_list = $DB->get_records_sql(
  361. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  362. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  363. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  364. print $OUTPUT->header();
  365. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  366. print '<ul style="list-style-type: none; margin: 1em;">';
  367. foreach ($exercises_list as $exercise) {
  368. $matches = [];
  369. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  370. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  371. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  372. if ($matches[0][0]) {
  373. 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>';
  374. } else {
  375. 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>';
  376. }
  377. } else {
  378. if ($matches[0][0]) {
  379. 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>';
  380. } else {
  381. 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>';
  382. }
  383. }
  384. }
  385. print '</ul>
  386. <center>
  387. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  388. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  389. <div id="evaluate_message" style="color: red"></div>
  390. <div id="evaluate_alerts"></div>
  391. <div>
  392. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  393. <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>
  394. </div>
  395. </center>';
  396. print '</div>';
  397. print '<script>';
  398. print '
  399. ';
  400. print 'var submissions = [';
  401. // Get list of student id have submit for each exercise:
  402. foreach ($exercises_list as $exercise) {
  403. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  404. print '
  405. {
  406. "exerciseid": "'.$exercise->id.'",
  407. "grade": '.$exercise->grade.',
  408. "ilm": "'. $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  409. "submited": [';
  410. $params = array('iassign_statementid' => $exercise->id);
  411. $submited = $DB->get_records_sql(
  412. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  413. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  414. foreach ($submited as $ss) {
  415. print( $ss->userid . ',');
  416. }
  417. print '],';
  418. print '"allgrades": [';
  419. foreach ($submited as $ss) {
  420. print( $ss->grade . ',');
  421. }
  422. print ']
  423. },';
  424. }
  425. print '];
  426. var total_submissions = 0;
  427. var selected_exercises;
  428. var count_steps;
  429. var value_by_step;
  430. var stoped = false;
  431. var time_interval = 5000;
  432. var var_interval;
  433. function add_hover_th (id_th, id_li) {
  434. $("#"+id_th).hover(function() {
  435. $("#"+id_li).css("background-color", "#d9d8d8");
  436. $(this).css("background-color", "#d9d8d8");
  437. }, function() {
  438. $("#"+id_li).css("background-color", "");
  439. $(this).css("background-color", "");
  440. });
  441. }
  442. function start_evaluation() {
  443. stoped = false;
  444. $("#progress_bar").css("display", "none");
  445. $("#evaluate_message").text("");
  446. $("#evaluate_alerts").text("");
  447. $(".added-col").remove();
  448. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  449. selected_exercises = [];
  450. var c = 0;
  451. for (var i = 0; i < exercises.length; i++) {
  452. if($("#ex_"+exercises[i]).is(":checked") == true) {
  453. selected_exercises[c++] = exercises[i];
  454. }
  455. }
  456. if (selected_exercises.length == 0) {
  457. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  458. return;
  459. } else {
  460. $("input:checkbox").attr("disabled", true);
  461. for (var i = 0; i < selected_exercises.length; i++) {
  462. var desc = $("#ex_"+selected_exercises[i]).data("iditem");
  463. $("#cols-exercises").append( $("<th />", {class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i]}));
  464. $("#table-results tbody tr").each(function(e) {
  465. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  466. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  467. });
  468. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  469. }
  470. $("#button_start").prop("disabled", true);
  471. $("#button_stop").prop("disabled", false);
  472. $("#progress_bar").css("display", "block");
  473. }
  474. total_submissions = selected_exercises.length * students.length;
  475. count_steps = 0;
  476. value_by_step = 100/total_submissions;
  477. actual_exercise = 0;
  478. actual_student = 0;
  479. actual_submission = 0;
  480. get_original_propositions();
  481. var_interval = setInterval(verifyBreak, time_interval);
  482. }
  483. var actual_exercise;
  484. var actual_student;
  485. var actual_submission;
  486. function run_individual_evaluation () {
  487. if (stoped) return;
  488. // Verificar se o aluno realmente enviou
  489. var found = false;
  490. for (var j = 0; j < submissions.length; j++) {
  491. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  492. for (var k = 0; k < submissions[j].submited.length; k++) {
  493. if (students[actual_student] == submissions[j].submited[k]) {
  494. found = true;
  495. break;
  496. }
  497. }
  498. break;
  499. }
  500. }
  501. if (found == false) {
  502. postResultAutoEval();
  503. } else {
  504. // Caso tenha enviado, buscar...
  505. var final_url = "";
  506. 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];
  507. for (var j = 0; j < submissions.length; j++) {
  508. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  509. final_url = submissions[j].ilm;
  510. break;
  511. }
  512. }
  513. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment="+encodeURIComponent(student_answer)+"&iLM_PARAM_TeacherAutoEval=true";
  514. window.frames["ifrm"].location=final_url;
  515. }
  516. }
  517. var break_student = -1;
  518. var break_exercise = -1;
  519. function verifyBreak () {
  520. if (actual_student == break_student && actual_exercise == break_exercise) {
  521. postResultAutoEval(-6);
  522. break_student = -1;
  523. break_exercise = -1;
  524. return;
  525. } else {
  526. break_student = actual_student;
  527. break_exercise = actual_exercise;
  528. }
  529. }
  530. function getAutoEvalOriginalData () {
  531. return original_propositions[actual_exercise];
  532. }
  533. function updateProgressBar () {
  534. if (stoped) return;
  535. var temp = (count_steps * value_by_step)|0;
  536. count_steps ++;
  537. temp = temp > 100 ? 100 : temp;
  538. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  539. if (temp >= 100) {
  540. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  541. $("#button_start").prop("disabled", false);
  542. $("#button_stop").prop("disabled", true);
  543. $("input:checkbox").attr("disabled", false);
  544. clearInterval(var_interval);
  545. }
  546. }
  547. function postResultAutoEval (grade = null) {
  548. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  549. if (grade == null) {
  550. $("#"+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>\');
  551. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  552. } else {
  553. // Verificar se a nota é a mesma que já está registrada:
  554. var actual_value = 0;
  555. var actual_student_grade = 0;
  556. for (var k = 0; k < submissions.length; k++) {
  557. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  558. actual_value = submissions[k].grade;
  559. for (var h = 0; h < submissions[k].submited.length; h++) {
  560. if (submissions[k].submited[h] == students[actual_student]) {
  561. actual_student_grade = submissions[k].allgrades[h];
  562. break;
  563. }
  564. }
  565. break;
  566. }
  567. }
  568. /** @FeedbackConvention **/
  569. if (grade < 0) {
  570. switch (grade) {
  571. case -1:
  572. // Casos de teste vazios:
  573. $("#"+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>\');
  574. var mm = actual_exercise;
  575. $("#"+id_t).find(".details-button").click(function(e) {
  576. $(".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>\');
  577. });
  578. break;
  579. case -2:
  580. // Casos de teste alterados pelo aluno:
  581. $("#"+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>\');
  582. var mm = actual_exercise;
  583. $("#"+id_t).find(".details-button").click(function(e) {
  584. $(".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>\');
  585. });
  586. $.ajax({
  587. dataType: "html",
  588. 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",
  589. success: function(d) {}
  590. });
  591. break;
  592. case -5:
  593. // Falha na execução:
  594. $("#"+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>\');
  595. var mm = actual_exercise;
  596. $("#"+id_t).find(".details-button").click(function(e) {
  597. $(".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>\');
  598. });
  599. break;
  600. case -6:
  601. // O iLM não respondeu:
  602. $("#"+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>\');
  603. $("#"+id_t).find(".details-button").click(function(e) {
  604. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('auto_evaluate_msg_time', 'iassign').'</td></tr></table>\');
  605. });
  606. break;
  607. }
  608. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  609. } else {
  610. if ((grade * actual_value) == (actual_student_grade)) {
  611. $("#"+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>\');
  612. } else { // Notas diferem:
  613. $("#"+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>\');
  614. var mm = actual_exercise;
  615. $("#"+id_t).find(".details-button").click(function(e) {
  616. $(".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+\'</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>\');
  617. });
  618. // Enviar para o endpoint post_auto_eval_result verificar:
  619. $.ajax({
  620. dataType: "html",
  621. 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 * actual_value),
  622. success: function(d) {}
  623. });
  624. }
  625. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  626. }
  627. }
  628. updateProgressBar();
  629. // Pode continuar no mesmo exercício ou para?
  630. if (actual_student < students.length) {
  631. actual_student ++;
  632. run_individual_evaluation();
  633. } else {
  634. actual_student = 0;
  635. // Pode ir para o próximo exercício ou acabou?
  636. if (actual_exercise < selected_exercises.length) {
  637. actual_exercise++;
  638. run_individual_evaluation();
  639. } else {
  640. $("#evaluate_alerts").text("'.get_string('auto_evaluate_finished', 'iassign').'");
  641. }
  642. }
  643. }
  644. var original_propositions;
  645. function get_original_propositions () {
  646. original_propositions = [];
  647. var count = 0;
  648. for (var i = 0; i < exercises.length; i++) {
  649. if($("#ex_"+exercises[i]).is(":checked") == true) {
  650. $.ajax({
  651. dataType: "html",
  652. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=get_teacher_exercise&id='.$this->cm->id.'&iassign_exercise="+exercises[i],
  653. success: function(d) {
  654. original_propositions[count] = d;
  655. count ++;
  656. if (count == selected_exercises.length) {
  657. run_individual_evaluation();
  658. }
  659. }
  660. });
  661. }
  662. }
  663. }
  664. function stop_evaluation () {
  665. stoped = true;
  666. $("#button_start").prop("disabled", false);
  667. $("#button_stop").prop("disabled", true);
  668. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  669. $("input:checkbox").attr("disabled", false);
  670. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  671. clearInterval(var_interval);
  672. }
  673. var exercises = [ ';
  674. foreach ($exercises_list as $exercise) {
  675. print $exercise->id . ',';
  676. }
  677. print ' ];';
  678. print ' var students = [ ';
  679. foreach ($students_list as $student) {
  680. print $student->userid . ',';
  681. }
  682. print '];';
  683. print ' var ilms = [';
  684. foreach ($exercises_list as $exercise) {
  685. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  686. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  687. }
  688. print ']';
  689. print '</script>';
  690. print '
  691. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  692. <div class="modal-dialog modal-dialog-centered" role="document">
  693. <div class="modal-content">
  694. <div class="modal-header">
  695. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('auto_evaluate_details', 'iassign').'</h5>
  696. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  697. <span aria-hidden="true">&times;</span>
  698. </button>
  699. </div>
  700. <div class="modal-body">
  701. ...
  702. </div>
  703. <div class="modal-footer">
  704. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('close', 'iassign').'</button>
  705. </div>
  706. </div>
  707. </div>
  708. </div>';
  709. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  710. print '<table id="table-results" class="table table-hover m-t-1">
  711. <thead>
  712. <tr id="cols-exercises">
  713. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  714. </tr>
  715. </thead>
  716. <tbody>';
  717. foreach ($students_list as $student) {
  718. $user = $DB->get_record('user', array('id' => $student->userid));
  719. $avatar = new user_picture($user);
  720. $avatar->courseid = $COURSE->id;
  721. $avatar->link = true;
  722. print
  723. '<tr data-student="'.$student->userid.'">
  724. <td>'.$OUTPUT->render($avatar). ' <span class="student-name">'.$user->firstname.' '.$user->lastname.'</span></td>
  725. </tr>';
  726. }
  727. print '</tbody>
  728. </table>';
  729. print $OUTPUT->footer();
  730. }
  731. /// This method moves an iAssign activity
  732. function move_activity () {
  733. global $USER, $CFG, $DB, $COURSE;
  734. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  735. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  736. $update_entry_new_iassign = new stdClass();
  737. $update_entry_new_iassign->id = $iassign_id;
  738. $update_entry_new_iassign->iassignid = $iassign_destiny;
  739. // Update the iassign_statement
  740. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  741. // Update file context
  742. $c_i = context_module::instance($this->cm->id);
  743. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  744. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  745. $path_module = context_course::instance($COURSE->id);
  746. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  747. if ($context_file) {
  748. $id_context = $context_file->id;
  749. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  750. $fs = get_file_storage(); // Get reference to all files in Moodle data
  751. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  752. foreach ($files as $value) {
  753. if ($value->get_filename() != ".") {
  754. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  755. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  756. $updateentry = new stdClass();
  757. $updateentry->id = $iassign_id;
  758. $updateentry->file = $newfile->get_itemid();
  759. $DB->update_record("iassign_statement", $updateentry);
  760. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  761. break;
  762. }
  763. }
  764. }
  765. $this->return_home_course('moved_activity');
  766. exit;
  767. }
  768. /// This method duplicates an iAssign activity
  769. function duplicate_activity () {
  770. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  771. $id = $this->cm->id;
  772. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  773. $context = context_module::instance($this->cm->id);
  774. $contextuser = context_user::instance($USER->id);
  775. // Get the the iAssign acitivity to be duplicated
  776. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  777. // Remove the current id of activity
  778. $iassign_statement->id=0;
  779. // Get the information about current author, and add this information in author_modified field
  780. $author = $DB->get_record("user", array('id' => $USER->id));
  781. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  782. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  783. // Store the activity in the table
  784. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  785. // Duplicate activity file
  786. $fs = get_file_storage(); // Get reference to all files in Moodle data
  787. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  788. foreach ($files as $value) {
  789. if ($value->get_filename() != ".") {
  790. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  791. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  792. $updateentry = new stdClass();
  793. $updateentry->id = $id_;
  794. $updateentry->file = $newfile->get_itemid();
  795. // Update the duplicated iLM iAssign with new file id
  796. $DB->update_record("iassign_statement", $updateentry);
  797. }
  798. }
  799. }
  800. // log event --------------------------------------------------------------------------------------
  801. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  802. $this->return_home_course('duplicated_activity');
  803. exit;
  804. }
  805. /// This method gets the content from the iLM and register it
  806. // It could be the "exercise template" (teacher) or an answer (student)
  807. function get_answer () {
  808. global $USER, $CFG, $DB, $OUTPUT;
  809. $id = $this->cm->id;
  810. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  811. $comment = false;
  812. if ($submission_comment)
  813. $comment = $this->write_comment_submission();
  814. // receives data of iLM using the current activity
  815. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  816. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  817. // receives data of submission of current activity
  818. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  819. // receives post and get
  820. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  821. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  822. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  823. $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)
  824. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  825. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  826. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  827. $msg = '';
  828. // Feedback
  829. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  830. $str_action = "view"; // repeat
  831. if (strtolower($iassign_ilm->name) == "igeom") {
  832. }
  833. $title = get_string('evaluate_iassign', 'iassign');
  834. print $OUTPUT->header();
  835. print $OUTPUT->box_start();
  836. // Action = { view ; repeat ; viewsubmission }
  837. // * '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")
  838. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  839. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  840. $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;
  841. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  842. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  843. print '<table width=100% >';
  844. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  845. //TODO alterar aqui???
  846. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  847. // empty_answer_post = No solution was posted.
  848. if ($comment)
  849. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  850. else
  851. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  852. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  853. } else {
  854. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  855. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  856. // Correct answer!!
  857. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  858. $this->write_solution = 1; //
  859. $status = 3;
  860. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  861. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  862. // log record
  863. $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;
  864. // Trigger module viewed event.
  865. $event = \mod_iassign\event\submission_created::create(array(
  866. 'objectid' => $this->iassign->id,
  867. 'context' => $this->context,
  868. 'other' => $info
  869. ));
  870. $event->add_record_snapshot('course', $this->course);
  871. $event->trigger();
  872. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  873. // Wrong answer...: get_answer_incorrect
  874. $status = 2;
  875. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  876. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  877. // log record
  878. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  879. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  880. // Trigger module viewed event.
  881. $event = \mod_iassign\event\submission_created::create(array(
  882. 'objectid' => $this->iassign->id,
  883. 'context' => $this->context,
  884. 'other' => $info
  885. ));
  886. $event->add_record_snapshot('course', $this->course);
  887. $event->trigger();
  888. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  889. // Presents to the learner the result of the automatic evaluate?
  890. if ($this->activity->get_activity()->show_answer == 0) { // no...
  891. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  892. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  893. print '<tr>';
  894. // log record
  895. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  896. // Trigger module viewed event.
  897. $event = \mod_iassign\event\submission_created::create(array(
  898. 'objectid' => $this->iassign->id,
  899. 'context' => $this->context,
  900. 'other' => $info
  901. ));
  902. $event->add_record_snapshot('course', $this->course);
  903. $event->trigger();
  904. } else { // yes!!!
  905. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  906. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  907. print '<tr>';
  908. print $msg;
  909. }
  910. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  911. $status = 1;
  912. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  913. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  914. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  915. print '<tr>';
  916. // log record
  917. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  918. $event = \mod_iassign\event\submission_created::create(array(
  919. 'objectid' => $this->iassign->id,
  920. 'context' => $this->context,
  921. 'other' => $info
  922. ));
  923. $event->add_record_snapshot('course', $this->course);
  924. $event->trigger();
  925. } // if ($iassign_ilm->evaluate == 1)
  926. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  927. print '</tr></table>';
  928. print $OUTPUT->box_end();
  929. // add or update evaluate
  930. if ($this->write_solution == 1) {
  931. $timenow = time();
  932. // new record
  933. if (!$iassign_submission) {
  934. $newentry = new stdClass();
  935. $newentry->userid = $this->userid_iassign;
  936. // $newentry->userid = $USER->id;
  937. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  938. $newentry->timecreated = $timenow;
  939. $newentry->timemodified = $timenow;
  940. $newentry->answer = $iLM_PARAM_ArchiveContent;
  941. $newentry->grade = round($grade_student, 2);
  942. $newentry->status = $status;
  943. $newentry->experiment = 1;
  944. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  945. print_error('error_insert', 'iassign');
  946. } else {
  947. // Trigger module viewed event.
  948. $event = \mod_iassign\event\submission_created::create(array(
  949. 'objectid' => $this->iassign->id,
  950. 'context' => $this->context
  951. ));
  952. $event->add_record_snapshot('course', $this->course);
  953. $event->trigger();
  954. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  955. }
  956. } elseif ($iassign_submission->status != 3) {
  957. $newentry = new stdClass();
  958. $newentry->id = $iassign_submission->id;
  959. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  960. $newentry->userid = $iassign_submission->userid;
  961. $newentry->timecreated = $iassign_submission->timecreated;
  962. $newentry->timemodified = $timenow;
  963. $newentry->answer = $iLM_PARAM_ArchiveContent;
  964. $newentry->grade = round($grade_student, 2);
  965. $newentry->status = $status;
  966. $newentry->experiment = $iassign_submission->experiment + 1;
  967. if (!$DB->update_record("iassign_submission", $newentry)) {
  968. print_error('error_update', 'iassign');
  969. //D depurar...
  970. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  971. //D $fp = fopen("teste1.txt","w");
  972. //D fwrite($fp,$stringAux);
  973. } else {
  974. // Trigger module viewed event.
  975. $event = \mod_iassign\event\submission_updated::create(array(
  976. 'objectid' => $this->iassign->id,
  977. 'context' => $this->context
  978. ));
  979. $event->add_record_snapshot('course', $this->course);
  980. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  981. }
  982. } else {
  983. if ($return_get_answer == 1) {
  984. $newentry = new stdClass();
  985. $newentry->id = $iassign_submission->id;
  986. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  987. $newentry->userid = $iassign_submission->userid;
  988. $newentry->timecreated = $iassign_submission->timecreated;
  989. $newentry->timemodified = $timenow;
  990. $newentry->answer = $iLM_PARAM_ArchiveContent;
  991. $newentry->grade = round($grade_student, 2);
  992. $newentry->status = $status;
  993. $newentry->experiment = $iassign_submission->experiment + 1;
  994. if (!$DB->update_record("iassign_submission", $newentry))
  995. print_error('error_update', 'iassign');
  996. else {
  997. $event = \mod_iassign\event\submission_updated::create(array(
  998. 'objectid' => $this->iassign->id,
  999. 'context' => $this->context
  1000. ));
  1001. $event->add_record_snapshot('course', $this->course);
  1002. $event->trigger();
  1003. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1004. print $OUTPUT->box_start();
  1005. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1006. print $OUTPUT->box_end();
  1007. }
  1008. } elseif ($return_get_answer == 2) {
  1009. print $OUTPUT->box_start();
  1010. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1011. print $OUTPUT->box_end();
  1012. } else {
  1013. print $OUTPUT->box_start();
  1014. print "
  1015. <script type='text/javascript'>
  1016. //<![CDATA[
  1017. function overwrite () {
  1018. document.formEnvio.return_get_answer.value = 1;
  1019. document.formEnvio.submit();
  1020. }
  1021. function nooverwrite () {
  1022. document.formEnvio.return_get_answer.value = 2;
  1023. document.formEnvio.submit();
  1024. }
  1025. //]]>
  1026. </script>";
  1027. $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;
  1028. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1029. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1030. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1031. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1032. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1033. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1034. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1035. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1036. <input type='hidden' name='return_get_answer'/> ";
  1037. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1038. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1039. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1040. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1041. print " </form>";
  1042. print $OUTPUT->box_end();
  1043. }
  1044. }
  1045. } // if ($this->write_solution == 1)
  1046. print $OUTPUT->footer();
  1047. die();
  1048. } // function get_answer()
  1049. /// Export in file the answer of student.
  1050. function export_file_answer () {
  1051. global $DB;
  1052. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1053. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1054. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1055. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1056. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1057. $extensions = explode(",", $iassign_ilm->extension);
  1058. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1059. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1060. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1061. header("Pragma: public");
  1062. header("Expires: 0");
  1063. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1064. header("Cache-Control: private", false);
  1065. header("Content-Type: document/unknown");
  1066. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1067. set_time_limit(0);
  1068. print($iassign_submission->answer);
  1069. exit;
  1070. } // function export_file_answer()
  1071. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1072. // @calledby $this->export_package_answer()
  1073. //TODO Precisa terminar! //TODO_HTML
  1074. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1075. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1076. <head>
  1077. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1078. $str_html .= " </head>
  1079. <body>\n";
  1080. $tam = sizeof($array_iassign_name);
  1081. for ($ii=0; $ii<$tam; $ii++) {
  1082. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1083. }
  1084. $str_html .= "
  1085. </body>\n</html>";
  1086. return $str_html;
  1087. }
  1088. /// Export an package (zip) with all answer of students
  1089. // @calledby $this->action()
  1090. function export_package_answer () {
  1091. global $DB, $CFG, $OUTPUT;
  1092. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1093. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1094. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1095. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1096. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1097. $userid = optional_param('userid', NULL, PARAM_INT);
  1098. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1099. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1100. //TODO_HTML echo "username=$username<br/>"; exit;
  1101. $current_date = date('Y_m_d_H');
  1102. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1103. // If temporary directory under Moodle data does not exists => create it
  1104. if (!is_dir($diretorio)) {
  1105. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1106. // created directory with permissions to be seen by everyone
  1107. }
  1108. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1109. if (!is_writable($diretorio)) { // send a highlighted message!
  1110. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1111. exit; // just in case
  1112. }
  1113. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1114. $zip = new zip_archive(); // create ZIP
  1115. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1116. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1117. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1118. $vet_student_filename = array();
  1119. $vet_student_content = array();
  1120. foreach ($iassign_statements as $iassign_statement) {
  1121. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1122. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1123. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1124. $extensions = explode(",", $iassign_ilm->extension);
  1125. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1126. if ($iassign_submission) {
  1127. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1128. $student_content = $iassign_submission->answer;
  1129. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1130. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1131. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1132. if ($resp) {
  1133. $vet_student_filename[] = $student_filename;
  1134. $vet_student_content[] = $student_content;
  1135. }
  1136. else { // send a highlighted message!
  1137. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1138. exit; // just in case
  1139. }
  1140. }
  1141. }
  1142. $zip->close(); // close the ZIP file
  1143. if (count($vet_student_filename)>0) {
  1144. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1145. $result_tf = $vet_result[0];
  1146. $filenameZip = $vet_result[1]->filename;
  1147. }
  1148. iassign_utils::download_file($zip_filename); // download the ZIP file
  1149. exit;
  1150. } // function export_package_answer()
  1151. /// Editing status of interactive activities
  1152. function edit_status () {
  1153. global $USER, $DB, $OUTPUT;
  1154. $newentry = new stdClass();
  1155. $newentry->id = $this->iassign_submission_current;
  1156. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1157. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1158. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1159. $newentry->status = $iassign_submission->status;
  1160. $newentry->teacher = $USER->id;
  1161. if (!$DB->update_record('iassign_submission', $newentry))
  1162. print_error('error_update', 'iassign');
  1163. else {
  1164. // Trigger module viewed event.
  1165. $event = \mod_iassign\event\submission_updated::create(array(
  1166. 'objectid' => $this->iassign->id,
  1167. 'context' => $this->context
  1168. ));
  1169. $event->add_record_snapshot('course', $this->course);
  1170. $event->trigger();
  1171. $this->action = 'viewsubmission';
  1172. $this->view_iassign_current();
  1173. } // if (!$DB->update_record('iassign_submission', $newentry))
  1174. } // function edit_status()
  1175. /// Editing grade of interactive activities
  1176. function edit_grade () {
  1177. global $USER, $DB, $OUTPUT;
  1178. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1179. if ($newgrade && $newgrade >= 0) {
  1180. $newentry = new stdClass();
  1181. $newentry->id = $this->iassign_submission_current;
  1182. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1183. $newentry->teacher = $USER->id;
  1184. if (!$DB->update_record('iassign_submission', $newentry))
  1185. print_error('error_update', 'iassign');
  1186. else {
  1187. // Trigger module viewed event.
  1188. $event = \mod_iassign\event\submission_updated::create(array(
  1189. 'objectid' => $this->iassign->id,
  1190. 'context' => $this->context
  1191. ));
  1192. $event->add_record_snapshot('course', $this->course);
  1193. $event->trigger();
  1194. }
  1195. } // if ($newgrade >= 0)
  1196. $this->action = 'viewsubmission';
  1197. $this->view_iassign_current();
  1198. }
  1199. /// Add or Edit interactive activities
  1200. // @calledby $this->action()
  1201. function add_edit_iassign () {
  1202. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1203. require_once('iassign_form.php');
  1204. $id = $this->cm->id;
  1205. $iassignid = $this->iassign->id;
  1206. $param = new stdClass();
  1207. $param->action = $this->action; // oculto
  1208. $param->id = $id; // oculto
  1209. $COURSE->cm = $id;
  1210. $COURSE->iassignid = $iassignid;
  1211. $COURSE->iassign_file_id = NULL;
  1212. $context = context_module::instance($this->cm->id);
  1213. $contextuser = context_user::instance($USER->id);
  1214. $component = 'mod_iassign';
  1215. $filearea = 'exercise';
  1216. if (!empty($this->iassign_current))
  1217. $COURSE->iassign_id = $this->iassign_current;
  1218. else
  1219. $COURSE->iassign_id = 0;
  1220. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1221. if ($this->action == 'add') {
  1222. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1223. $params = array('iassignid' => $iassignid);
  1224. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1225. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1226. $total_of_activities = count($iassign_statement);
  1227. $param->iassignid = $iassignid;
  1228. $param->name = "";
  1229. $param->oldname = "";
  1230. $param->type_iassign = 3;
  1231. $param->proposition = "";
  1232. $author = $DB->get_record("user", array("id" => $USER->id));
  1233. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1234. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1235. $param->author = $param->author_name;
  1236. $param->author_modified = $param->author_modified_name;
  1237. $COURSE->iassign_list = array();
  1238. $param->iassign_list = array();
  1239. if ($iassign_statement) {
  1240. foreach ($iassign_statement as $iassign) {
  1241. $iassignid = $iassign->id;
  1242. $param->iassign_list[$iassignid] = 0;
  1243. $COURSE->iassign_list[$iassignid] = new stdClass();
  1244. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1245. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1246. $COURSE->iassign_list[$iassignid]->enable = 1;
  1247. } // foreach ($iassign_statement as $iassign)
  1248. }
  1249. $param->iassign_ilmid = 0;
  1250. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1251. $param->file = 0;
  1252. $param->fileold = 0;
  1253. $param->filename = "";
  1254. $param->grade = $iassign_data->grade;
  1255. $param->timemodified = time();
  1256. $param->timecreated = time();
  1257. $param->timeavailable = $iassign_data->timeavailable;
  1258. $param->timedue = $iassign_data->timedue;
  1259. $param->preventlate = $iassign_data->preventlate;
  1260. $param->test = $iassign_data->test;
  1261. $param->special_param1 = 0;
  1262. $param->visible = 1;
  1263. $param->max_experiment = $iassign_data->max_experiment;
  1264. $param->dependency = 0;
  1265. $param->automatic_evaluate = 1;
  1266. $param->show_answer = 1;
  1267. } // if ($this->action == 'add')
  1268. elseif ($this->action == 'edit') {
  1269. $COURSE->iassign_list = array();
  1270. $this_activity = $this->activity->get_activity();
  1271. if ($this_activity != null) {
  1272. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1273. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1274. $param->iassign_id = $iassign_statement_current->id; // oculto
  1275. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1276. $param->name = $iassign_statement_current->name;
  1277. $param->oldname = $iassign_statement_current->name;
  1278. $param->type_iassign = $iassign_statement_current->type_iassign;
  1279. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1280. //2019 $param->proposition = $iassign_statement_current->proposition;
  1281. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1282. $param->author_name = $iassign_statement_current->author_name; // oculto
  1283. $param->author = $iassign_statement_current->author_name;
  1284. $author = $DB->get_record("user", array('id' => $USER->id));
  1285. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1286. $param->author_modified = $param->author_modified_name;
  1287. $dependency = explode(';', $iassign_statement_current->dependency);
  1288. $param->iassign_list = array();
  1289. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1290. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1291. $array_dependency = array();
  1292. $subdependency = "";
  1293. $sub_subdependency = "";
  1294. // dependent on this exercise
  1295. if ($iassign_statement_dependency) {
  1296. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1297. // to whom this exercise depends
  1298. foreach ($inter as $tmp)
  1299. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1300. $list_dependency = $subdependency . $sub_subdependency;
  1301. $array_dependency = explode(";", $list_dependency);
  1302. }
  1303. // Get all activity with the same iLM - iassignid
  1304. $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";
  1305. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1306. $total_of_activities = count($all_others_iassign_statement) + 1;
  1307. $inter = array();
  1308. if ($all_others_iassign_statement) {
  1309. foreach ($all_others_iassign_statement as $iassign)
  1310. if (in_array($iassign->id, $dependency))
  1311. $inter[] = $iassign->id;
  1312. }
  1313. if ($all_others_iassign_statement) {
  1314. foreach ($all_others_iassign_statement as $iassign) {
  1315. $iassignid = $iassign->id;
  1316. $COURSE->iassign_list[$iassignid] = new stdClass();
  1317. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1318. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1319. if (in_array($iassignid, $dependency))
  1320. $param->iassign_list[$iassignid] = 1;
  1321. else
  1322. $param->iassign_list[$iassignid] = 0;
  1323. if (in_array($iassignid, $array_dependency))
  1324. $COURSE->iassign_list[$iassignid]->enable = 0;
  1325. else
  1326. $COURSE->iassign_list[$iassignid]->enable = 1;
  1327. } // foreach ($all_others_iassign_statement as $iassign)
  1328. }
  1329. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1330. $param->fileold = 0;
  1331. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1332. $param->filename = '';
  1333. $param->grade = $iassign_statement_current->grade;
  1334. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1335. $param->timeavailable = $iassign_statement_current->timeavailable;
  1336. $param->timedue = $iassign_statement_current->timedue;
  1337. $param->preventlate = $iassign_statement_current->preventlate;
  1338. $param->test = $iassign_statement_current->test;
  1339. $param->special_param1 = $iassign_statement_current->special_param1;
  1340. $param->position = $iassign_statement_current->position; // oculto
  1341. $param->visible = $iassign_statement_current->visible;
  1342. $param->max_experiment = $iassign_statement_current->max_experiment;
  1343. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1344. $param->show_answer = $iassign_statement_current->show_answer;
  1345. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1346. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1347. if ($files) {
  1348. foreach ($files as $file) {
  1349. if ($file->get_filename() != '.') {
  1350. $param->filename = $file->get_filename();
  1351. $param->file = $file->get_id();
  1352. $param->fileold = $file->get_id();
  1353. $COURSE->iassign_file_id = $file->get_id();
  1354. }
  1355. }
  1356. }
  1357. //TODO //MOOC2014 -- inicio
  1358. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1359. //D if ($iassign_ilm_configs) {
  1360. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1361. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1362. //D } //MOOC2014 -- fim
  1363. } // if ($this_activity != null)
  1364. } // elseif ($this->action == 'edit')
  1365. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1366. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1367. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1368. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1369. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1370. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1371. $param->position = $total_of_activities;
  1372. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1373. $mform->set_data($param);
  1374. if ($mform->is_cancelled()) {
  1375. $this->return_home_course('iassign_cancel');
  1376. exit;
  1377. }
  1378. else { // if ($mform->is_cancelled())
  1379. $result = $mform->get_data();
  1380. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1381. if ($result) {
  1382. $result->context = $context;
  1383. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1384. $result->grade = 0;
  1385. if ($result->type_iassign == 1) {
  1386. $result->automatic_evaluate = 0;
  1387. $result->show_answer = 0;
  1388. }
  1389. elseif ($result->automatic_evaluate == 0)
  1390. $result->show_answer = 0;
  1391. // $_POST['iassign_list']
  1392. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1393. if ($result->iassign_list) {
  1394. foreach ($result->iassign_list as $key => $value)
  1395. $result->dependency .= $key . ';';
  1396. }
  1397. else
  1398. $result->dependency = 0;
  1399. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1400. //TODO Then get it directly from the form data $_POST!
  1401. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1402. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1403. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1404. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1405. if ($this->action == 'add') {
  1406. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1407. if ($iassign_statement_name) {
  1408. $this->return_home_course('error_iassign_name');
  1409. die();
  1410. }
  1411. // Really insert the new iActivity in table '*_iassign_statement'
  1412. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1413. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1414. // Trigger module viewed event.
  1415. $event = \mod_iassign\event\iassign_created::create(array(
  1416. 'objectid' => $iassignid,
  1417. 'context' => $context
  1418. ));
  1419. $event->add_record_snapshot('course', $this->course);
  1420. $event->trigger();
  1421. $this->return_home_course('iassign_add');
  1422. } // if ($this->action == 'add')
  1423. elseif ($this->action == 'edit') {
  1424. $iassignid = $this->activity->update_iassign($result);
  1425. $this->activity->update_calendar($iassignid, $result->oldname);
  1426. // Trigger module viewed event.
  1427. $event = \mod_iassign\event\iassign_updated::create(array(
  1428. 'objectid' => $iassignid,
  1429. 'context' => $context
  1430. ));
  1431. $event->add_record_snapshot('course', $this->course);
  1432. $event->trigger();
  1433. $this->return_home_course('iassign_update');
  1434. } // elseif ($this->action == 'edit')
  1435. die();
  1436. } // if ($result)
  1437. } // else if ($mform->is_cancelled())
  1438. print $OUTPUT->header();
  1439. $mform->display();
  1440. print $OUTPUT->footer();
  1441. die();
  1442. } // function add_edit_iassign()
  1443. /// Search for dependencies
  1444. function search_dependency ($search_iassing_id, $iassign_statement) {
  1445. global $DB, $OUTPUT;
  1446. $dependency = "";
  1447. if ($iassign_statement)
  1448. foreach ($iassign_statement as $iassign) {
  1449. $inter_dependency = explode(';', $iassign->dependency);
  1450. if (in_array($search_iassing_id, $inter_dependency)) {
  1451. $dependency .= $iassign->id . ";";
  1452. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1453. } // if (in_array($search_iassing_id, $inter_dependency))
  1454. } // foreach ($iassign_statement as $iassign)
  1455. return $dependency;
  1456. }
  1457. /// Search for "sub"dependency
  1458. function search_sub_dependency ($search_iassing_id) {
  1459. global $DB, $OUTPUT;
  1460. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1461. $dependency = "";
  1462. if ($iassign_statement) {
  1463. $inter_dependency = explode(';', $iassign_statement->dependency);
  1464. foreach ($inter_dependency as $tmp) {
  1465. if ($tmp != 0)
  1466. $dependency .= $tmp . ";";
  1467. $dependency .= $this->search_sub_dependency($tmp);
  1468. } // foreach ($inter_dependency as $tmp)
  1469. } // if ($iassign_statement)
  1470. return $dependency;
  1471. }
  1472. // Warning message
  1473. static function warning_message_iassign ($strcode) {
  1474. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1475. }
  1476. /// Update grade of iAssign
  1477. // Called always any iAssign activity is created
  1478. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1479. static function update_grade_iassign ($iassignid) {
  1480. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1481. require_once($CFG->libdir . '/gradelib.php');
  1482. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1483. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1484. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1485. // Each iAssign item is associated with one item on the "gradebook"
  1486. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1487. //$sum_grade = 0;
  1488. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1489. //foreach($grade as $tmp) {
  1490. // $sum_grade += $tmp->grade;
  1491. // }
  1492. //1 Solution 1
  1493. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1494. //1 $sum_grade = 0; //1
  1495. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1496. //2 Solution 2
  1497. $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
  1498. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1499. if (key($array_sum_grade))
  1500. $sum_grade = key($array_sum_grade); //2
  1501. else
  1502. $sum_grade = 0; //2
  1503. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1504. $grades = NULL;
  1505. $params = array('itemname' => $grade_iassign->name);
  1506. $params['iteminstance'] = $iassignid;
  1507. $params['gradetype'] = GRADE_TYPE_VALUE;
  1508. //2016 if ($sum_grade != 0) {
  1509. $params['grademax'] = $sum_grade;
  1510. $params['rawgrademax'] = $sum_grade;
  1511. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1512. $params['grademin'] = 0;
  1513. // @calls /lib/gradelib.php: call to grade_item->insert()
  1514. //TODO: is there any error here in Moodle version 3.0?
  1515. //TODO: Incorrect property 'grademax' found when inserting grade object
  1516. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1517. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1518. }
  1519. /// Update grade of student
  1520. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1521. global $CFG, $DB, $OUTPUT;
  1522. require_once($CFG->libdir . '/gradelib.php');
  1523. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1524. // Review all the student submission for this iAssign activity
  1525. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1526. $total_grade = 0;
  1527. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1528. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1529. if ($iassign_submission)
  1530. $total_grade += $iassign_submission->grade;
  1531. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1532. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1533. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1534. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1535. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1536. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1537. $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
  1538. if (key($array_sum_grade))
  1539. $sum_grade = key($array_sum_grade); //2
  1540. else
  1541. $sum_grade = 0; //2
  1542. $grades['userid'] = $userid;
  1543. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1544. $params = array('itemname' => $grade_iassign->name);
  1545. $params['iteminstance'] = $iassignid;
  1546. $params['gradetype'] = GRADE_TYPE_VALUE;
  1547. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1548. $params['grademax'] = $sum_grade;
  1549. $params['rawgrademax'] = $sum_grade;
  1550. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1551. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1552. }
  1553. /// Display caption of icons
  1554. function view_legend_icons () {
  1555. global $USER, $CFG, $DB, $OUTPUT;
  1556. $id = $this->cm->id;
  1557. if ($this->action == 'print')
  1558. print '<table border=1 width=100%><tr>';
  1559. else
  1560. print '<table width=100%><tr>';
  1561. print '<td >';
  1562. if ($this->action != 'print')
  1563. print $OUTPUT->help_icon('legend', 'iassign');
  1564. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1565. // $imagetext = '');
  1566. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1567. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1568. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1569. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1570. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1571. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1572. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1573. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1574. print '</td>' . "\n";
  1575. if ($this->action != 'print') {
  1576. $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>";
  1577. $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>";
  1578. $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>";
  1579. $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>";
  1580. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1581. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1582. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1583. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1584. } // if ($this->action != 'print')
  1585. print '</tr></table>' . "\n";
  1586. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1587. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1588. $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>";
  1589. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1590. print '</tr></table>' . "\n";
  1591. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1592. else
  1593. print '</td></tr></table>' . "\n";
  1594. } // function view_legend_icons()
  1595. /// Display activity current
  1596. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1597. function view_iassign_current () {
  1598. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1599. $id = $this->cm->id;
  1600. $iassignid = $this->iassign->id;
  1601. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1602. $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
  1603. // 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 ...
  1604. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1605. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1606. $ilm_name = '';
  1607. if ($ilm->ilm)
  1608. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1609. // 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
  1610. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1611. // log record
  1612. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1613. //Trigger module viewed event.
  1614. $event = \mod_iassign\event\submission_viewed::create(array(
  1615. 'objectid' => $iassign->id,
  1616. 'context' => $this->context,
  1617. 'other' => $info
  1618. ));
  1619. $event->add_record_snapshot('course', $this->course);
  1620. $event->trigger();
  1621. // Search of iLM data used in the current activity
  1622. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1623. // Add actual activity to navbar:
  1624. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1625. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1626. print $OUTPUT->header();
  1627. if ($this->action == 'viewsubmission') {
  1628. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1629. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1630. else
  1631. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1632. } else {
  1633. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1634. }
  1635. if ($iassign_submission)
  1636. $this->update_comment($iassign_submission->id);
  1637. $file = $iassign_statement_activity_item->file;
  1638. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1639. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1640. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1641. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1642. $this->bottonPost = 0; // hide submit button
  1643. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1644. $this->view_iassign = false; // disable visualization of activity
  1645. $repeat = "";
  1646. $last_iassign = "";
  1647. $student_answer = "";
  1648. $comment = "";
  1649. // *** Teacher access (view learner's submission)
  1650. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1651. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1652. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1653. // ---> access teacher for test
  1654. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1655. $this->bottonPost = 1;
  1656. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1657. $this->activity->view_dates();
  1658. $USER->iassignEdit = $this->bottonPost;
  1659. $this->activity->show_info_iassign();
  1660. if ($iassign_submission) {
  1661. //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;
  1662. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1663. } else {
  1664. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1665. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1666. }
  1667. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1668. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1669. // Prepare tags to present the iLM
  1670. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1671. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1672. // *** (end) Teacher access (view the activity)
  1673. // *** Teacher access (view learner's submission to the activity)
  1674. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1675. // It is teacher or 'nonediting teacher' that can evaluate
  1676. // ----> area teacher evaluate
  1677. $row = optional_param('row', 0, PARAM_INT);
  1678. $column = optional_param('column', 0, PARAM_INT);
  1679. $link_next = iassign_icons::insert('right_disable');
  1680. $link_previous = iassign_icons::insert('left_disable');
  1681. $link_up = iassign_icons::insert('up_disable');
  1682. $link_down = iassign_icons::insert('down_disable');
  1683. // next_activity
  1684. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1685. $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);
  1686. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1687. }
  1688. // previous_activity
  1689. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1690. $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);
  1691. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1692. }
  1693. // previous_student
  1694. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1695. $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);
  1696. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1697. }
  1698. // next_student
  1699. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1700. $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);
  1701. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1702. }
  1703. if ($iassign_submission) {
  1704. $student_answer = $iassign_submission->answer;
  1705. }
  1706. $last_iassign = get_string('last_iassign', 'iassign');
  1707. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1708. // Messages related to due date (and user role)
  1709. $this->activity->view_dates();
  1710. print $OUTPUT->box_start();
  1711. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1712. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1713. print $OUTPUT->user_picture($user_data);
  1714. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1715. print '</td>' . "\n";
  1716. print '<td width=20% align=right>' . "\n";
  1717. print '<table width=50 cellpadding="0">';
  1718. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1719. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1720. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1721. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1722. print '</table>' . "\n";
  1723. print '</td></tr></table>' . "\n";
  1724. print $OUTPUT->box_end();
  1725. print $OUTPUT->box_start();
  1726. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1727. print '<td width=60% valign="top">' . "\n";
  1728. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1729. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1730. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1731. $resp = get_string('yes');
  1732. else
  1733. $resp = get_string('no');
  1734. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1735. if ($iassign_statement_activity_item->show_answer == 1)
  1736. $resp = get_string('yes');
  1737. else
  1738. $resp = get_string('no');
  1739. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1740. print '</td>';
  1741. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1742. print '<td width=40% valign="top" align="left">';
  1743. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1744. // check status of solution sent by the student
  1745. if ($iassign_submission) {
  1746. switch ($iassign_submission->status) {
  1747. case 3 :
  1748. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1749. break;
  1750. case 2 :
  1751. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1752. break;
  1753. case 1 :
  1754. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1755. break;
  1756. default :
  1757. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1758. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1759. } // switch ($iassign_submission->status)
  1760. }
  1761. else { // if ($iassign_submission)
  1762. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1763. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1764. }
  1765. // update_status
  1766. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1767. $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);
  1768. print " <script type='text/javascript'>
  1769. //<![CDATA[
  1770. function overwriteStatus (newstatus) {
  1771. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1772. document.formEditStatus.return_status.value=newstatus;
  1773. document.formEditStatus.submit();
  1774. }
  1775. else
  1776. document.formEditStatus.return_status.value=-1;
  1777. }
  1778. //]]>
  1779. </script>";
  1780. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1781. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1782. 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";
  1783. print " <input type='hidden' name='return_status'>\n";
  1784. print "</form>\n";
  1785. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1786. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1787. $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);
  1788. print "
  1789. <script type='text/javascript'>
  1790. //<![CDATA[
  1791. function overwriteGrade (newgrade,maxgrade) {
  1792. if (newgrade<0 || newgrade>maxgrade) {
  1793. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1794. document.formEditGrade.return_grade.value=-1;
  1795. document.formEditGrade.submit();
  1796. }
  1797. else {
  1798. document.formEditGrade.return_grade.value=newgrade;
  1799. document.formEditGrade.submit();
  1800. }
  1801. }
  1802. //]]>
  1803. </script>";
  1804. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1805. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1806. print " <input type='text' name='grade' size='6'>";
  1807. print " <input type='hidden' name='return_grade'> ";
  1808. 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";
  1809. print "</form>";
  1810. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1811. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1812. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1813. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1814. if ($teacher)
  1815. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1816. } // if ($iassign_submission->experiment > 0)
  1817. print '</td>';
  1818. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1819. print '</tr></table>';
  1820. print $OUTPUT->box_end();
  1821. $USER->iassignEdit = $this->bottonPost;
  1822. if ($iassign_submission && $allow_resubmission) {
  1823. // Put the iLM to
  1824. print $OUTPUT->box_start();
  1825. print '<p><strong>' . $last_iassign . '</strong></p>';
  1826. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1827. $enderecoPOST = "";
  1828. // Prepare tags to present the iLM
  1829. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1830. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1831. print $OUTPUT->box_end();
  1832. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1833. // ATTENTION: exception used by iGeom (exercise with "script")
  1834. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1835. if (substr($ilm_name, 0, 5)=="igeom") {
  1836. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1837. $loadTeacherActivity = true;
  1838. }
  1839. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1840. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1841. // Prepare tags to present the iLM
  1842. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1843. }
  1844. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1845. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1846. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1847. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1848. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1849. // *** (end) Teacher access (view learner's submission to the activity)
  1850. // *** Student access (view the activity)
  1851. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1852. // It could be the learner (he could send or resend the activity)
  1853. // ---> access student
  1854. $time_now = time();
  1855. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1856. // activity of type example - not submit button for submission
  1857. $this->view_iassign = true;
  1858. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1859. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1860. // activity of type test - iLM automatic evaluator - submit button for submission
  1861. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1862. $this->bottonPost = 1;
  1863. $this->view_iassign = true;
  1864. } else
  1865. $this->view_iassign = false;
  1866. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1867. // activity of type exercise (learner can send his answer, if yet open...)
  1868. $this->view_iassign = true;
  1869. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1870. $this->view_iassign = false;
  1871. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1872. $this->bottonPost = 1; // allow the submit button
  1873. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1874. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1875. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1876. if (!$iassign_submission) {
  1877. $str_iassign_submission_id = '';
  1878. $str_iassign_submission_answer = '';
  1879. }
  1880. else {
  1881. $str_iassign_submission_id = $iassign_submission->id;
  1882. $str_iassign_submission_answer = $iassign_submission->answer;
  1883. }
  1884. if ($this->action != 'repeat') {
  1885. $repeat = "<a href='view.php?action=repeat&id="
  1886. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1887. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1888. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1889. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1890. }
  1891. $this->bottonPost = 1;
  1892. $this->write_solution = 1; // can register his submission
  1893. $student_answer = $str_iassign_submission_answer;
  1894. }
  1895. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1896. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1897. $last_iassign = get_string('last_iassign', 'iassign');
  1898. if ($iassign_submission) {
  1899. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1900. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1901. $student_answer = $iassign_submission->answer;
  1902. } else {
  1903. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1904. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1905. }
  1906. }
  1907. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1908. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1909. $this->bottonPost = 1;
  1910. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1911. } else {
  1912. $last_iassign = get_string('last_iassign', 'iassign');
  1913. if ($iassign_submission) {
  1914. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1915. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1916. $student_answer = $iassign_submission->answer;
  1917. } else {
  1918. // Symbol of "redo activity"
  1919. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1920. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1921. }
  1922. }
  1923. } // elseif ($iassign_statement_activity_item->test == 1)
  1924. elseif ($iassign_statement_activity_item->test == 0)
  1925. $this->view_iassign = false;
  1926. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1927. if ($iassign_submission)
  1928. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1929. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1930. else
  1931. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1932. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1933. $this->activity->view_dates();
  1934. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1935. print $OUTPUT->box_start();
  1936. print '<table width=100% border=0 valign="top">' . "\n";
  1937. print '<tr><td width=60% valign="top">' . "\n";
  1938. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1939. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1940. $flag_dependency = true;
  1941. if ($iassign_statement_activity_item->type_iassign == 3) {
  1942. if ($iassign_statement_activity_item->dependency == 0) {
  1943. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1944. } else {
  1945. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1946. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1947. foreach ($dependencys as $dependency) {
  1948. if ($dependency) {
  1949. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1950. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1951. if ($dependencysubmissions) {
  1952. if ($dependencysubmissions->status == 3)
  1953. $icon = iassign_icons::insert('correct');
  1954. elseif ($dependencysubmissions->status == 2) {
  1955. $icon = iassign_icons::insert('incorrect');
  1956. $flag_dependency = false;
  1957. } elseif ($dependencysubmissions->status == 1) {
  1958. $icon = iassign_icons::insert('post');
  1959. $flag_dependency = false;
  1960. } elseif ($dependencysubmissions->status == 0) {
  1961. $icon = iassign_icons::insert('not_post');
  1962. $flag_dependency = false;
  1963. }
  1964. } else {
  1965. $icon = iassign_icons::insert('not_post');
  1966. $flag_dependency = false;
  1967. } // if ($dependencysubmissions)
  1968. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1969. } // if ($dependency)
  1970. } // foreach ($dependencys as $dependency)
  1971. } // if ($iassign_statement_activity_item->dependency == 0)
  1972. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1973. if ($flag_dependency == false) {
  1974. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1975. $this->view_iassign = false;
  1976. print '</tr></table>' . "\n";
  1977. }
  1978. else {
  1979. $this->view_iassign = true;
  1980. print '</td>' . "\n";
  1981. } // if ($flag_dependency == false)
  1982. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1983. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1984. // receiver=1 - message to teacher
  1985. // receiver=2 - message to student
  1986. if ($iassign_submission) {
  1987. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1988. if ($verify_message)
  1989. $comment = iassign_icons::insert('comment_unread');
  1990. }
  1991. print '<td width=40% valign="top" align="left">';
  1992. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1993. if ($iassign_statement_activity_item->show_answer == 1) {
  1994. // check status of solution sent by the student
  1995. if ($iassign_submission) {
  1996. switch ($iassign_submission->status) {
  1997. case 3 :
  1998. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1999. break;
  2000. case 2 :
  2001. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2002. break;
  2003. case 1 :
  2004. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2005. break;
  2006. default :
  2007. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2008. $repeat = "";
  2009. $last_iassign = "";
  2010. } // switch ($iassign_submission->status)
  2011. } else {
  2012. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2013. $repeat = "";
  2014. $last_iassign = "";
  2015. }
  2016. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2017. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2018. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2019. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2020. if ($iassign_statement_activity_item->max_experiment == 0)
  2021. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2022. else {
  2023. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2024. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2025. $repeat = "";
  2026. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2027. $this->bottonPost = 0;
  2028. $this->write_solution = 0;
  2029. }
  2030. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2031. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2032. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2033. if ($teacher)
  2034. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2035. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2036. } // if ($iassign_statement_activity_item->show_answer==1)
  2037. else {
  2038. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2039. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2040. $repeat = "";
  2041. $last_iassign = "";
  2042. } elseif ($iassign_submission->status == 1) {
  2043. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2044. }
  2045. }
  2046. print '</td>';
  2047. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2048. print '</tr></table>' . "\n";
  2049. // Presents the iLM
  2050. print '<table width=100% border=0 valign="top">' . "\n";
  2051. print '<td width=80% align="left">';
  2052. 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\".
  2053. print '<td width=20% align="rigth">';
  2054. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2055. print $repeat; // symbol of "redo activity"
  2056. print '</td></tr></table>' . "\n";
  2057. //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)'
  2058. $output = '';
  2059. if (!$iassign_ilm) {
  2060. $iassign_ilm = new stdClass();
  2061. $iassign_ilm->file_jar = "";
  2062. }
  2063. $output .= $OUTPUT->box_start();
  2064. $USER->iassignEdit = $this->bottonPost;
  2065. // ---
  2066. // Presents the iLM
  2067. // Prepare tags to present the iLM
  2068. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2069. $student_answer = ""; //?
  2070. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2071. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2072. $student_answer = "";
  2073. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2074. } else {
  2075. // When student is redoing his activity
  2076. // ATTENTION: exception used by iGeom (exercise with "script")
  2077. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2078. if (substr($ilm_name, 0, 5)=="igeom") {
  2079. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2080. $loadTeacherActivity = true;
  2081. }
  2082. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2083. }
  2084. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2085. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2086. //1 $history_comment = '';
  2087. //1 if ($iassign_submission) {
  2088. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2089. //1 }
  2090. //1 if (!empty($history_comment)) {
  2091. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2092. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2093. //1 $output .= $history_comment;
  2094. //1 $output .= "</table>\n";
  2095. //1 }
  2096. //1 $output .= "</form></center>\n";
  2097. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2098. //1 }
  2099. $output .= $OUTPUT->box_end();
  2100. print $output;
  2101. } // if ($this->view_iassign)
  2102. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2103. } // if ($this->view_iassign)
  2104. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2105. else
  2106. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2107. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2108. print '<table width=100% border=0 valign="top">' . "\n";
  2109. print '<tr><td width=60% valign="top">' . "\n";
  2110. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2111. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2112. print '</tr></table>' . "\n";
  2113. $student_answer = "";
  2114. $enderecoPOST = "";
  2115. // Prepare tags to present the iLM
  2116. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2117. print $output;
  2118. }
  2119. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2120. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2121. 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
  2122. // Put a block with area to sent/answer comments
  2123. $output = '';
  2124. $history_comment = '';
  2125. $row = optional_param('row', 0, PARAM_INT);
  2126. $column = optional_param('column', 0, PARAM_INT);
  2127. if ($iassign_submission) {
  2128. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2129. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2130. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2131. }
  2132. else {
  2133. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2134. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2135. }
  2136. $output .= $OUTPUT->box_start();
  2137. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  2138. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2139. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2140. $output .= "</form></center>\n";
  2141. if (!empty($history_comment)) {
  2142. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2143. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2144. $output .= $history_comment;
  2145. $output .= "</table>";
  2146. }
  2147. $output .= $OUTPUT->box_end();
  2148. print $output;
  2149. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2150. // final block 'studant'
  2151. print $OUTPUT->footer();
  2152. die();
  2153. } // function view_iassign_current()
  2154. /// Export the data from performance report into CSV file format
  2155. function export_csv () {
  2156. global $USER, $CFG, $DB, $OUTPUT;
  2157. $str = "";
  2158. $fields = "student_id, student_name";
  2159. // Finding all iassign activities for the iassign:
  2160. $id = $this->cm->id;
  2161. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2162. $c = 1;
  2163. foreach ($iassign_list as $iassign) {
  2164. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2165. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2166. $c ++;
  2167. }
  2168. // Finding enrolled students:
  2169. $params = array('shortname' => 'student');
  2170. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2171. $context = context_course::instance($this->course->id);
  2172. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2173. $students = $DB->get_records_sql(
  2174. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2175. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2176. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2177. foreach ($students as $student) {
  2178. $str .= $student->userid . ',';
  2179. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2180. foreach ($iassign_list as $iassign) {
  2181. $str .= ',' . $iassign->id . ',';
  2182. $str .= '"' . $iassign->name . '",';
  2183. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2184. if ($student_submissions) {
  2185. $str .= $student_submissions->experiment . ',';
  2186. $str .= $student_submissions->grade . ',';
  2187. switch ($student_submissions->status) {
  2188. case 3:
  2189. $str .= '"correct",';
  2190. break;
  2191. case 2:
  2192. $str .= '"incorrect",';
  2193. break;
  2194. case 1:
  2195. $str .= '"post",';
  2196. break;
  2197. case 0:
  2198. $str .= '"not_post",';
  2199. break;
  2200. }
  2201. } else {
  2202. $str .= ',,"not_post",';
  2203. }
  2204. $str .= $iassign->iassign_ilmid . ',';
  2205. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2206. $str .= '"' . $ilm_activity->name . '"';
  2207. }
  2208. $str .= "\n";
  2209. }
  2210. $str = $fields . "\n" . $str;
  2211. header("Content-type: text/csv");
  2212. header("Content-disposition: attachment; filename=report.csv");
  2213. header("Pragma: no-cache");
  2214. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2215. header('Content-Length: ' . strlen($str));
  2216. header('Connection: close');
  2217. print $str;
  2218. flush();
  2219. } // function export_csv()
  2220. /// Display report of performance
  2221. function report () {
  2222. global $USER, $CFG, $DB, $OUTPUT;
  2223. $id = $this->cm->id;
  2224. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2225. if ($this->action != 'print') {
  2226. $title = get_string('report', 'iassign');
  2227. print $OUTPUT->header();
  2228. } // if ($this->action != 'print')
  2229. print $OUTPUT->box_start();
  2230. $this->view_legend_icons();
  2231. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2232. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2233. print $OUTPUT->box_end();
  2234. if ($this->action == 'print')
  2235. print '<table border=1 width="100%">' . "\n";
  2236. else
  2237. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2238. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2239. // $num = array();
  2240. $i = 1;
  2241. $num = array();
  2242. foreach ($iassign_list as $iassign) {
  2243. $test_exercise = "";
  2244. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2245. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2246. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2247. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2248. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2249. $num[$i] = new stdClass();
  2250. $num[$i]->name = $iassign->name;
  2251. $num[$i]->id = $i;
  2252. $num[$i]->iassignid = $iassign->id;
  2253. print ' <tr >' . "\n";
  2254. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2255. print "<td class=\"cell c0 actvity\">";
  2256. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2257. print ' </tr>' . "\n";
  2258. $i ++;
  2259. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2260. } // foreach ($iassign_list as $iassign)
  2261. print "</table>";
  2262. print "<p></p>";
  2263. if ($this->action == 'print')
  2264. print '<table border=1 width="100%">' . "\n";
  2265. else
  2266. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2267. $context = context_course::instance($this->course->id);
  2268. if ($i > 1) {
  2269. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2270. $params = array('shortname' => 'student');
  2271. $role = $DB->get_record_sql(
  2272. "SELECT s.id, s.shortname FROM {role} s " .
  2273. " WHERE s.shortname = :shortname", $params);
  2274. // $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");
  2275. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2276. $students = $DB->get_records_sql(
  2277. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2278. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2279. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2280. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2281. for ($j = 1; $j < $i; $j ++) {
  2282. $sum_iassign_correct[$j] = 0;
  2283. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2284. }
  2285. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2286. $sum_iassign = $j - 1;
  2287. print '</tr>' . "\n";
  2288. $total = 0;
  2289. $sum_student = 0;
  2290. $comment = iassign_icons::insert('comment_read');
  2291. $sum_comment = 0;
  2292. $sum_correct_iassign = array();
  2293. $sum_correct_student = array();
  2294. $USER->matrix_iassign = array();
  2295. if ($students) {
  2296. $w = 0;
  2297. foreach ($students as $tmp) {
  2298. $users_array[$w] = $tmp;
  2299. $w ++;
  2300. }
  2301. for ($x = 0; $x < $w; $x ++) {
  2302. print '<tr>' . "\n";
  2303. $sum_student ++;
  2304. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2305. print ' <td >' . $name . '</td>' . "\n";
  2306. $total_student = 0;
  2307. $tentativas = 0;
  2308. for ($j = 1; $j < $i; $j ++) {
  2309. $sum_comment = 0;
  2310. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2311. print ' <td valign="bottom" align="center">' . "\n";
  2312. if ($student_submissions) {
  2313. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2314. $tentativas = $student_submissions->experiment;
  2315. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2316. $params = array('iassign_submissionid' => $student_submissions->id);
  2317. $student_submissions_comment = $DB->get_record_sql(
  2318. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2319. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2320. if ($student_submissions_comment)
  2321. foreach ($student_submissions_comment as $tmp)
  2322. $sum_comment = $tmp;
  2323. // informations to previous activities
  2324. if ($j - 1 < 1 || $j == $i)
  2325. $iassign_previous = "-1";
  2326. else
  2327. $iassign_previous = $num[$j - 1]->iassignid;
  2328. if ($x - 1 < 0 || $x == $w)
  2329. $user_previous = "-1";
  2330. else
  2331. $user_previous = $users_array[$x - 1]->userid;
  2332. // next
  2333. if ($i - 1 > $j)
  2334. $iassign_next = $num[$j + 1]->iassignid;
  2335. else
  2336. $iassign_next = "-1";
  2337. if ($w - 1 > $x)
  2338. $user_next = $users_array[$x + 1]->userid;
  2339. else
  2340. $user_next = "-1";
  2341. $position = "&row= $x&column=$j";
  2342. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2343. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2344. $url .= $position;
  2345. // receiver=1 - message to teacher
  2346. // receiver=2 - message to student
  2347. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2348. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2349. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2350. $verify_message = $DB->get_record_sql(
  2351. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2352. "WHERE iassign_submissionid = :iassign_submissionid " .
  2353. " AND return_status= :return_status " .
  2354. " AND receiver= :receiver", $params);
  2355. if ($verify_message)
  2356. foreach ($verify_message as $tmp)
  2357. $sum_verify_message = $tmp;
  2358. if ($sum_verify_message > 0)
  2359. $comment = iassign_icons::insert('comment_unread');
  2360. else
  2361. $comment = iassign_icons::insert('comment_read');
  2362. if ($student_submissions->status == 3) {
  2363. $sum_iassign_correct[$j] ++;
  2364. $total_student ++;
  2365. $feedback = iassign_icons::insert('correct');
  2366. }
  2367. elseif ($student_submissions->status == 2) {
  2368. $feedback = iassign_icons::insert('incorrect');
  2369. }
  2370. elseif ($student_submissions->status == 1) {
  2371. $feedback = iassign_icons::insert('post');
  2372. }
  2373. elseif ($student_submissions->status == 0) {
  2374. $feedback = iassign_icons::insert('not_post');
  2375. }
  2376. if ($this->action != 'print') {
  2377. print '<table><tr>';
  2378. if ($tentativas > 0)
  2379. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2380. else
  2381. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2382. print '<td> &nbsp; </td>';
  2383. print '</tr>' . "\n";
  2384. if ($sum_comment > 0 && $sum_verify_message > 0)
  2385. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2386. else if ($sum_comment > 0)
  2387. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2388. print '</table>' . "\n";
  2389. }
  2390. if ($this->action == 'print')
  2391. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2392. } // if ($student_submissions)
  2393. else { // if ($student_submissions)
  2394. // informations to browse previous activities
  2395. if ($j - 1 < 1 || $j == $i)
  2396. $iassign_previous = "-1";
  2397. else
  2398. $iassign_previous = $num[$j - 1]->iassignid;
  2399. if ($x - 1 < 0 || $x == $w)
  2400. $user_previous = "-1";
  2401. else
  2402. $user_previous = $users_array[$x - 1]->userid;
  2403. // next
  2404. if ($i - 1 > $j)
  2405. $iassign_next = $num[$j + 1]->iassignid;
  2406. else
  2407. $iassign_next = "-1";
  2408. if ($w - 1 > $x)
  2409. $user_next = $users_array[$x + 1]->userid;
  2410. else
  2411. $user_next = "-1";
  2412. $position = "&row= $x&column=$j";
  2413. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2414. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2415. $url .= $position;
  2416. $feedback = iassign_icons::insert('not_post');
  2417. if ($this->action == 'print')
  2418. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2419. else {
  2420. print '<table><tr>';
  2421. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2422. print '<td> &nbsp; </td>';
  2423. print '</tr><tr>' . "\n";
  2424. print '<td> &nbsp;</td>';
  2425. if ($sum_comment > 0)
  2426. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2427. else
  2428. print '<td> &nbsp;</td>';
  2429. print '</tr></table>';
  2430. }
  2431. } // else if ($student_submissions)
  2432. $USER->matrix_iassign[$x][$j] = new stdClass();
  2433. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2434. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2435. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2436. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2437. if ($student_submissions)
  2438. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2439. else
  2440. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2441. print '</td>' . "\n";
  2442. } // for ($j=1; $j<$i; $j++)
  2443. $total = $total + $total_student;
  2444. $porcentagem = ($total_student / ($j - 1)) * 100;
  2445. if ($tentativas != 0 && $tentativas != null) {
  2446. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2447. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2448. }
  2449. else {
  2450. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2451. }
  2452. print '</tr>' . "\n";
  2453. $sum_correct_student[$sum_student] = new stdClass();
  2454. $sum_correct_student[$sum_student]->name = $name;
  2455. $sum_correct_student[$sum_student]->sum = $total_student;
  2456. } // for ($x = 0; $x < $w; $x ++)
  2457. for ($i = 1; $i < $j; $i ++) {
  2458. if (is_null($sum_iassign_correct[$i]))
  2459. $sum_iassign_correct[$i] = 0;
  2460. $sum_correct_iassign[$i] = new stdClass();
  2461. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2462. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2463. }
  2464. // print '</tr></table>' . "\n";
  2465. }
  2466. } // if ($i>1)
  2467. else {
  2468. print_string('no_activity', 'iassign');
  2469. }
  2470. print "</table>\n";
  2471. if ($this->action != 'print')
  2472. print $OUTPUT->footer();
  2473. die();
  2474. } // function report()
  2475. /// Display graphics of performance
  2476. function stats () {
  2477. global $USER, $CFG, $DB, $OUTPUT;
  2478. $id = $this->cm->id;
  2479. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2480. if ($this->action != 'printstats')
  2481. $title = get_string('graphic', 'iassign');
  2482. $num = array();
  2483. $sum_correct_iassign = array();
  2484. $sum_correct_student = array();
  2485. $sum_student = 0;
  2486. $i = 1;
  2487. foreach ($iassign_list as $iassign) {
  2488. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2489. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2490. $sum_iassign_correct[$i] = 0;
  2491. $num[$i] = new stdClass();
  2492. $num[$i]->name = $iassign->name;
  2493. $num[$i]->id = $i;
  2494. $num[$i]->iassignid = $iassign->id;
  2495. $i ++;
  2496. } // if ($iassign->type_iassign == 3)
  2497. } // foreach ($iassign_list as $iassign)
  2498. $sum_iassign = $i - 1;
  2499. $context = context_course::instance($this->course->id);
  2500. if ($i > 1) {
  2501. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2502. $params = array('shortname' => 'student');
  2503. $role = $DB->get_record_sql(
  2504. "SELECT s.id, s.shortname FROM {role} s " .
  2505. " WHERE s.shortname = :shortname", $params);
  2506. // $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");
  2507. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2508. $students = $DB->get_records_sql(
  2509. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2510. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2511. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2512. $total = 0;
  2513. $sum_student = 0;
  2514. $j = 0;
  2515. $sum_correct_iassign = array();
  2516. $sum_correct_student = array();
  2517. $sum_experiment = array();
  2518. if ($students) {
  2519. foreach ($students as $users) {
  2520. $sum_student ++;
  2521. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2522. // rows
  2523. $total_student = 0;
  2524. for ($j = 1; $j < $i; $j ++) {
  2525. $total_experiment = 0;
  2526. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2527. if ($student_submissions) {
  2528. if ($student_submissions->status == 3) {
  2529. $sum_iassign_correct[$j] ++;
  2530. $total_student ++;
  2531. } // if ($student_submissions->status == 3)
  2532. $total_experiment += $student_submissions->experiment;
  2533. }
  2534. $sum_experiment[$j] = $total_experiment;
  2535. } // for ($j=1; $j<$i; $j++)
  2536. $total = $total + $total_student;
  2537. $sum_correct_student[$sum_student] = new stdClass();
  2538. $sum_correct_student[$sum_student]->name = $name;
  2539. $sum_correct_student[$sum_student]->sum = $total_student;
  2540. } // foreach ($students as $users)
  2541. }
  2542. for ($i = 1; $i < $j; $i ++) {
  2543. if (is_null($sum_iassign_correct[$i]))
  2544. $sum_iassign_correct[$i] = 0;
  2545. $sum_correct_iassign[$i] = new stdClass();
  2546. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2547. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2548. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2549. } // for ($i = 1; $i < $j; $i++)
  2550. } // if ($i > 1)
  2551. if ($this->action != 'printstats') {
  2552. $title = get_string('graphic', 'iassign');
  2553. print $OUTPUT->header();
  2554. $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>";
  2555. $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>";
  2556. print '<table width=100%><tr>';
  2557. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2558. print '<td width=15% align="right">' . $link_report . '</td>';
  2559. print '</td></tr></table>' . "\n";
  2560. print "<br><br>";
  2561. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2562. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2563. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2564. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2565. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2566. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2567. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2568. print '</tr>' . "\n";
  2569. $sum_correct = 0;
  2570. if ($sum_correct_iassign) {
  2571. foreach ($sum_correct_iassign as $iassign) {
  2572. if (is_null($iassign->experiment))
  2573. $iassign->experiment = 0;
  2574. $bar = "";
  2575. $sum = $iassign->sum;
  2576. $percent = ($sum / $sum_student) * 100;
  2577. $text = number_format($percent, 1) . '%';
  2578. $sum_correct += $sum;
  2579. if ($sum > 0) {
  2580. for ($i = 1; $i < $percent * 2; $i ++)
  2581. $bar .= iassign_icons::insert('hbar_blue');
  2582. $bar .= iassign_icons::insert('hbar_blue_r');
  2583. } // if ($sum > 0)
  2584. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2585. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2586. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2587. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2588. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2589. print '</tr>' . "\n";
  2590. } // foreach ($sum_correct_iassign as $iassign)
  2591. }
  2592. print "</table>";
  2593. print "<br><br>";
  2594. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2595. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2596. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2597. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2598. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2599. print '</tr>' . "\n";
  2600. $sum_correct = 0;
  2601. foreach ($sum_correct_student as $student) {
  2602. $bar = "";
  2603. $sum = $student->sum;
  2604. $percent = ($sum / $sum_iassign) * 100;
  2605. $text = number_format($percent, 1) . '%';
  2606. $sum_correct += $sum;
  2607. if ($sum > 0) {
  2608. for ($i = 1; $i < $percent * 2; $i ++)
  2609. $bar .= iassign_icons::insert('hbar_blue');
  2610. $bar .= iassign_icons::insert('hbar_blue_r');
  2611. } // if ($sum > 0)
  2612. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2613. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2614. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2615. print '</tr>' . "\n";
  2616. } // foreach ($sum_correct_student as $student)
  2617. print "</table>\n";
  2618. print "<br><br>\n";
  2619. $var = 0;
  2620. $cv = 0;
  2621. $dv = 0;
  2622. $avg = 0;
  2623. if ($sum_correct_student) {
  2624. $avg = $sum_correct / $sum_student;
  2625. if ($avg > 0) {
  2626. foreach ($sum_correct_student as $student)
  2627. $var += pow($student->sum - $avg, 2);
  2628. $var = $var / $sum_student;
  2629. $dv = sqrt($var);
  2630. $cv = ($dv / $avg) * 100;
  2631. }
  2632. }
  2633. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2634. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2635. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2636. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2637. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2638. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2639. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2640. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2641. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2642. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2643. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2644. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2645. print "</table>\n";
  2646. print $OUTPUT->footer();
  2647. } else {
  2648. print "<STYLE TYPE='text/css'>
  2649. <!--
  2650. .boldtable {
  2651. font-family:sans-serif;
  2652. font-size:10pt;
  2653. }
  2654. -->
  2655. </STYLE>\n";
  2656. print '<table border=1 width=100%>' . "\n";
  2657. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2658. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2659. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2660. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2661. print '</tr>' . "\n";
  2662. $sum_correct = 0;
  2663. foreach ($sum_correct_iassign as $iassign) {
  2664. $bar = "";
  2665. $sum = $iassign->sum;
  2666. $percent = ($sum / $sum_student) * 100;
  2667. $text = number_format($percent, 1) . '%';
  2668. $sum_correct += $sum;
  2669. if ($sum > 0) {
  2670. for ($i = 1; $i < $percent * 2; $i ++)
  2671. $bar .= iassign_icons::insert('hbar_blue');
  2672. $bar .= iassign_icons::insert('hbar_blue_r');
  2673. } // if ($sum > 0)
  2674. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2675. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2676. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2677. print '</tr>' . "\n";
  2678. } // foreach ($sum_correct_iassign as $iassign)
  2679. print "</table>";
  2680. print "<br><br>";
  2681. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2682. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2683. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2684. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2685. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2686. print '</tr>' . "\n";
  2687. $sum_correct = 0;
  2688. foreach ($sum_correct_student as $student) {
  2689. $bar = "";
  2690. $sum = $student->sum;
  2691. $percent = ($sum / $sum_iassign) * 100;
  2692. $text = number_format($percent, 1) . '%';
  2693. $sum_correct += $sum;
  2694. if ($sum > 0) {
  2695. for ($i = 1; $i < $percent * 2; $i ++)
  2696. $bar .= iassign_icons::insert('hbar_blue');
  2697. $bar .= iassign_icons::insert('hbar_blue_r');
  2698. } // if ($sum > 0)
  2699. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2700. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2701. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2702. print '</tr>' . "\n";
  2703. } // foreach ($sum_correct_student as $student)
  2704. print "</table>\n";
  2705. print "<br/><br/>\n";
  2706. $var = 0;
  2707. $cv = 0;
  2708. $dv = 0;
  2709. $avg = 0;
  2710. if ($sum_correct_student) {
  2711. $avg = $sum_correct / $sum_student;
  2712. if ($avg > 0) {
  2713. foreach ($sum_correct_student as $student)
  2714. $var += pow($student->sum - $avg, 2);
  2715. $var = $var / $sum_student;
  2716. $dv = sqrt($var);
  2717. $cv = ($dv / $avg) * 100;
  2718. }
  2719. }
  2720. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2721. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2722. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2723. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2724. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2725. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2726. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2727. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2728. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2729. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2730. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2731. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2732. print "</table>\n";
  2733. } // if ($this->action != 'printstats')
  2734. die();
  2735. }
  2736. /// Display graphics of performance for students
  2737. function stats_students () {
  2738. global $USER, $CFG, $DB, $OUTPUT;
  2739. $id = $this->cm->id;
  2740. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2741. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2742. $title = get_string('results', 'iassign');
  2743. $sum_correct = 0;
  2744. $sum_incorrect = 0;
  2745. $sum_post = 0;
  2746. $sum_nopost = 0;
  2747. $sum_iassign = count($iassign_statement_list);
  2748. $bar_nopost = "";
  2749. $bar_correct = "";
  2750. $bar_incorrect = "";
  2751. $bar_post = "";
  2752. $text_nopost = "";
  2753. $text_correct = "";
  2754. $text_incorrect = "";
  2755. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2756. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2757. if ($iassign_submission) {
  2758. if ($iassign_submission->status == 3)
  2759. $sum_correct ++;
  2760. elseif ($iassign_submission->status == 2)
  2761. $sum_incorrect ++;
  2762. elseif ($iassign_submission->status == 1)
  2763. $sum_post ++;
  2764. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2765. $sum_nopost ++;
  2766. } // if ($iassign_submission)
  2767. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2768. if ($sum_iassign > 0) {
  2769. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2770. $text_correct = number_format($percent_correct, 1) . '%';
  2771. }
  2772. if ($sum_correct > 0) {
  2773. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2774. $bar_correct .= iassign_icons::insert('hbar_green');
  2775. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2776. } // if ($sum_correct > 0)
  2777. if ($sum_iassign > 0) {
  2778. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2779. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2780. }
  2781. if ($sum_incorrect > 0) {
  2782. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2783. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2784. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2785. } // if ($sum_incorrect > 0)
  2786. if ($sum_iassign > 0) {
  2787. $percent_post = ($sum_post / $sum_iassign) * 100;
  2788. $text_post = number_format($percent_post, 1) . '%';
  2789. }
  2790. if ($sum_post > 0) {
  2791. for ($i = 1; $i < $percent_post * 2; $i ++)
  2792. $bar_post .= iassign_icons::insert('hbar_blue');
  2793. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2794. } // if ($sum_post > 0)
  2795. if ($sum_iassign > 0) {
  2796. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2797. $text_nopost = number_format($percent_nopost, 1) . '%';
  2798. }
  2799. if ($sum_nopost > 0) {
  2800. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2801. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2802. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2803. } // if ($sum_nopost > 0)
  2804. print $OUTPUT->header();
  2805. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2806. print '<table width=100%><tr>';
  2807. print '<td align="right">' . $link_return . '</td>' . "\n";
  2808. print '</td></tr></table>' . "\n";
  2809. print "<br/><br/>\n";
  2810. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2811. print '<tr><th colspan=3 class="header c1">' . "\n";
  2812. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2813. // $imagetext = '');
  2814. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2815. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2816. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2817. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2818. print '</tr>' . "\n";
  2819. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2820. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2821. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2822. print '</tr>' . "\n";
  2823. if ($sum_post) {
  2824. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2825. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2826. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2827. print '</tr>' . "\n";
  2828. } // if ($sum_post)
  2829. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2830. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2831. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2832. print '</tr>' . "\n";
  2833. print "</table>";
  2834. print "<br><br>";
  2835. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2836. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2837. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2838. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2839. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2840. $sum_grade = 0;
  2841. $sum_grade_student = 0;
  2842. $avg = 0;
  2843. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2844. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2845. if (!$iassign_submission) {
  2846. $iassign_submission = new stdClass();
  2847. $iassign_submission->grade = 0;
  2848. }
  2849. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2850. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2851. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2852. print '</tr>' . "\n";
  2853. $sum_grade += $iassign_statement_activity_item->grade;
  2854. $sum_grade_student += $iassign_submission->grade;
  2855. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2856. if ($sum_grade > 0)
  2857. $avg = $sum_grade_student / $sum_grade * 100;
  2858. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2859. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2860. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2861. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2862. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2863. print "</table>";
  2864. print $OUTPUT->footer();
  2865. die();
  2866. } // function stats_students()
  2867. /// Display page of iAssign's activity
  2868. function view_iassigns () {
  2869. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2870. $id = $this->cm->id;
  2871. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2872. $notice = optional_param('notice', '', PARAM_TEXT);
  2873. if (strpos($notice, 'error'))
  2874. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2875. else if ($notice != '')
  2876. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2877. print $OUTPUT->box_start();
  2878. print '<table width=100% border=0><tr>' . "\n";
  2879. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2880. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2881. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2882. $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>";
  2883. $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>";
  2884. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2885. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2886. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2887. // Has capability to see "report": teacher or up
  2888. print '<td width=10% align="left">' . "\n";
  2889. print $link_help;
  2890. print '</td>' . "\n";
  2891. print '<td width=10% align="left">' . "\n";
  2892. print $link_report;
  2893. print '</td>' . "\n";
  2894. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2895. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2896. print '<td width=15% align="left">' . "\n";
  2897. print $link_add;
  2898. print "</td>\n";
  2899. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2900. //print '</tr></table>' . "\n";
  2901. print '<div style="float: right;">';
  2902. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2903. if ($iassign_list) {
  2904. print '<td align="right">' . "\n";
  2905. // $USER->iassignEdit == 0 view 'Turn editing off'
  2906. // $USER->iassignEdit == 1 view 'Turn editing on'
  2907. if (!isset($USER->iassignEdit))
  2908. $USER->iassignEdit = 0;
  2909. if ($USER->iassignEdit == 0) {
  2910. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2911. $botton = 1;
  2912. } // if ($USER->iassignEdit == 0)
  2913. elseif ($USER->iassignEdit == 1) {
  2914. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2915. $botton = 0;
  2916. } // elseif ($USER->iassignEdit == 1)
  2917. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2918. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2919. print " <input type=submit value='$bottonEdit_message'/>\n";
  2920. print "</form>\n";
  2921. print "</td>\n";
  2922. } // if ($iassign_list)
  2923. }
  2924. print '</tr></table>' . "\n";
  2925. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2926. // $this->view_legend_icons();
  2927. print $OUTPUT->box_end();
  2928. $iassign_array_exercise = array();
  2929. $i_exercise = 0;
  2930. $iassign_array_test = array();
  2931. $i_test = 0;
  2932. $iassign_array_example = array();
  2933. $i_example = 0;
  2934. $iassign_array_general = array();
  2935. $i_general = 0;
  2936. if ($iassign_list) {
  2937. if ($this->iassign->activity_group == 0) {
  2938. foreach ($iassign_list as $iassign) {
  2939. $iassign_array_general[$i_general] = $iassign;
  2940. $i_general ++;
  2941. }
  2942. } // if ($this->iassign->activity_group == 0)
  2943. else {
  2944. foreach ($iassign_list as $iassign) {
  2945. if ($iassign->type_iassign == 3) {
  2946. $iassign_array_exercise[$i_exercise] = $iassign;
  2947. $i_exercise ++;
  2948. } // if ($iassign->type_iassign == 3)
  2949. if ($iassign->type_iassign == 2) {
  2950. $iassign_array_test[$i_test] = $iassign;
  2951. $i_test ++;
  2952. } // if ($iassign->type_iassign == 2)
  2953. if ($iassign->type_iassign == 1) {
  2954. $iassign_array_example[$i_example] = $iassign;
  2955. $i_example ++;
  2956. } // if ($iassign->type_iassign == 1)
  2957. }
  2958. }
  2959. if ($iassign_array_exercise) {
  2960. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2961. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2962. }
  2963. if ($iassign_array_test) {
  2964. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2965. $this->show_iassign($title, $iassign_array_test, $i_test);
  2966. }
  2967. if ($iassign_array_example) {
  2968. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2969. $this->show_iassign($title, $iassign_array_example, $i_example);
  2970. }
  2971. if ($iassign_array_general) {
  2972. $title = "";
  2973. $this->show_iassign($title, $iassign_array_general, $i_general);
  2974. }
  2975. } else { // if ($iassign_list)
  2976. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2977. }
  2978. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2979. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2980. print $OUTPUT->box_start();
  2981. print '<table width=100% border=0><tr>' . "\n";
  2982. print '<td width=10% align="left">' . "\n";
  2983. print $link_report;
  2984. print '</td>' . "\n";
  2985. print '</tr></table>' . "\n";
  2986. print $OUTPUT->box_end();
  2987. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2988. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2989. print $OUTPUT->box_start();
  2990. print '<table width=100% border=0><tr>' . "\n";
  2991. print '<td align="left">' . "\n";
  2992. print $link_add;
  2993. print '</td>' . "\n";
  2994. print '</tr></table>' . "\n";
  2995. print $OUTPUT->box_end();
  2996. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2997. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2998. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2999. $this->view_legend_icons();
  3000. } // function view_iassigns()
  3001. /// Display all iAssigns
  3002. function show_iassign ($title, $iassign_array, $i) {
  3003. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3004. $id = $this->cm->id;
  3005. print $OUTPUT->box_start();
  3006. print " <script type='text/javascript'>
  3007. //<![CDATA[
  3008. function validate_move () {
  3009. var radios = document.getElementsByName('iassign_destiny');
  3010. var formValid = false;
  3011. //alert('aqui validate_move()');
  3012. var i = 0;
  3013. while (!formValid && i < radios.length) {
  3014. if (radios[i].checked) formValid = true;
  3015. i++;
  3016. }
  3017. if (!formValid) {
  3018. document.getElementById('move_dest').classList.add('alert-danger');
  3019. }
  3020. return formValid;
  3021. }
  3022. var modal;
  3023. function load_move(id_ias) {
  3024. document.form_move_activity.iassign_current.value = id_ias;
  3025. modal.style.display = 'block';
  3026. var radios = document.getElementsByName('iassign_destiny');
  3027. var i = 0;
  3028. while (i < radios.length) {
  3029. radios[i].checked = false;
  3030. i++;
  3031. }
  3032. document.getElementById('move_dest').classList.remove('alert-danger');
  3033. }
  3034. function load_modal_elements() {
  3035. modal = document.getElementById('myModal');
  3036. var span = document.getElementById('close_modal');
  3037. span.onclick = function() {
  3038. modal.style.display = 'none';
  3039. }
  3040. window.onclick = function(event) {
  3041. if (event.target == modal) {
  3042. modal.style.display = 'none';
  3043. }
  3044. }
  3045. }
  3046. window.onload = load_modal_elements;
  3047. //]]>
  3048. </script>\n";
  3049. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3050. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3051. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3052. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3053. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3054. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3055. <input type='hidden' name='iassign_current' value='' />";
  3056. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3057. $section = $course_sections[0];
  3058. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3059. for ($k = 0; $k < count($ids_sections); $k++) {
  3060. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3061. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3062. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3063. if ($c_cm) {
  3064. if ($ccm->instance == $c_cm->instance) {
  3065. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3066. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3067. }
  3068. else {
  3069. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3070. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3071. }
  3072. }
  3073. }
  3074. $radio_buttons .= "</ul>";
  3075. }
  3076. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3077. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3078. </form>
  3079. </div></div> </div></div>\n";
  3080. print " <style>.modal {
  3081. display: none;
  3082. position: fixed;
  3083. z-index: 1;
  3084. left: 0;
  3085. top: 0;
  3086. width: 100%;
  3087. height: 100%;
  3088. overflow: scroll;
  3089. background-color: rgb(0,0,0);
  3090. background-color: rgba(0,0,0,0.4);
  3091. }
  3092. .modal-content {
  3093. background-color: #fefefe;
  3094. margin: 15% auto;
  3095. padding: 10px 10px;
  3096. border: 1px solid #888;
  3097. width: 50%;
  3098. }
  3099. #close_modal {
  3100. color: #aaa;
  3101. float: right;
  3102. font-size: 28px;
  3103. font-weight: bold;
  3104. margin-top: -15px;
  3105. margin-right: -3px;
  3106. }
  3107. #close_modal:hover,
  3108. #close_modal:focus {
  3109. color: black;
  3110. text-decoration: none;
  3111. cursor: pointer;
  3112. }
  3113. #modal_title {
  3114. min-height: 3rem;
  3115. color: initial;
  3116. background: initial;
  3117. font-size: 1.5rem;
  3118. line-height: 1.5;
  3119. padding: 15px;
  3120. border-bottom: 1px solid #e5e5e5;
  3121. }
  3122. .input_move {
  3123. width: 90%;
  3124. padding: 2px;
  3125. }
  3126. .input_move:hover {
  3127. background: #eff0ef;
  3128. }
  3129. </style>";
  3130. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3131. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3132. for ($j = 0; $j < $i; $j ++) {
  3133. $iassign_current = $iassign_array[$j]->id;
  3134. // receiver=1 - message to teacher
  3135. // receiver=2 - message to student
  3136. $sum_comment = 0;
  3137. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3138. foreach ($iassign_submissions as $iassign_submission) {
  3139. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3140. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3141. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3142. if ($verify_message)
  3143. foreach ($verify_message as $tmp)
  3144. $sum_comment += $tmp;
  3145. } // foreach ($iassign_submissions as $iassign_submission)
  3146. if ($sum_comment == 0)
  3147. $comment_unread = "";
  3148. else {
  3149. $comment_unread_message = get_string('comment_unread', 'iassign');
  3150. if ($sum_comment == 1)
  3151. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3152. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3153. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3154. }
  3155. if ($j == $i - 1)
  3156. $iassign_down = $iassign_array[$j]->id;
  3157. else
  3158. $iassign_down = $iassign_array[$j + 1]->id;
  3159. if ($j > 0)
  3160. $iassign_up = $iassign_array[$j - 1]->id;
  3161. else
  3162. $iassign_up = $iassign_array[$j]->id;
  3163. if ($iassign_array[$j]->visible == 0)
  3164. $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>";
  3165. else
  3166. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3167. $links .= $comment_unread;
  3168. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3169. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3170. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3171. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3172. if ($j==0) // first activity
  3173. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3174. else
  3175. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3176. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3177. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3178. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3179. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3180. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3181. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3182. if (count($iassign_array) > 1) {
  3183. if ($j == 0)
  3184. $links .= $link_down;
  3185. elseif ($j == $i - 1)
  3186. $links .= $link_up;
  3187. else
  3188. $links .= $link_up . $link_down;
  3189. } // if (count($iassign_array) > 1)
  3190. $links .= $link_edit . $link_delete;
  3191. if ($iassign_array[$j]->visible == 0)
  3192. $links .= $link_visible_show;
  3193. else
  3194. $links .= $link_visible_hide;
  3195. $links .= $link_duplicate_activity . $link_move_activity;
  3196. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3197. print '<p>' . $links . '</p>' . "\n";
  3198. }
  3199. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3200. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3201. print '<table width=100% ><tr>' . "\n";
  3202. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3203. print '</tr></table>' . "\n";
  3204. for ($j = 0; $j < $i; $j ++) {
  3205. $icon_status = "";
  3206. $icon_comment = "";
  3207. if ($iassign_array[$j]->visible == 1) {
  3208. $iassign_current = $iassign_array[$j]->id;
  3209. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3210. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3211. $icon_status = "";
  3212. $icon_comment = "";
  3213. if ($iassign_submission) {
  3214. // receiver=1 - message to teacher
  3215. // receiver=2 - message to student
  3216. // $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");
  3217. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3218. $verify_message = $DB->get_record_sql(
  3219. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3220. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3221. if ($verify_message)
  3222. foreach ($verify_message as $tmp)
  3223. $sum_comment = $tmp;
  3224. if ($sum_comment > 0) {
  3225. $comment_unread_message = get_string('comment_unread', 'iassign');
  3226. if ($sum_comment == 1)
  3227. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3228. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3229. }
  3230. // $icon_comment = iassign_icons::insert('comment_unread');
  3231. if ($iassign_array[$j]->type_iassign == 3) {
  3232. if ($iassign_array[$j]->show_answer == 1) {
  3233. if ($iassign_submission->status == 3)
  3234. $icon_status = iassign_icons::insert('correct');
  3235. elseif ($iassign_submission->status == 2)
  3236. $icon_status = iassign_icons::insert('incorrect');
  3237. elseif ($iassign_submission->status == 1)
  3238. $icon_status = iassign_icons::insert('post');
  3239. elseif ($iassign_submission->status == 0)
  3240. $icon_status = iassign_icons::insert('not_post');
  3241. } // if ($iassign_array[$j]->show_answer==1)
  3242. else {
  3243. if ($iassign_submission->status == 0)
  3244. $icon_status = iassign_icons::insert('not_post');
  3245. else
  3246. $icon_status = iassign_icons::insert('post');
  3247. }
  3248. } // if ($iassign_array[$j]->type_iassign == 3)
  3249. } // if ($iassign_submission)
  3250. elseif ($iassign_array[$j]->type_iassign == 3) {
  3251. $icon_status = iassign_icons::insert('not_post');
  3252. } // if ($iassign_array[$j]->type_iassign == 3)
  3253. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3254. } // if ($iassign_array[$j]->visible == 1)
  3255. } // for ($j = 0; $j < $i; $j++)
  3256. } else if (isguestuser()) {
  3257. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3258. print '<table width=100% ><tr>' . "\n";
  3259. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3260. print '</tr></table>' . "\n";
  3261. for ($j = 0; $j < $i; $j ++) {
  3262. $icon_status = "";
  3263. $icon_comment = "";
  3264. if ($iassign_array[$j]->visible == 1) {
  3265. $iassign_current = $iassign_array[$j]->id;
  3266. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3267. print '<p>' . $links . '</p>' . "\n";
  3268. } // if ($iassign_array[$j]->visible == 1)
  3269. }
  3270. }
  3271. print $OUTPUT->box_end();
  3272. } // function show_iassign($title, $iassign_array, $i)
  3273. /// Show message of return
  3274. function return_home_course ($message) {
  3275. //D global $DB, $OUTPUT;
  3276. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3277. //D echo $OUTPUT->box_start();
  3278. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3279. //D echo '<tr><td align="left"><strong>' . "\n";
  3280. //D print_string($message, 'iassign');
  3281. //D echo '</strong></td>' . "\n";
  3282. //D echo '<td width=20% align="right">' . "\n";
  3283. //D echo $link_return;
  3284. //D echo '</td></tr></table>' . "\n";
  3285. //D echo $OUTPUT->box_end();
  3286. //D // echo $OUTPUT->footer();
  3287. redirect(new moodle_url($this->return . '&notice=' . $message));
  3288. exit;
  3289. }
  3290. /// Search comment of activity
  3291. function search_comment_submission ($iassign_submissionid) {
  3292. global $USER, $DB, $OUTPUT, $COURSE;
  3293. // $context = context_course::instance($COURSE->id);
  3294. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3295. $colorEdit2 = "#b7ceee";
  3296. $has_capability = 0;
  3297. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3298. $text = "";
  3299. if ($comments) {
  3300. $even = 1;
  3301. foreach ($comments as $tmp) {
  3302. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3303. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3304. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3305. // $text .= $tmp->comment . "</td></tr>";
  3306. //} else {
  3307. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3308. if ($even) {
  3309. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3310. $even = 0;
  3311. } else {
  3312. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3313. $even = 1;
  3314. }
  3315. $text .= $tmp->comment . "</td></tr>\n";
  3316. } // foreach ($comments as $tmp)
  3317. }
  3318. return $text;
  3319. }
  3320. /// Update comment of activity
  3321. function update_comment ($iassign_submissionid) {
  3322. global $USER, $DB, $OUTPUT;
  3323. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3324. $receiver = 1; // student message to teacher
  3325. else
  3326. $receiver = 2; // teacher message to student
  3327. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3328. if ($verify_message) {
  3329. foreach ($verify_message as $message) {
  3330. if ($message->receiver == $receiver) {
  3331. $newentry = new stdClass();
  3332. $newentry->id = $message->id;
  3333. $newentry->return_status = 1;
  3334. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3335. print_error('error_update', 'iassign');
  3336. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3337. } // if ($message->receiver == $receiver)
  3338. // Trigger module viewed event.
  3339. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3340. 'objectid' => $this->iassign->id,
  3341. 'context' => $this->context
  3342. ));
  3343. $event->add_record_snapshot('course', $this->course);
  3344. $event->trigger();
  3345. } // foreach ($verify_message as $message)
  3346. }
  3347. }
  3348. /// Record comment of activity
  3349. function write_comment_submission () {
  3350. global $USER, $CFG, $DB;
  3351. $id = $this->cm->id;
  3352. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3353. $row = optional_param('row', 0, PARAM_INT);
  3354. $column = optional_param('column', 0, PARAM_INT);
  3355. $sum_comment = 0;
  3356. $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);
  3357. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3358. $str1 = trim($submission_comment);
  3359. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3360. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3361. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3362. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3363. $receiver = 1; // student message to teacher
  3364. $this->action = 'view';
  3365. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3366. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3367. } else {
  3368. $receiver = 2; // teacher message to student
  3369. $this->action = 'viewsubmission';
  3370. //D $tousers = array(); //MOOC 2016
  3371. //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
  3372. }
  3373. //MOOC 2016: foi p/ 15 linhas acima:
  3374. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3375. if (!$iassign_submission) {
  3376. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3377. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3378. $this->iassign_submission_current = $id_submission;
  3379. } else {
  3380. $id_submission = $iassign_submission->id;
  3381. } // if (!$iassign_submission)
  3382. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3383. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3384. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3385. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3386. $comments = $DB->get_record_sql(
  3387. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3388. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3389. if ($comments)
  3390. foreach ($comments as $tmp)
  3391. $sum_comment = $tmp;
  3392. if ($sum_comment == 0) {
  3393. $newentry = new stdClass();
  3394. $newentry->iassign_submissionid = $id_submission;
  3395. $newentry->comment_authorid = $USER->id;
  3396. $newentry->timecreated = time();
  3397. $newentry->comment = $submission_comment;
  3398. $newentry->receiver = $receiver;
  3399. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3400. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3401. //T $eventdata = new stdClass();
  3402. //T $eventdata->component = 'mod_iassign'; //your component name
  3403. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3404. //T $eventdata->userfrom = $USER;
  3405. //T $eventdata->userto = $touser;
  3406. //T $eventdata->subject = "Teste de Subject";
  3407. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3408. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3409. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3410. //T $eventdata->smallmessage = "Teste de Mensagem";
  3411. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3412. //T // alteracao tulio faria
  3413. //T //message_send($eventdata);
  3414. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3415. // Trigger module viewed event.
  3416. $event = \mod_iassign\event\submission_comment_created::create(array(
  3417. 'objectid' => $this->iassign->id,
  3418. 'context' => $this->context
  3419. ));
  3420. $event->add_record_snapshot('course', $this->course);
  3421. $event->trigger();
  3422. }
  3423. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3424. // if ($this->action=='viewsubmission') {
  3425. // echo $OUTPUT->header();
  3426. // $this->return_last('confirm_add_comment', $link_return);
  3427. // die;
  3428. // }
  3429. return true;
  3430. } // function write_comment_submission()
  3431. /// Writes a new submission
  3432. // The first student answer is under 'function get_answer()'
  3433. function new_submission ($iassignid, $id_user, $receiver) {
  3434. global $USER, $DB, $OUTPUT;
  3435. $newentry = new stdClass();
  3436. $newentry->iassign_statementid = $iassignid;
  3437. $newentry->userid = $id_user;
  3438. $newentry->timecreated = time();
  3439. $newentry->timemodified = time();
  3440. $newentry->answer = 0; // student only submit message
  3441. if ($receiver == 2) // teacher message to student (write id teacher)
  3442. $newentry->teacher = $USER->id;
  3443. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3444. return_home_course('error_insert_submissions');
  3445. else {
  3446. // Trigger module view event
  3447. $event = \mod_iassign\event\submission_created::create(array(
  3448. 'objectid' => $this->iassign->id,
  3449. 'context' => $this->context
  3450. ));
  3451. $event->add_record_snapshot('course', $this->course);
  3452. $event->trigger();
  3453. }
  3454. return $newentry->id;
  3455. }
  3456. /// Return to a specific address of page
  3457. function return_last ($message, $link_return) {
  3458. global $DB, $OUTPUT;
  3459. print $OUTPUT->box_start();
  3460. print '<table width=100% border=0 valign="top">' . "\n";
  3461. print '<tr><td align="left"><strong>' . "\n";
  3462. print_string($message, 'iassign');
  3463. print '</strong></td>' . "\n";
  3464. print '<td width=20% align="right">' . "\n";
  3465. print $link_return;
  3466. print '</td></tr></table>' . "\n";
  3467. print $OUTPUT->box_end();
  3468. print $OUTPUT->footer();
  3469. die();
  3470. } // function return_last($message, $link_return)
  3471. } // class iassign
  3472. /// Class for manage activities
  3473. class activity {
  3474. var $activity;
  3475. /// Constructor of class.
  3476. // @param int $id Id of activity
  3477. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3478. //D public function activity($id) { self::__construct($id); }
  3479. function __construct ($id) {
  3480. global $DB;
  3481. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3482. if (empty($this->activity))
  3483. $this->activity = null;
  3484. }
  3485. /// Get an activity
  3486. // @return NULL
  3487. function get_activity () {
  3488. if ($this->activity != null)
  3489. return $this->activity;
  3490. else
  3491. return null;
  3492. }
  3493. /// Delete interactive activities
  3494. function delete ($return) {
  3495. global $USER, $CFG, $DB, $OUTPUT;
  3496. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3497. $output = $OUTPUT->header();
  3498. $output .= $OUTPUT->box_start();
  3499. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3500. if ($iassign_submission_currents) {
  3501. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3502. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3503. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3504. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3505. $output .= $OUTPUT->box_end();
  3506. $output .= $OUTPUT->footer();
  3507. print $output;
  3508. die();
  3509. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3510. } // if ($iassign_submission_currents)
  3511. else
  3512. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3513. $output .= '<table width=50% border=0>';
  3514. $output .= '<tr valign="top"><td>';
  3515. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3516. $output .= '</td><td>';
  3517. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3518. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3519. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3520. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3521. $output .= "</form>\n";
  3522. $output .= '</td><td>';
  3523. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3524. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3525. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3526. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3527. $output .= "</form>\n";
  3528. $output .= '</td></tr></table>' . "\n";
  3529. $output .= $OUTPUT->box_end();
  3530. $output .= $OUTPUT->footer();
  3531. print $output;
  3532. } // function delete($return)
  3533. /// Function for confirm the delete of activity
  3534. // @param String $return Url of return
  3535. // @param Object $iassign Object content an activity
  3536. function deleteyes ($return, $iassign) {
  3537. global $USER, $CFG, $DB, $OUTPUT;
  3538. $msg = '';
  3539. if (!empty($this->activity->id)) {
  3540. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3541. if ($iassign_submission_currents) {
  3542. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3543. foreach ($iassign_submission_currents as $iassign_submission)
  3544. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3545. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3546. } // if ($iassign_submission_currents)
  3547. }
  3548. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3549. $this->delete_calendar($this->activity->id);
  3550. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3551. iassign::update_grade_iassign($this->activity->iassignid);
  3552. if ($delete_iassign_current) {
  3553. $iassign->return_home_course('confirm_delete_iassign');
  3554. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3555. } else {
  3556. $iassign->return_home_course('error_confirm_delete_iassign');
  3557. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3558. }
  3559. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3560. }
  3561. }
  3562. /// Changes position of activities (between those inside a group of interactive activities)
  3563. // @param $move_action = must be "up" or "down"
  3564. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3565. function move_iassign ($move_action, $target, $return) {
  3566. global $DB, $OUTPUT;
  3567. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3568. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3569. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3570. if ($move_action=="firstdown") {
  3571. $final_position_source = 2;
  3572. $final_position_target = 1;
  3573. }
  3574. else
  3575. if ($move_action=="down") {
  3576. $final_position_target = $this->activity->position;
  3577. $final_position_source = $final_position_target + 1;
  3578. }
  3579. else
  3580. if ($move_action=="up") {
  3581. $final_position_target = $this->activity->position;
  3582. $final_position_source = $final_position_target - 1;
  3583. }
  3584. else { // error:
  3585. print_error('error_update_move_iassign', 'iassign');
  3586. exit;
  3587. }
  3588. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3589. $newentry->id = $this->activity->id; // ID of the "source activity"
  3590. $newentry->position = $final_position_source;
  3591. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3592. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3593. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3594. print_error('error_update_move_iassign', 'iassign');
  3595. }
  3596. else { // first update performed successfully
  3597. $newentry->id = $iassign_target->id;
  3598. $newentry->position = $final_position_target;
  3599. if (!$DB->update_record('iassign_statement', $newentry))
  3600. print_error('error_update_move_iassign', 'iassign');
  3601. }
  3602. redirect($return);
  3603. }
  3604. /// Enable or disable the display of interactive activities
  3605. function visible_iassign ($return) {
  3606. global $DB;
  3607. $newentry = new stdClass();
  3608. $newentry->id = $this->activity->id;
  3609. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3610. if (!$DB->update_record('iassign_statement', $newentry))
  3611. print_error('error_update_visible_iassign', 'iassign');
  3612. redirect($return);
  3613. }
  3614. /// Add news interactive activities (register in table 'iassign_statement')
  3615. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3616. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3617. function new_iassign ($param) {
  3618. global $DB;
  3619. $newentry = new stdClass();
  3620. $newentry->iassignid = $param->iassignid;
  3621. $newentry->name = $param->name;
  3622. $newentry->type_iassign = $param->type_iassign;
  3623. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3624. $proposition = $param->proposition;
  3625. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3626. else $proposition_text = $proposition;
  3627. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3628. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3629. //TODO Then get it directly from the form data $_POST!
  3630. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3631. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3632. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3633. $newentry->author_name = $param->author_name;
  3634. $newentry->author_modified_name = $param->author_modified_name;
  3635. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3636. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3637. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3638. $newentry->grade = $param->grade;
  3639. $newentry->timemodified = time();
  3640. $newentry->timecreated = time();
  3641. if ($param->type_iassign == 1) {
  3642. $newentry->timedue = 0;
  3643. $newentry->timeavailable = 0;
  3644. } // if ($param->type_iassign == 1)
  3645. else {
  3646. $newentry->timedue = $param->timedue;
  3647. $newentry->timeavailable = $param->timeavailable;
  3648. }
  3649. $newentry->preventlate = $param->preventlate;
  3650. $newentry->test = $param->test;
  3651. $newentry->special_param1 = $param->special_param1;
  3652. $newentry->visible = $param->visible;
  3653. $newentry->position = $param->position;
  3654. $newentry->max_experiment = $param->max_experiment;
  3655. $newentry->dependency = $param->dependency;
  3656. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3657. $newentry->show_answer = $param->show_answer;
  3658. $id = $DB->insert_record("iassign_statement", $newentry);
  3659. if ($id) {
  3660. $component = 'mod_iassign';
  3661. $filearea = 'exercise';
  3662. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3663. $file = $fs->get_file_by_id($param->file);
  3664. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3665. // File already inserted in other context!
  3666. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3667. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3668. $updateentry = new stdClass();
  3669. $updateentry->id = $id;
  3670. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3671. $updateentry->file = $newfile->get_itemid();
  3672. if (!$DB->update_record("iassign_statement", $updateentry))
  3673. print_error('error_add', 'iassign');
  3674. if ($param->type_iassign == 3)
  3675. iassign::update_grade_iassign($param->iassignid);
  3676. //TODO iLM_HTML5 :: //MOOC2014
  3677. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3678. //D if ($iassign_ilm_configs) {
  3679. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3680. //D if ($iassign_ilm_config->param_type != 'static') {
  3681. //D $newentry = new stdClass();
  3682. //D $newentry->iassign_statementid = $id;
  3683. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3684. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3685. //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});
  3686. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3687. //D print_error('error_add_param', 'iassign');
  3688. //D }
  3689. //D }
  3690. //D }
  3691. // log event --------------------------------------------------------------------------------------
  3692. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3693. // log event --------------------------------------------------------------------------------------
  3694. return $id;
  3695. }
  3696. else
  3697. print_error('error_add', 'iassign');
  3698. } // function new_iassign($param)
  3699. /// Add the calendar entries for this iassign
  3700. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3701. // @return bool
  3702. static function add_calendar ($iassignid) {
  3703. global $DB, $CFG;
  3704. require_once($CFG->dirroot . '/calendar/lib.php');
  3705. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3706. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3707. $event = new stdClass();
  3708. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3709. $event->description = $iassign_statement_activity_item->name;
  3710. $event->courseid = $iassign->course;
  3711. $event->groupid = 0;
  3712. $event->userid = 0;
  3713. $event->modulename = 'iassign';
  3714. $event->instance = $iassign->id;
  3715. $event->eventtype = 'due';
  3716. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3717. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3718. calendar_event::create($event);
  3719. }
  3720. /// Update the calendar entries for this iassign
  3721. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3722. // @return bool
  3723. function update_calendar ($iassignid, $olddescription) {
  3724. global $DB, $CFG;
  3725. require_once($CFG->dirroot . '/calendar/lib.php');
  3726. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3727. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3728. $event = new stdClass();
  3729. $event->id = 0;
  3730. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3731. if ($events) {
  3732. foreach ($events as $value) {
  3733. if ($value->description == $olddescription) {
  3734. $event->id = $value->id;
  3735. }
  3736. }
  3737. }
  3738. if ($event->id != 0) {
  3739. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3740. $event->description = $iassign_statement_activity_item->name;
  3741. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3742. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3743. $calendarevent = calendar_event::load($event->id);
  3744. $calendarevent->update($event);
  3745. } else
  3746. $this->add_calendar($iassignid);
  3747. }
  3748. /// Update the calendar entries for this iassign
  3749. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3750. // @return bool
  3751. function delete_calendar ($iassignid) {
  3752. global $DB, $CFG;
  3753. require_once($CFG->dirroot . '/calendar/lib.php');
  3754. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3755. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3756. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3757. if ($events) {
  3758. foreach ($events as $value) {
  3759. if ($value->description == $iassign_statement_activity_item->name) {
  3760. $DB->delete_records('event', array('id' => $value->id));
  3761. }
  3762. }
  3763. }
  3764. }
  3765. /// Update interactive activities
  3766. function update_iassign ($param) {
  3767. global $DB;
  3768. $component = 'mod_iassign';
  3769. $filearea = 'exercise';
  3770. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3771. $file = $fs->get_file_by_id($param->file);
  3772. $fileold = $fs->get_file_by_id($param->fileold);
  3773. if ($param->file != $param->fileold) {
  3774. if ($fileold) {
  3775. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3776. foreach ($fileoldarea as $value) {
  3777. $value->delete();
  3778. }
  3779. }
  3780. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3781. $itemid = $file->get_itemid() + $param->iassign_id;
  3782. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3783. $param->file = $newfile->get_itemid();
  3784. } else
  3785. $param->file = $file->get_itemid();
  3786. } else {
  3787. $param->file = $file->get_itemid();
  3788. }
  3789. $newentry = new stdClass();
  3790. $newentry->id = $param->iassign_id;
  3791. $newentry->name = $param->name;
  3792. $newentry->type_iassign = $param->type_iassign;
  3793. //2019 $newentry->proposition = $param->proposition;
  3794. $proposition = $param->proposition;
  3795. if (is_array($proposition))
  3796. $proposition_text = $proposition['text'];
  3797. else
  3798. $proposition_text = $proposition;
  3799. $newentry->proposition = $proposition_text;
  3800. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3801. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3802. $newentry->grade = $param->grade;
  3803. $newentry->author_modified_name = $param->author_modified_name;
  3804. $newentry->timemodified = time();
  3805. if ($param->type_iassign == 1) {
  3806. $newentry->timedue = 0;
  3807. $newentry->timeavailable = 0;
  3808. } // if ($param->type_iassign == 1)
  3809. else {
  3810. $newentry->timedue = $param->timedue;
  3811. $newentry->timeavailable = $param->timeavailable;
  3812. }
  3813. $newentry->preventlate = $param->preventlate;
  3814. $newentry->test = $param->test;
  3815. $newentry->special_param1 = $param->special_param1;
  3816. $newentry->visible = $param->visible;
  3817. $newentry->max_experiment = $param->max_experiment;
  3818. $newentry->dependency = $param->dependency;
  3819. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3820. $newentry->show_answer = $param->show_answer;
  3821. if (!$DB->update_record("iassign_statement", $newentry))
  3822. print_error('error_update', 'iassign');
  3823. if ($param->type_iassign == 3) {
  3824. iassign::update_grade_iassign($param->iassignid);
  3825. }
  3826. //$id = $newentry->id; // MOOC 2016 --- inicio
  3827. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3828. //if ($iassign_activity_item_configs) {
  3829. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3830. // $newentry = new stdClass();
  3831. // $newentry->id = $iassign_activity_item_config->id;
  3832. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3833. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3834. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3835. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3836. // print_error('error_edit_param', 'iassign');
  3837. // }
  3838. // } // MOOC 2016 --- final
  3839. // log event --------------------------------------------------------------------------------------
  3840. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3841. // log event --------------------------------------------------------------------------------------
  3842. return $newentry->id;
  3843. // if ($param->type_iassign==3)
  3844. // $this->update_grade_iassign($param->iassignid);
  3845. } // function update_iassign($param)
  3846. /// Show information of activity
  3847. function show_info_iassign () {
  3848. global $DB, $OUTPUT;
  3849. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3850. if ($this->activity->type_iassign == 3) {
  3851. if ($this->activity->dependency == 0) {
  3852. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3853. } else {
  3854. $dependencys = explode(';', $this->activity->dependency);
  3855. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3856. foreach ($dependencys as $dependency) {
  3857. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3858. if ($dependencyiassign)
  3859. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3860. } // foreach ($dependencys as $dependency)
  3861. } // if ($iassign_statement_activity_item->dependency == 0)
  3862. if ($this->activity->max_experiment == 0)
  3863. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3864. else
  3865. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3866. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3867. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3868. print $OUTPUT->box($output);
  3869. } // function show_info_iassign()
  3870. /// Shows date of opening and closing activities
  3871. function view_dates () {
  3872. global $USER, $CFG, $DB, $OUTPUT;
  3873. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3874. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3875. $status_iassign = "";
  3876. $status_iassign1 = "";
  3877. $status_iassign2 = "";
  3878. if ($this->activity->type_iassign == 1) // activity of type example
  3879. $type_iassign = get_string('example_iassign', 'iassign');
  3880. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3881. $type_iassign = get_string('test_iassign', 'iassign');
  3882. if ($this->activity->timeavailable > time()) {
  3883. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3884. } elseif ($this->activity->timedue < time()) {
  3885. $status_iassign = get_string('last_timedue', 'iassign');
  3886. }
  3887. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3888. $type_iassign = get_string('exercise_iassign', 'iassign');
  3889. if ($this->activity->timeavailable > time()) {
  3890. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3891. } elseif ($this->activity->timedue < time()) { // after delivery
  3892. $status_iassign = get_string('last_timedue', 'iassign');
  3893. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3894. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3895. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3896. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3897. if ($this->activity->test == 1) // allowed to test after of deadline
  3898. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3899. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3900. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3901. } // elseif ($iassign_statement_activity_item->test == 0)
  3902. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3903. } // elseif ($iassign_statement_activity_item->timedue < time())
  3904. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3905. $output = '<table width=100% >' . "\n";
  3906. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3907. $output .= '<tr>' . "\n";
  3908. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3909. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3910. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3911. // leo $output .= '<td width=80%>' . $type_iassign;
  3912. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3913. // $output .= '</td>' . "\n";
  3914. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3915. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3916. $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>";
  3917. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3918. } else {
  3919. $link_next = "";
  3920. $link_previous = "";
  3921. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3922. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3923. // previous_activity
  3924. if ($iassign_previous) {
  3925. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3926. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3927. } // next_activity
  3928. if ($iassign_next) {
  3929. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3930. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3931. }
  3932. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3933. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3934. $output .= '</tr></table>' . "\n";
  3935. $output .= '<table width=100% >' . "\n";
  3936. if ($this->activity->type_iassign > 1) {
  3937. if ($this->activity->timeavailable)
  3938. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3939. if ($this->activity->timedue)
  3940. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3941. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3942. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3943. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3944. $output .= '</table>' . "\n";
  3945. print $OUTPUT->box($output);
  3946. } // function view_dates()
  3947. } // class activity
  3948. /// Class to manage Interactive Learning Module (iLM)
  3949. class ilm {
  3950. var $ilm;
  3951. /// Constructor of class
  3952. // @param int $id Id of iLM
  3953. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3954. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3955. function __construct ($id) {
  3956. global $DB;
  3957. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3958. if (empty($this->ilm))
  3959. $this->ilm = null;
  3960. }
  3961. /// Shows activity in iLM
  3962. // @calledby view_iassign_current()
  3963. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3964. global $USER, $CFG, $DB;
  3965. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3966. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3967. $typec = strtolower($iassign_ilm->type);
  3968. require_once 'ilm_handlers/' . $typec . '.php';
  3969. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3970. return $retorno;
  3971. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3972. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3973. // @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);
  3974. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3975. // @param Object $file File in use in activity
  3976. // @return int Return the id of log
  3977. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3978. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3979. $newentry = new stdClass();
  3980. $newentry->iassign_statementid = $iassign_activity_itemid;
  3981. $newentry->userid = $USER->id;
  3982. $newentry->file = $content_or_id_from_ilm_security;
  3983. $newentry->timecreated = time();
  3984. $newentry->view = 1;
  3985. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3986. if (!$id_iLM_security) {
  3987. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3988. } // from (!$DB->insert_record("iassign_security", $newentry))
  3989. return $id_iLM_security;
  3990. }
  3991. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3992. // @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);
  3993. // @param int $userid
  3994. // @param int $iassign_activity_itemid Id of iassign statement
  3995. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3996. global $DB;
  3997. // 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")
  3998. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3999. }
  4000. } // class ilm
  4001. /// Class to manage settings of iLM.
  4002. class ilm_settings {
  4003. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4004. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4005. // @param int $ilm_id Id of iLM
  4006. // @param array $options An array with options for create dynamic tag html APPLET
  4007. // @return string Return with a tag html APPLET created
  4008. static function build_ilm_tags ($ilm_id, $options = array()) {
  4009. global $DB;
  4010. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4011. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4012. $typec = strtolower($iassign_ilm->type);
  4013. require_once 'ilm_handlers/' . $typec . '.php';
  4014. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  4015. return $retorno;
  4016. } // static function build_ilm_tags($ilm_id, $options = array())
  4017. /// Function for get modified date of iLM file
  4018. // @param string $file_jar String with Ids of iLM files
  4019. // @return string Return with the filenames and modified date
  4020. static function applet_filetime ($file_jar) {
  4021. $filetime = "";
  4022. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4023. $files_jar = explode(",", $file_jar);
  4024. foreach ($files_jar as $one_file) {
  4025. $file = $fs->get_file_by_id($one_file);
  4026. if ($file)
  4027. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4028. }
  4029. return $filetime;
  4030. }
  4031. /// Function for verify an default applet
  4032. // @param String $file_jar String containing an list de ids of applet files
  4033. // @return boolean Return true or fale if applet is default
  4034. static function applet_default ($file_jar) {
  4035. $is_default = true;
  4036. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4037. $files_jar = explode(",", $file_jar);
  4038. foreach ($files_jar as $one_file) {
  4039. $file = $fs->get_file_by_id($one_file);
  4040. if ($file)
  4041. $is_default &= ($file->get_itemid() == 0);
  4042. }
  4043. return $is_default;
  4044. }
  4045. /// Function for get form variables for add, edit, or copy iLM
  4046. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4047. // @see settings_form.php
  4048. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4049. // @param int $ilm_id Id of iLM
  4050. // @param string $action String with the action
  4051. // @return object Return an object with forms variables
  4052. static function add_edit_copy_ilm ($ilm_id, $action) {
  4053. global $USER, $DB, $CFG;
  4054. require_once('settings_form.php'); // put the form
  4055. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4056. $param = new stdClass();
  4057. $param->action = $action;
  4058. $param->ilm_id = $ilm_id;
  4059. $CFG->action_ilm = $action;
  4060. $CFG->ilm_id = $ilm_id;
  4061. if ($action == 'add') {
  4062. $param->title = get_string('add_ilm', 'iassign');
  4063. $param->name = "";
  4064. $param->version = "";
  4065. $param->url = "";
  4066. $param->description = "";
  4067. $param->extension = "";
  4068. $param->author = $USER->id;
  4069. $param->file_jar = "";
  4070. $param->file_jar_static = "";
  4071. $param->file_class = "";
  4072. $param->width = 800;
  4073. $param->height = 600;
  4074. $param->enable = 0; // 0 - hide / 1 - show
  4075. $param->timecreated = time();
  4076. $param->timemodified = time();
  4077. $param->evaluate = 0;
  4078. $param->parent = 0;
  4079. }
  4080. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4081. if ($iassign_ilm) {
  4082. $description = json_decode($iassign_ilm->description);
  4083. $param->title = get_string('edit_ilm', 'iassign');
  4084. $param->id = $iassign_ilm->id;
  4085. $param->name_ilm = $iassign_ilm->name;
  4086. $param->name = $iassign_ilm->name;
  4087. $param->version = $iassign_ilm->version;
  4088. $param->ilm_type = $iassign_ilm->type;
  4089. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4090. $param->url = $iassign_ilm->url;
  4091. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4092. if (!isset($description->{current_language()})) {
  4093. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4094. else
  4095. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4096. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4097. }
  4098. else
  4099. $param->description = $description->{current_language()};
  4100. $param->description_lang = $iassign_ilm->description;
  4101. $param->extension = $iassign_ilm->extension;
  4102. $param->author = $iassign_ilm->author;
  4103. $param->file_jar = $iassign_ilm->file_jar;
  4104. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4105. $param->file_class = $iassign_ilm->file_class;
  4106. $param->width = $iassign_ilm->width;
  4107. $param->height = $iassign_ilm->height;
  4108. $param->enable = $iassign_ilm->enable;
  4109. $param->timecreated = $iassign_ilm->timecreated;
  4110. $param->timemodified = time();
  4111. $param->evaluate = $iassign_ilm->evaluate;
  4112. $param->parent = $iassign_ilm->parent;
  4113. }
  4114. }
  4115. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4116. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4117. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4118. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4119. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4120. // echo "Sem dados<br/>"; exit;
  4121. return;
  4122. }
  4123. $description = json_decode($iassign_ilm->description);
  4124. if ($iassign_ilm) {
  4125. if ($iassign_ilm->parent == 0)
  4126. $iassign_ilm->parent = $ilm_id;
  4127. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4128. $param->title = get_string('new_version_ilm', 'iassign');
  4129. $param->name_ilm = $iassign_ilm->name;
  4130. $param->name = $iassign_ilm->name;
  4131. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4132. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4133. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4134. $param->ilm_type = $iassign_ilm->type;
  4135. $param->url = $iassign_ilm->url;
  4136. $param->description = $description->{current_language()};
  4137. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4138. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4139. $param->extension = $iassign_ilm->extension;
  4140. $param->author = $USER->id;
  4141. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4142. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4143. $param->file_jar_static = '';
  4144. $param->file_class = $iassign_ilm->file_class;
  4145. $param->width = $iassign_ilm->width;
  4146. $param->height = $iassign_ilm->height;
  4147. $param->enable = 0;
  4148. $param->timecreated = time();
  4149. $param->timemodified = time();
  4150. $param->evaluate = $iassign_ilm->evaluate;
  4151. $param->parent = $iassign_ilm->parent;
  4152. }
  4153. }
  4154. elseif ($action == 'copy') {
  4155. $description = json_decode($iassign_ilm->description);
  4156. if ($iassign_ilm) {
  4157. if ($iassign_ilm->parent == 0)
  4158. $iassign_ilm->parent = $ilm_id;
  4159. $param->title = get_string('copy_ilm', 'iassign');
  4160. $param->id = $iassign_ilm->id;
  4161. $param->name_ilm = $iassign_ilm->name;
  4162. $param->name = $iassign_ilm->name;
  4163. $param->version = "";
  4164. $param->ilm_type = $iassign_ilm->type;
  4165. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4166. $param->url = $iassign_ilm->url;
  4167. $param->description = $description->{current_language()};
  4168. $param->description_lang = $iassign_ilm->description;
  4169. $param->extension = $iassign_ilm->extension;
  4170. $param->author = $USER->id;
  4171. $param->file_jar = '';
  4172. $param->file_jar_static = '';
  4173. $param->file_class = $iassign_ilm->file_class;
  4174. $param->width = $iassign_ilm->width;
  4175. $param->height = $iassign_ilm->height;
  4176. $param->enable = 0;
  4177. $param->timecreated = time();
  4178. $param->timemodified = time();
  4179. $param->evaluate = $iassign_ilm->evaluate;
  4180. $param->parent = $iassign_ilm->parent;
  4181. }
  4182. }
  4183. return $param;
  4184. } // static function add_edit_copy_ilm($ilm_id, $action)
  4185. /// Function for save iLM file in moodledata
  4186. // @param int $itemid Itemid of file save in draft (upload file)
  4187. // @param int $ilm_id Id of iLM
  4188. // @return string Return an string with ids of iLM files
  4189. static function new_file_ilm ($itemid, $iassign_ilm) {
  4190. global $CFG, $USER, $DB;
  4191. $return = null;
  4192. $file_jar = array();
  4193. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4194. $contextuser = context_user::instance($USER->id);
  4195. $contextsystem = context_system::instance();
  4196. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4197. if ($files_ilm) {
  4198. foreach ($files_ilm as $value) {
  4199. // CHECK IF file is HTML type
  4200. if ($iassign_ilm->type == 1) {
  4201. // Check if the file extension is ZIP
  4202. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4203. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4204. if ((strtolower($ext) == 'zip')) {
  4205. // Coping...:
  4206. $destination = 'ilm_debug/' . $value->get_filename();
  4207. $value->copy_content_to($destination);
  4208. // Extracting content...:
  4209. $zip = new ZipArchive();
  4210. $extracted = './ilm';
  4211. $dir = "";
  4212. if ($zip->open($destination) === TRUE) {
  4213. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4214. if (is_dir($dir)) {
  4215. $i = 1;
  4216. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4217. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4218. $i ++;
  4219. }
  4220. $name = $previous . "_" . $i;
  4221. $dir = './ilm/' . $name . "/";
  4222. $j = 0;
  4223. while ($item_name = $zip->getNameIndex($j)) {
  4224. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4225. $j++;
  4226. }
  4227. $zip->close();
  4228. }
  4229. $zip->open($destination);
  4230. $zip->extractTo($extracted);
  4231. $zip->close();
  4232. // After the extraction, remove it from DEBUG
  4233. unlink($destination);
  4234. } else { // Error trying to open destination...
  4235. // After the extraction error, also remove it from DEBUG
  4236. unlink($destination);
  4237. print_error('error_add_ilm_zip', 'iassign');
  4238. }
  4239. return $dir;
  4240. }
  4241. } // if ($iassign_ilm->type == 1)
  4242. if ($value->get_filename() != '.') {
  4243. $file_ilm = array(
  4244. 'userid' => $USER->id,
  4245. 'contextid' => $contextsystem->id,
  4246. 'component' => 'mod_iassign',
  4247. 'filearea' => 'ilm',
  4248. 'itemid' => rand(1, 999999999),
  4249. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4250. 'filename' => $value->get_filename());
  4251. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4252. array_push($file_jar, $file_ilm->get_id());
  4253. }
  4254. }
  4255. if (!empty($file_jar)) {
  4256. $return = implode(",", $file_jar);
  4257. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4258. foreach ($old_file_jar as $value) {
  4259. $file = $fs->get_file_by_id($value);
  4260. if ($file)
  4261. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4262. }
  4263. }
  4264. }
  4265. else // if ($files_ilm)
  4266. $return = $iassign_ilm->file_jar;
  4267. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4268. return $return;
  4269. } // static function new_file_ilm($itemid, $iassign_ilm)
  4270. /// Function for save in database an new iLM
  4271. // @param object $param An object with iLM params
  4272. static function new_ilm ($itemid) {
  4273. global $CFG, $USER, $OUTPUT;
  4274. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4275. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4276. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4277. }
  4278. $pathtemp = $CFG->dataroot . '/temp/';
  4279. $contextuser = context_user::instance($USER->id);
  4280. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4281. $zip = new zip_packer();
  4282. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4283. foreach ($files as $file) {
  4284. if (!$file->is_directory())
  4285. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4286. }
  4287. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4288. // Verifica se o pacote possui o XML
  4289. if (!$application_xml) {
  4290. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4291. return;
  4292. } else {
  4293. $missing = "";
  4294. if (!isset($application_xml->name)) {
  4295. $missing .= "name";
  4296. }
  4297. if (!isset($application_xml->version)) {
  4298. $missing .= ", version";
  4299. }
  4300. if (!isset($application_xml->type)) {
  4301. $missing .= ", type";
  4302. }
  4303. if (!isset($application_xml->extension)) {
  4304. $missing .= ", extension";
  4305. }
  4306. if (!isset($application_xml->file_jar)) {
  4307. $missing .= ", file_jar";
  4308. }
  4309. if (!isset($application_xml->file_class)) {
  4310. $missing .= ", file_class";
  4311. }
  4312. if (!isset($application_xml->width)) {
  4313. $missing .= ", width";
  4314. }
  4315. if (!isset($application_xml->height)) {
  4316. $missing .= ", height";
  4317. }
  4318. if (!isset($application_xml->evaluate)) {
  4319. $missing .= ", evaluate";
  4320. }
  4321. if (strlen($missing) > 2) {
  4322. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4323. return;
  4324. }
  4325. }
  4326. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4327. $typec = strtolower($application_xml->type);
  4328. require_once 'ilm_handlers/' . $typec . '.php';
  4329. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4330. return $retorno;
  4331. } // static function new_ilm($itemid)
  4332. /// Function for save in database an iLM edit
  4333. // @param object $param An object with iLM params
  4334. static function edit_ilm ($param, $itemid) {
  4335. // Descobrir o tipo de iLM:
  4336. global $DB, $USER, $CFG;
  4337. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4338. $pathtemp = $CFG->dataroot . '/temp/';
  4339. $contextuser = context_user::instance($USER->id);
  4340. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4341. $zip = new zip_packer();
  4342. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4343. $files_extract = null;
  4344. foreach ($files as $file) {
  4345. if (!$file->is_directory())
  4346. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4347. }
  4348. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4349. $typec = strtolower($iassign_t->type);
  4350. require_once 'ilm_handlers/' . $typec . '.php';
  4351. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4352. }
  4353. /// Function for register the new iLM (in database and in the directory)
  4354. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4355. // @param object $param An object with iLM params
  4356. static function copy_new_version_ilm ($param) {
  4357. global $DB, $CFG, $USER;
  4358. $itemid = $param->file;
  4359. $pathtemp = $CFG->dataroot . '/temp/';
  4360. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4361. //D echo "pathtemp=$pathtemp<br/>";
  4362. $contextuser = context_user::instance($USER->id);
  4363. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4364. $zip = new zip_packer();
  4365. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4366. $files_extract = null;
  4367. foreach ($files as $file) {
  4368. if (!$file->is_directory())
  4369. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4370. }
  4371. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4372. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4373. $typec = strtolower($iassign_t->type);
  4374. require_once 'ilm_handlers/' . $typec . '.php';
  4375. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4376. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4377. } // static function copy_new_version_ilm($param)
  4378. //VER::
  4379. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4380. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4381. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4382. /// Function for change visibility of iLM
  4383. // @param int $ilm_id Id of iLM
  4384. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4385. static function visible_ilm ($ilm_id, $status) {
  4386. global $DB;
  4387. if ($status == 0)
  4388. $visible = 1;
  4389. else
  4390. $visible = 0;
  4391. $newentry = new stdClass();
  4392. $newentry->id = $ilm_id;
  4393. $newentry->enable = $visible;
  4394. if (!$DB->update_record("iassign_ilm", $newentry))
  4395. error(get_string('error_edit_ilm', 'iassign'));
  4396. }
  4397. /// Function for confirm change default iLM
  4398. // @param int $ilm_id Id of iLM
  4399. // @param int $ilm_parent Id of parent iLM
  4400. // @return string Return with an string for create default page confirmation
  4401. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4402. global $OUTPUT, $DB;
  4403. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4404. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4405. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4406. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4407. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4408. return $return;
  4409. }
  4410. /// Function for change the default iLM
  4411. // @see settings_ilm.php
  4412. // @param int $ilm_id Id of iLM
  4413. // @return int Return Id of default iLM
  4414. static function default_ilm ($ilm_id) {
  4415. global $DB;
  4416. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4417. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4418. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4419. $iassign_ilm_default->id = $iassign_ilm->id;
  4420. $iassign_ilm_default->parent = 0;
  4421. $iassign_ilm->parent = $iassign_ilm_default->id;
  4422. $iassign_ilm->id = 0;
  4423. $iassign_ilm_default->enable = 1;
  4424. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4425. print_error('error_edit_ilm', 'iassign');
  4426. }
  4427. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4428. if (!$inserted) {
  4429. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4430. print_error($msg_error);
  4431. //xx print_error('error_add_ilm', 'iassign');
  4432. }
  4433. return $iassign_ilm_default->id;
  4434. } // static function default_ilm ($ilm_id)
  4435. /// Function for confirm delete iLM
  4436. // @param int $ilm_id Id of iLM
  4437. // @param int $ilm_parent Id of parent iLM
  4438. // @return string Return with an string for create delete page confirmation
  4439. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4440. global $OUTPUT, $DB;
  4441. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4442. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4443. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4444. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4445. }
  4446. /// Function for delete directory where the iLM is allocated.
  4447. // @param string $dirPath
  4448. // @throws InvalidArgumentException
  4449. public static function delete_dir ($dirPath) {
  4450. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4451. $dirPath .= '/';
  4452. }
  4453. $files = glob($dirPath . '*', GLOB_MARK);
  4454. foreach ($files as $file) {
  4455. if (is_dir($file)) {
  4456. ilm_settings::delete_dir($file);
  4457. } else {
  4458. unlink($file);
  4459. }
  4460. }
  4461. rmdir($dirPath);
  4462. }
  4463. /// Function for delete iLM
  4464. // @param int $ilm_id Id of iLM
  4465. // @return int Return Id of parent iLM
  4466. static function delete_ilm ($ilm_id) {
  4467. global $DB;
  4468. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4469. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4470. $typec = strtolower($iassign_ilm->type);
  4471. require_once 'ilm_handlers/' . $typec . '.php';
  4472. $retorno = $typec::delete_ilm($ilm_id);
  4473. return $retorno;
  4474. }
  4475. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4476. // @param int $ilm_id Id of iLM
  4477. static function export_ilm ($ilm_id) {
  4478. global $DB;
  4479. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4480. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4481. $typec = strtolower($iassign_ilm->type);
  4482. require_once 'ilm_handlers/' . $typec . '.php';
  4483. $typec::export_ilm($ilm_id);
  4484. } // static function export_ilm($ilm_id)
  4485. //TODO iLM_HTML5 :: //MOOC 2016
  4486. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4487. // @param int $ilm_id Id of iLM
  4488. static function export_update_ilm ($ilm_id) {
  4489. global $DB, $CFG;
  4490. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4491. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4492. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4493. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4494. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4495. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4496. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4497. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4498. $upgrade_descriptor .= '</upgrade>' . "\n";
  4499. file_put_contents($xml_filename, $upgrade_descriptor);
  4500. header("Pragma: public");
  4501. header("Expires: 0");
  4502. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4503. header("Cache-Control: private", false);
  4504. header('Content-Type: application/xml; charset=utf-8');
  4505. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4506. header("Content-Length: " . @filesize($xml_filename));
  4507. set_time_limit(0);
  4508. @readfile("$xml_filename") || die("File not found.");
  4509. unlink($xml_filename);
  4510. exit;
  4511. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4512. /// Function for save iLM from XML descriptor
  4513. // @param array $application_xml Data of XML descriptor
  4514. // @param array $files_extract Filenames of extract files
  4515. // @return array Return an array content id of JAR files
  4516. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4517. global $CFG, $USER;
  4518. // Tratamento diferenciado se for do tipo HTML5:
  4519. $source = "";
  4520. $diretorio = "";
  4521. if (strtolower($application_xml->type) == 'html5') {
  4522. $i = 0;
  4523. foreach ($files_extract as $key => $value) {
  4524. $file = $CFG->dataroot . '/temp/' . $key;
  4525. // Verifica se já existe a pasta no diretório dos iLM:
  4526. if ($i == 0) {
  4527. $source = $file;
  4528. if (file_exists("ilm/" . basename($file))) {
  4529. $j = 1;
  4530. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4531. $j ++;
  4532. }
  4533. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4534. // mkdir($diretorio, 0777, true);
  4535. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4536. }
  4537. else {
  4538. $diretorio = 'ilm/' . basename($file);
  4539. // mkdir($diretorio, 0777, true);
  4540. mkdir($diretorio, 0755, true);
  4541. }
  4542. break;
  4543. }
  4544. $i ++;
  4545. }
  4546. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4547. if ($item->isDir()) {
  4548. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4549. }
  4550. else {
  4551. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4552. }
  4553. }
  4554. ilm_settings::delete_dir($source);
  4555. return "./" . $diretorio;
  4556. }
  4557. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4558. $file_jar = array();
  4559. $files_ilm = explode(",", $application_xml->file_jar);
  4560. $contextsystem = context_system::instance();
  4561. foreach ($files_ilm as $value) {
  4562. $file_ilm = array(
  4563. 'userid' => $USER->id,
  4564. 'contextid' => $contextsystem->id,
  4565. 'component' => 'mod_iassign',
  4566. 'filearea' => 'ilm',
  4567. 'itemid' => rand(1, 999999999),
  4568. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4569. 'filename' => $value);
  4570. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4571. array_push($file_jar, $file_ilm->get_id());
  4572. }
  4573. foreach ($files_extract as $key => $value) {
  4574. $file = $CFG->dataroot . '/temp/' . $key;
  4575. if (file_exists($file))
  4576. unlink($file);
  4577. }
  4578. return $file_jar;
  4579. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4580. /// Function for import the iLM from an package
  4581. // @param int $itemid Itemid of zip file
  4582. static function import_ilm ($itemid) {
  4583. global $CFG, $USER, $OUTPUT;
  4584. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4585. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4586. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4587. }
  4588. $pathtemp = $CFG->dataroot . '/temp/';
  4589. $contextuser = context_user::instance($USER->id);
  4590. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4591. $zip = new zip_packer();
  4592. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4593. foreach ($files as $file) {
  4594. if (!$file->is_directory())
  4595. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4596. }
  4597. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4598. // Verifica se o pacote possui o XML
  4599. if (!$application_xml) {
  4600. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4601. return;
  4602. } else {
  4603. $missing = "";
  4604. if (!isset($application_xml->name)) {
  4605. $missing .= "name";
  4606. }
  4607. if (!isset($application_xml->version)) {
  4608. $missing .= ", version";
  4609. }
  4610. if (!isset($application_xml->type)) {
  4611. $missing .= ", type";
  4612. }
  4613. if (!isset($application_xml->extension)) {
  4614. $missing .= ", extension";
  4615. }
  4616. if (!isset($application_xml->file_jar)) {
  4617. $missing .= ", file_jar";
  4618. }
  4619. if (!isset($application_xml->file_class)) {
  4620. $missing .= ", file_class";
  4621. }
  4622. if (!isset($application_xml->width)) {
  4623. $missing .= ", width";
  4624. }
  4625. if (!isset($application_xml->height)) {
  4626. $missing .= ", height";
  4627. }
  4628. if (!isset($application_xml->evaluate)) {
  4629. $missing .= ", evaluate";
  4630. }
  4631. if (strlen($missing) > 2) {
  4632. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4633. return;
  4634. }
  4635. }
  4636. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4637. $typec = strtolower($application_xml->type);
  4638. require_once 'ilm_handlers/' . $typec . '.php';
  4639. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4640. } // static function import_ilm($itemid)
  4641. /// Function for list iLM defaults
  4642. // @return string Return an string with a table of iLM
  4643. static function list_ilm () {
  4644. global $DB, $OUTPUT;
  4645. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4646. $str = '';
  4647. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4648. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4649. if ($iassign_ilm) {
  4650. foreach ($iassign_ilm as $ilm) {
  4651. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4652. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4653. $str .= '<tr><td>';
  4654. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4655. $str .= '<tr>';
  4656. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4657. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4658. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4659. $str .= '</tr>';
  4660. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4661. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4662. $str .= '</table>';
  4663. $str .= '</td></tr>';
  4664. }
  4665. }
  4666. $str .= '</table>';
  4667. return $str;
  4668. }
  4669. /// Function for download and install an upgrade of an iLM
  4670. // @param int $ilm_id Id of iLM
  4671. static function upgrade_ilm ($ilm_id) {
  4672. global $DB, $CFG, $USER;
  4673. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4674. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4675. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4676. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4677. if (!$result)
  4678. print_error('error_upgrade_ilm', 'iassign');
  4679. else {
  4680. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4681. $extension = explode(".", $zip_filename);
  4682. if ($extension[count($extension) - 1] != 'ipz') {
  4683. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4684. die;
  4685. }
  4686. $zip = new zip_packer();
  4687. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4688. $contextuser = context_user::instance($USER->id);
  4689. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4690. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4691. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4692. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4693. if (file_exists($zip_filename))
  4694. unlink($zip_filename);
  4695. if (empty($file_jar)) {
  4696. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4697. print_error($msg_error);
  4698. //xx print_error('error_add_ilm', 'iassign');
  4699. }
  4700. else {
  4701. $newentry = new stdClass();
  4702. $newentry->name = (String) $application_xml->name;
  4703. $newentry->version = (String) $application_xml->version;
  4704. $newentry->url = (String) $application_xml->url;
  4705. $newentry->description = $description_str;
  4706. $newentry->extension = strtolower((String) $application_xml->extension);
  4707. $newentry->file_jar = implode(",", $file_jar);
  4708. $newentry->file_class = (String) $application_xml->file_class;
  4709. $newentry->width = (String) $application_xml->width;
  4710. $newentry->height = (String) $application_xml->height;
  4711. $newentry->enable = 0;
  4712. $newentry->timemodified = time();
  4713. $newentry->author = $USER->id;
  4714. $newentry->timecreated = time();
  4715. $newentry->evaluate = (String) $application_xml->evaluate;
  4716. $newentry->parent = $ilm_id;
  4717. }
  4718. }
  4719. return $iassign_ilm->id;
  4720. } // static function upgrade_ilm($ilm_id)
  4721. //MOOC2014 -- inicio
  4722. //TODO: REVIEW
  4723. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4724. // static function move_iassign($ilm_id)
  4725. //MOOC2014 -- final
  4726. /// Function for list iLM versions with all informations
  4727. // @return string Return an string with a table of iLM
  4728. static function view_ilm ($ilmid, $from) {
  4729. global $DB;
  4730. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4731. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4732. $typec = strtolower($iassign_ilm->type);
  4733. require_once 'ilm_handlers/' . $typec . '.php';
  4734. $retorno = $typec::view_ilm($ilmid, $from);
  4735. return $retorno;
  4736. }
  4737. /// Function for get form variables for add, edit, or copy iLM params
  4738. // @param int $ilm_param_id Id of iLM param
  4739. // @param string $action String with the action
  4740. // @return object Return an object with forms variables
  4741. static function add_edit_copy_param ($ilm_param_id, $action) {
  4742. global $DB;
  4743. require_once('params_form.php');
  4744. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4745. $param = new stdClass();
  4746. $param->action = $action;
  4747. $param->ilm_param_id = $ilm_param_id;
  4748. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4749. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4750. $type = $iassign_ilm_config->param_type;
  4751. if ($action == 'add') {
  4752. $param->title = get_string('add_ilm', 'iassign');
  4753. $param->iassign_ilmid = $ilm_param_id;
  4754. $param->param_name = "";
  4755. $param->param_value = "";
  4756. $param->description = "";
  4757. $param->visible = 1;
  4758. }
  4759. elseif ($action == 'edit') {
  4760. if ($iassign_ilm_config) {
  4761. $param->title = get_string('edit_ilm', 'iassign');
  4762. $param->id = $iassign_ilm_config->id;
  4763. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4764. $param->param_type = $type; //MOOC2014
  4765. $param->param_name = $iassign_ilm_config->param_name;
  4766. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4767. $param->param_value = $iassign_ilm_config->param_value;
  4768. else //MOOC2014
  4769. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4770. $param->param_value = $iassign_ilm_config->param_value;
  4771. $param->description = $iassign_ilm_config->description;
  4772. $param->visible = $iassign_ilm_config->visible;
  4773. }
  4774. }
  4775. elseif ($action == 'copy') {
  4776. if ($iassign_ilm_config) {
  4777. $param->title = get_string('copy_ilm', 'iassign');
  4778. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4779. $param->param_type = $type; //MOOC2014
  4780. $param->param_name = $iassign_ilm_config->param_name;
  4781. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4782. $param->param_value = $iassign_ilm_config->param_value;
  4783. else //MOOC2014
  4784. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4785. $param->description = $iassign_ilm_config->description;
  4786. $param->visible = $iassign_ilm_config->visible;
  4787. }
  4788. }
  4789. return $param;
  4790. } // static function add_edit_copy_param($ilm_param_id, $action)
  4791. /// Function for change visibility of iLM param
  4792. // @param int $ilm_param_id Id of iLM param
  4793. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4794. static function visible_param ($ilm_param_id, $status) {
  4795. global $DB, $CFG;
  4796. if ($status == 0)
  4797. $visible = 1;
  4798. else
  4799. $visible = 0;
  4800. $newentry = new stdClass();
  4801. $newentry->id = $ilm_param_id;
  4802. $newentry->visible = $visible;
  4803. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4804. error(get_string('error_edit_param', 'iassign'));
  4805. }
  4806. /// Function for save in database an new iLM param
  4807. // @param object $param An object with iLM params
  4808. static function add_param ($param) {
  4809. global $DB;
  4810. $newentry = new stdClass();
  4811. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4812. //MOOC2014 $newentry->param_name = $param->param_name;
  4813. $newentry->param_type = $param->param_type; //MOOC2014
  4814. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4815. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4816. $newentry->param_value = $param->param_value;
  4817. else //MOOC2014
  4818. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4819. $newentry->description = $param->description;
  4820. $newentry->visible = $param->visible;
  4821. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4822. if (!$newentry->id) {
  4823. print_error('error_add_param', 'iassign');
  4824. }
  4825. }
  4826. /// Function for save in database a iLM param edit
  4827. // @param object $param An object with iLM params
  4828. static function edit_param ($param) {
  4829. global $DB;
  4830. $updentry = new stdClass();
  4831. $updentry->id = $param->id;
  4832. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4833. $updentry->param_type = $param->param_type; //MOOC2014
  4834. // $updentry->param_name = $param->param_name;
  4835. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4836. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4837. $updentry->param_value = $param->param_value;
  4838. else //MOOC2014
  4839. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4840. $updentry->description = $param->description;
  4841. $updentry->visible = $param->visible;
  4842. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4843. error(get_string('error_edit_param', 'iassign'));
  4844. }
  4845. }
  4846. /// Function for save in database a iLM param copy
  4847. // @param object $param An object with iLM params
  4848. static function copy_param ($param) {
  4849. global $DB;
  4850. $newentry = new stdClass();
  4851. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4852. //$newentry->param_name = $param->param_name;
  4853. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4854. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4855. $newentry->param_value = $param->param_value;
  4856. else //MOOC2014
  4857. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4858. $newentry->description = $param->description;
  4859. $newentry->visible = $param->visible;
  4860. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4861. if (!$newentry->id) {
  4862. print_error('error_add_param', 'iassign');
  4863. }
  4864. }
  4865. /// Function for delete iLM param of database
  4866. // @param int $param_id Id of iLM param
  4867. static function delete_param ($param_id) {
  4868. global $DB;
  4869. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4870. print_error('error_delete_param', 'iassign');
  4871. }
  4872. }
  4873. } // class ilm_settings
  4874. /// Class for manage iLM files (editor).
  4875. class ilm_manager {
  4876. var $id; // course id
  4877. var $url;
  4878. var $from;
  4879. /// Constructor for the base ilm_manager class
  4880. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4881. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4882. function __construct ($id, $url, $from) {
  4883. $this->id = $id; // course id
  4884. $this->url = $url;
  4885. $this->from = $from;
  4886. }
  4887. /// Function to get iAssign content file in Moodle data (exercise)
  4888. // @calledby x function preview_ilm($iassign_ilm) :
  4889. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4890. function get_file_ilm () {
  4891. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4892. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4893. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4894. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4895. $md_file = $fs->get_file_by_id($fileid);
  4896. $ilm_content_file = $md_file->get_content();
  4897. return $ilm_content_file;
  4898. }
  4899. /// Function for creating a new file from the iLM online editor
  4900. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4901. function ilm_editor_new () {
  4902. global $CFG, $DB, $OUTPUT, $PAGE;
  4903. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4904. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4905. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4906. $context = context_course::instance($this->id);
  4907. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4908. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4909. if (!$iassign) {
  4910. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4911. die();
  4912. }
  4913. $temp = explode(",", $iassign->extension);
  4914. $extension = $temp[0]; // default extension for this iLM
  4915. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4916. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4917. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4918. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4919. if ($stringArchiveContent != NULL) {
  4920. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4921. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4922. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4923. $filename = optional_param('filename', NULL, PARAM_RAW);
  4924. //Leo $filename = iassign_utils::format_filename($filename); //
  4925. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4926. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4927. //2019/02 $arrayfilename = explode(".", $filename);
  4928. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4929. //2019/02 $count_dots = count($arrayfilename);
  4930. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4931. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4932. //2019/02 if ($last_name != $extension)
  4933. //2019/02 $filename = $filename . '.' . $extension;
  4934. //2019/02 }
  4935. //2019/02 else { // no extension...
  4936. //2019/02 $filename = $filename . '.' . $extension;
  4937. //2019/02 }
  4938. // Store the name of recent created file
  4939. $_SESSION['file_name'] = $filename;
  4940. //$this->write_file_iassign($string, $filename);
  4941. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4942. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4943. die();
  4944. }
  4945. else { // if ($stringArchiveContent != NULL)
  4946. // iLM On-line editor
  4947. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4948. $str_get_iLM = "window.frames.iLM";
  4949. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4950. }
  4951. else { // otherwise it is JAR named 'iLM'
  4952. $str_get_iLM = "document.iLM";
  4953. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4954. }
  4955. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4956. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4957. $files_array = '';
  4958. foreach ($files as $value) {
  4959. if ($value->get_filename() != ".")
  4960. $files_array .= "'" . $value->get_filename() . "',";
  4961. }
  4962. $files_array .= "''";
  4963. $file = null;
  4964. $ia_content = "";
  4965. $filename = "";
  4966. $error_files_exists = get_string('error_file_exists', 'iassign');
  4967. $output = "<script type='text/javascript'>
  4968. //<![CDATA[
  4969. //D alert('locallib.php: ilm_editor_new');
  4970. function submit_iLM_Answer () {
  4971. var docFormOnLineEditor = document.formEnvio;
  4972. var resposta_exerc = new Array(3);
  4973. var valor_resposta = new Array(3);
  4974. var sessao = new Array(3);
  4975. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4976. resposta_exerc[0] = doc_iLM.getAnswer();
  4977. valor_resposta[0] = doc_iLM.getEvaluation();
  4978. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4979. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4980. var files = new Array(" . $files_array . ");
  4981. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4982. if (docFormOnLineEditor.filename.value=='') {
  4983. // ERROR: the file name is empty
  4984. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4985. return false;
  4986. }
  4987. // }
  4988. for (i=0; i<files.length; i++) {
  4989. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4990. alert('" . $error_files_exists . "');
  4991. return false;
  4992. }
  4993. }
  4994. docFormOnLineEditor.submit();
  4995. return true;
  4996. }
  4997. //]]>
  4998. </script>\n";
  4999. $output .= "
  5000. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5001. $output .= $OUTPUT->box_start();
  5002. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5003. $output .= "
  5004. <table width='100%' cellpadding='20'>
  5005. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5006. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5007. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5008. </tr>
  5009. </table>\n";
  5010. $output .= $OUTPUT->box_end();
  5011. $output .= "<center>\n";
  5012. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5013. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5014. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5015. $output .= $output_ilm;
  5016. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5017. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5018. </center>
  5019. </form>\n";
  5020. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5021. $PAGE->navbar->add($title);
  5022. $PAGE->set_title($title);
  5023. $PAGE->set_heading($title); // insert title above the navigation bar
  5024. print $OUTPUT->header();
  5025. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5026. print $output;
  5027. print $OUTPUT->footer();
  5028. }
  5029. die();
  5030. } // function ilm_editor_new()
  5031. /// Function for editing an file in online editor
  5032. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5033. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5034. global $CFG, $DB, $OUTPUT, $PAGE;
  5035. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5036. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5037. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5038. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5039. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5040. // If iLM is not registered, error!
  5041. if (!$iassign) {
  5042. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5043. die;
  5044. }
  5045. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5046. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5047. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5048. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5049. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5050. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5051. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5052. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5053. if ($stringArchiveContent != NULL) {
  5054. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5055. die();
  5056. } else { // if ($stringArchiveContent != NULL)
  5057. $end_file = '';
  5058. if ($content_file) {
  5059. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5060. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5061. }
  5062. $temp = explode(",", $iassign->extension);
  5063. $extension = $temp[0]; // default extension for this iLM
  5064. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  5065. $str_get_iLM = "window.frames.iLM";
  5066. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5067. } else { // otherwise it is JAR named 'iLM'
  5068. $str_get_iLM = "document.iLM";
  5069. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5070. }
  5071. $output = "<script type='text/javascript'>
  5072. //<![CDATA[
  5073. function submit_iLM_Answer () {
  5074. var docFormEditor = document.formEnvio;
  5075. var activityAnswer; // to get activity answer (text)
  5076. var activityValue; // to get activity answer value (float)
  5077. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5078. //activityAnswer = doc_iLM.getAnswer();
  5079. //activityValue = doc_iLM.getEvaluation();
  5080. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5081. activityValue = " . $str_get_iLM . ".getEvaluation();
  5082. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5083. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5084. docFormEditor.submit();
  5085. return true;
  5086. }
  5087. //]]>
  5088. </script>\n";
  5089. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5090. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5091. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5092. // return true;
  5093. // }
  5094. $output .= "
  5095. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5096. $output .= $OUTPUT->box_start();
  5097. $output .= "
  5098. <table width='100%' cellpadding='20'>
  5099. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5100. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5101. <input type='hidden' name='filename' value='$filename'/></td>
  5102. <td>
  5103. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5104. </tr>
  5105. </table>\n";
  5106. $output .= $OUTPUT->box_end();
  5107. $output .= " <center>\n";
  5108. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5109. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5110. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5111. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5112. </center>
  5113. </form>\n";
  5114. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5115. $PAGE->navbar->add($title);
  5116. $PAGE->set_title($title);
  5117. $PAGE->set_heading($title); // insert title above the navigation bar
  5118. print $OUTPUT->header();
  5119. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5120. print $output;
  5121. print $OUTPUT->footer();
  5122. } // else if ($stringArchiveContent != NULL)
  5123. die();
  5124. } // function ilm_editor_update()
  5125. /// Function for write iAssign file in Moodle data (exercise)
  5126. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5127. // @param string $stringArchiveContent Content of iassign file
  5128. // @param string $filename Filename of iassign file
  5129. function write_file_iassign ($stringArchiveContent, $filename) {
  5130. global $USER;
  5131. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5132. $context = context_course::instance($this->id);
  5133. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5134. $dirid = $this->get_dir_ilm('dirid');
  5135. $dir = $fs->get_file_by_id($dirid);
  5136. $fileinfo = array('contextid' => $context->id, // ID of course
  5137. 'component' => 'mod_iassign', // usually = table name
  5138. 'filearea' => 'activity', // usually = table name
  5139. 'itemid' => 0, // usually = ID of row in table
  5140. 'filepath' => '/', // any path beginning and ending whith '/'
  5141. 'userid' => $USER->id,
  5142. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5143. 'filename' => $filename); // any filename
  5144. // Create file containing text. '$stringArchiveContent'
  5145. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5146. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5147. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5148. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5149. // 'Activité interactive enregistrée avec succès sous le nom:';
  5150. // 'Atividade interativa gravada com sucesso sob o nome:'
  5151. $output = "
  5152. <script type='text/javascript'>
  5153. //<![CDATA[
  5154. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5155. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5156. //]]>
  5157. </script>";
  5158. print $output;
  5159. die();
  5160. }
  5161. /// Function for write iAssign file in Moodle data (exercise)
  5162. // @param string $stringArchiveContent Content of iassign file
  5163. // @param string $filename Filename of iassign file
  5164. // @param int $itemid Itemid of iassign file
  5165. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5166. global $OUTPUT, $USER;
  5167. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5168. $context = context_course::instance($this->id);
  5169. $dirid = $this->get_dir_ilm('dirid');
  5170. if ($stringArchiveContent != (-1)) {
  5171. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5172. $file = $fs->get_file_by_id($fileid);
  5173. if (!$file) {
  5174. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5175. die;
  5176. }
  5177. $fileinfo = array('contextid' => $context->id, // ID of context
  5178. 'component' => 'mod_iassign', // usually = table name
  5179. 'filearea' => 'activity', // usually = table name
  5180. 'itemid' => 0, // usually = ID of row in table
  5181. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5182. 'userid' => $USER->id,
  5183. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5184. 'license' => 'allrightsreserved', // allrightsreserved
  5185. 'timecreated' => $file->get_timecreated(),
  5186. 'filename' => $file->get_filename()); // any filename
  5187. $file->delete();
  5188. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5189. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5190. }
  5191. $output = "<script type='text/javascript'>
  5192. //<![CDATA[
  5193. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5194. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5195. //]]>
  5196. </script>";
  5197. print $output;
  5198. die();
  5199. }
  5200. /// Function for create an tag for iAssign filter
  5201. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5202. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5203. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5204. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5205. // @param int $fileid Id of file
  5206. // @return string Return an string with an tag of iassign filter
  5207. function tag_ilm ($fileid) {
  5208. global $DB;
  5209. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5210. $width = '600';
  5211. $height = '400';
  5212. $file = $fs->get_file_by_id($fileid);
  5213. $filetype = explode(".", $file->get_filename());
  5214. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5215. foreach ($iassign_ilm as $value) {
  5216. $extensions = explode(",", $value->extension);
  5217. if (in_array($filetype[1], $extensions)) {
  5218. $width = $value->width;
  5219. $height = $value->height;
  5220. }
  5221. }
  5222. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5223. }
  5224. /// Function for delete iAssign file in Moodle data (exercise)
  5225. function delete_file_ilm () {
  5226. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5227. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5228. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5229. $file = $fs->get_file_by_id($fileid);
  5230. if ($file)
  5231. $file->delete();
  5232. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5233. die();
  5234. }
  5235. /// Function for delete selected iAssign file in Moodle data (exercise)
  5236. function delete_selected_ilm () {
  5237. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5238. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5239. $context = context_course::instance($this->id);
  5240. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5241. $dirid = $this->get_dir_ilm('dirid');
  5242. foreach ($files_id as $file_id) {
  5243. $file = $fs->get_file_by_id($file_id);
  5244. if ($file) {
  5245. if (!$file->is_directory())
  5246. $file->delete();
  5247. else {
  5248. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5249. foreach ($files_delete as $value)
  5250. $value->delete();
  5251. $file->delete();
  5252. }
  5253. }
  5254. }
  5255. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5256. die();
  5257. }
  5258. /// Function for duplicate iAssign file from "online" edition
  5259. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5260. function duplicate_file_ilm () {
  5261. global $USER, $COURSE;
  5262. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5263. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5264. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5265. $filename = optional_param('filename', NULL, PARAM_RAW);
  5266. $file = $fs->get_file_by_id($fileid);
  5267. $context = context_course::instance($this->id);
  5268. $fileinfo = array(
  5269. 'contextid' => $context->id, // ID of context
  5270. 'component' => 'mod_iassign', // usually = table name
  5271. 'filearea' => 'activity', // usually = table name
  5272. 'itemid' => 0, // usually = ID of row in table
  5273. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5274. 'userid' => $USER->id,
  5275. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5276. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5277. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5278. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5279. die();
  5280. }
  5281. /// Function for rename iAssign file
  5282. function rename_file_ilm () {
  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_TEXT);
  5287. $file = $fs->get_file_by_id($fileid);
  5288. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5289. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5290. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5291. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5292. die();
  5293. }
  5294. /// Function for get iassign file for iassign form
  5295. function add_ilm () {
  5296. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5297. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5298. $output = "
  5299. <script type='text/javascript'>
  5300. //<![CDATA[
  5301. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5302. iassign_file_link.innerHTML = '$filename';
  5303. window.opener.document.forms['mform1'].file.value='$fileid';
  5304. window.opener.document.forms['mform1'].filename.value='$filename';
  5305. window.close();
  5306. //]]>
  5307. </script>";
  5308. print $output;
  5309. die();
  5310. }
  5311. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5312. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5313. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5314. function preview_ilm ($courseid, $iassign_ilm) {
  5315. global $OUTPUT, $CFG, $USER;
  5316. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5317. $title = get_string('modulename', 'iassign'); // iAssign
  5318. print $OUTPUT->header();
  5319. print $OUTPUT->box_start();
  5320. $javascript = "
  5321. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5322. <script type='text/javascript'>
  5323. //<![CDATA[
  5324. function submit_close () {
  5325. window.opener.location.reload();
  5326. window.close();
  5327. }
  5328. //]]>
  5329. </script>\n";
  5330. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5331. // to the complete "applet" tag
  5332. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5333. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5334. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5335. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5336. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5337. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5338. if ($ilm_name != "ivprog") {
  5339. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5340. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5341. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5342. } else {
  5343. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5344. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5345. $timecreated = time();
  5346. $token = md5($timecreated);
  5347. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5348. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5349. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5350. $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)
  5351. }
  5352. $html = "
  5353. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5354. <table border='1'>
  5355. <tr><td>
  5356. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5357. <!-- iLM calls : end -->
  5358. </td></tr>
  5359. </table>
  5360. <table>
  5361. <tr>
  5362. <td align='center'>
  5363. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5364. </td></tr>
  5365. </table>
  5366. </form>\n";
  5367. print $javascript . $html;
  5368. print $OUTPUT->box_end();
  5369. //NAO echo format_string($html); // Moodle 3.X
  5370. die();
  5371. } // function preview_ilm($courseid, $iassign_ilm)
  5372. //r_ function preview_ilm ($iassign_ilm)
  5373. //r_ /// Function for preview iassign file from iassign filter.
  5374. //r_ function preview_ilm() {
  5375. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5376. //r_ $tag_filter = $this->tag_ilm($fileid);
  5377. //r_ $javascript = "<script type='text/javascript'>
  5378. //r_ //<![CDATA[
  5379. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5380. //r_ //]]>
  5381. //r_ </script>";
  5382. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5383. //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>
  5384. //r_ </table></form></body></html>";
  5385. //r_ echo $javascript . format_text($html);
  5386. //r_ die;
  5387. //r_ }
  5388. /// Function for export an package (zip) of iassign files
  5389. function export_files_ilm () {
  5390. global $CFG;
  5391. $context = context_course::instance($this->id);
  5392. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5393. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5394. $zip = new zip_archive();
  5395. $zip->open($zip_filename);
  5396. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5397. foreach ($files_id as $file_id) {
  5398. $file = $fs->get_file_by_id($file_id);
  5399. if (!$file->is_directory())
  5400. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5401. else {
  5402. $zip->add_directory($file->get_filepath());
  5403. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5404. foreach ($files_zip as $value) {
  5405. if (!$value->is_directory())
  5406. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5407. else
  5408. $zip->add_directory($value->get_filepath());
  5409. }
  5410. }
  5411. }
  5412. $zip->close();
  5413. header("Pragma: public");
  5414. header("Expires: 0");
  5415. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5416. header("Cache-Control: private", false);
  5417. header("Content-Type: application/zip");
  5418. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5419. header("Content-Transfer-Encoding: binary");
  5420. header("Content-Length: " . @filesize($zip_filename));
  5421. set_time_limit(0);
  5422. @readfile("$zip_filename") || die("File not found.");
  5423. unlink($zip_filename);
  5424. exit;
  5425. }
  5426. /// Function of execute a command in button editor tinymce
  5427. // @param int $fileid Id of file
  5428. function tinymce_ilm ($fileid) {
  5429. $tag_filter = $this->tag_ilm($fileid);
  5430. $output = "<script type='text/javascript'>
  5431. //<![CDATA[
  5432. var tag_filter = '$tag_filter';
  5433. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5434. // all right, insert it
  5435. } else {
  5436. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5437. }
  5438. // window.close();
  5439. //]]>
  5440. </script>\n";
  5441. print $output;
  5442. die();
  5443. }
  5444. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5445. /// Function to add content to the Editor Window
  5446. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5447. // @param int $fileid Id of file
  5448. function editor_ilm ($fileid, $editor) {
  5449. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5450. $output1 = "<script type='text/javascript'>
  5451. //<![CDATA[
  5452. var tag_filter = '$tag_filter';\n";
  5453. if ($editor == 'atto') {
  5454. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5455. } elseif ($editor == 'tinyMCE') {
  5456. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5457. } else
  5458. $output2 = "";
  5459. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5460. window.close();
  5461. //]]>
  5462. </script>\n";
  5463. //D var_dump($output);
  5464. print $output1 . $output2 . $output3;
  5465. die();
  5466. }
  5467. /// Function to add content to the Atto Editor Window
  5468. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5469. // @param int $fileid Id of file
  5470. function atto_ilm ($fileid) {
  5471. global $CFG, $DB;
  5472. $tag_filter = $this->tag_ilm($fileid);
  5473. $output = "<script type='text/javascript'>
  5474. //<![CDATA[
  5475. var tag_filter = '$tag_filter';
  5476. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5477. // all right, insert iLM tag to this editor
  5478. } else {
  5479. // error trying to insert
  5480. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5481. }
  5482. //window.close();
  5483. //]]>
  5484. </script>\n";
  5485. print $output;
  5486. die();
  5487. }
  5488. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5489. // @param string $key Key for return information
  5490. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5491. function get_dir_ilm ($key) {
  5492. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5493. $context = context_course::instance($this->id);
  5494. $dirid = optional_param('dirid', 0, PARAM_INT);
  5495. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5496. if ($dirid == 0) {
  5497. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5498. $dirid = $dir->get_id();
  5499. }
  5500. else {
  5501. $dir = $fs->get_file_by_id($dirid);
  5502. $dir_base = $dir->get_filepath();
  5503. }
  5504. $dir_parent = $dir->get_parent_directory();
  5505. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5506. return $data[$key];
  5507. }
  5508. /// Function for create an new dir
  5509. function new_dir_ilm () {
  5510. global $USER;
  5511. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5512. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5513. $dir_base = $this->get_dir_ilm('dir_base');
  5514. $context = context_course::instance($this->id);
  5515. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5516. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5517. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5518. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5519. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5520. }
  5521. /// Function for delete an dir
  5522. function delete_dir_ilm () { //
  5523. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5524. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5525. $context = context_course::instance($this->id);
  5526. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5527. $dir_parent = $this->get_dir_ilm('dir_parent');
  5528. if ($dir) {
  5529. if ($dir->is_directory()) {
  5530. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5531. foreach ($files_delete as $value)
  5532. $value->delete();
  5533. $dir->delete();
  5534. }
  5535. }
  5536. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5537. die();
  5538. }
  5539. /// Function for rename an dir
  5540. function rename_dir_ilm () {
  5541. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5542. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5543. $context = context_course::instance($this->id);
  5544. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5545. $dir_parent = $this->get_dir_ilm('dir_parent');
  5546. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5547. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5548. if ($dir->is_directory()) {
  5549. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5550. foreach ($files_rename_path as $value)
  5551. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5552. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5553. }
  5554. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5555. die();
  5556. }
  5557. /// Function for move an dir and your content for other dir
  5558. function selected_move_ilm () {
  5559. global $PAGE, $OUTPUT, $CFG;
  5560. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5561. $context = context_course::instance($this->id);
  5562. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5563. $dirid = $this->get_dir_ilm('dirid');
  5564. $dir_base = $this->get_dir_ilm('dir_base');
  5565. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5566. $code_javascript_ilm = "
  5567. <script type='text/javascript'>
  5568. //<![CDATA[
  5569. function getRadiobutton () {
  5570. var radioButtons = document.getElementsByTagName('input');
  5571. var param = '';
  5572. for (var counter=0; counter < radioButtons.length; counter++) {
  5573. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5574. param = radioButtons[counter].value;
  5575. }
  5576. return param;
  5577. }
  5578. function move_selected_ilm () {
  5579. var msgAnswer;
  5580. if (getRadiobutton() != '') {
  5581. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5582. if (msgAnswer)
  5583. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5584. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5585. }
  5586. else
  5587. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5588. }
  5589. function cancel_selected_ilm () {
  5590. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5591. }
  5592. //]]>
  5593. </script>\n";
  5594. $title = get_string('move_files', 'iassign');
  5595. $PAGE->set_title($title);
  5596. $PAGE->set_pagelayout('base');
  5597. print $OUTPUT->header();
  5598. print $OUTPUT->heading($title);
  5599. $dir_paths = array();
  5600. print $OUTPUT->box_start();
  5601. print "<center>";
  5602. foreach ($files_id as $file_id) {
  5603. $file = $fs->get_file_by_id($file_id);
  5604. if ($file) {
  5605. if (!$file->is_directory())
  5606. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5607. else {
  5608. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5609. array_push($dir_paths, $file->get_filepath());
  5610. }
  5611. }
  5612. }
  5613. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5614. if ($dir_base != '/') {
  5615. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5616. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5617. }
  5618. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5619. foreach ($files_tree as $file) {
  5620. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5621. $is_parent = false;
  5622. foreach ($dir_paths as $dir) {
  5623. $path = explode("/", $dir);
  5624. array_pop($path);
  5625. $path[count($path) - 1] = '';
  5626. $path = implode("/", $path);
  5627. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5628. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5629. }
  5630. if ($is_parent == false) {
  5631. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5632. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5633. }
  5634. }
  5635. }
  5636. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5637. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5638. print "</center>";
  5639. print $OUTPUT->box_end();
  5640. print $OUTPUT->footer();
  5641. print $code_javascript_ilm;
  5642. die;
  5643. }
  5644. /// Function for move files for an dir
  5645. function move_files_ilm () {
  5646. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5647. $context = context_course::instance($this->id);
  5648. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5649. $dirid = $this->get_dir_ilm('dirid');
  5650. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5651. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5652. foreach ($files_id as $file_id) {
  5653. $file = $fs->get_file_by_id($file_id);
  5654. if ($file) {
  5655. if ($file->is_directory()) {
  5656. $pathname = explode("/", $file->get_filepath());
  5657. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5658. foreach ($files_move_path as $value) {
  5659. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5660. $value->rename($path_move, $value->get_filename());
  5661. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5662. }
  5663. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5664. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5665. $file->rename($path_move, $file->get_filename());
  5666. } else {
  5667. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5668. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5669. }
  5670. }
  5671. }
  5672. //die;
  5673. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5674. die();
  5675. } // function move_files_ilm()
  5676. /// Function for recover files in use on all activities of a course
  5677. function recover_files_ilm () {
  5678. global $DB, $USER;
  5679. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5680. $courseid = optional_param('id', NULL, PARAM_INT);
  5681. $dirid = $this->get_dir_ilm('dirid');
  5682. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5683. $contextfile = context_course::instance($this->id);
  5684. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5685. foreach ($iassigns as $iassign) {
  5686. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5687. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5688. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5689. $context = context_module::instance($cm->id);
  5690. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5691. if ($files) {
  5692. foreach ($files as $value) {
  5693. $extension = explode(".", $value->get_filename());
  5694. if (!$value->is_directory()) {
  5695. $fileinfo = array('contextid' => $contextfile->id,
  5696. 'component' => 'mod_iassign',
  5697. 'filearea' => 'activity',
  5698. 'itemid' => 0,
  5699. 'filepath' => $this->get_dir_ilm('dir_base'),
  5700. 'userid' => $USER->id,
  5701. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5702. 'license' => 'allrightsreserved',
  5703. 'timecreated' => time(),
  5704. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5705. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5706. }
  5707. }
  5708. } // if ($files)
  5709. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5710. } // foreach ($iassigns as $iassign)
  5711. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5712. die();
  5713. } // function recover_files_ilm()
  5714. /// Auxiliary function the get all files in a given context
  5715. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5716. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5717. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5718. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5719. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5720. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5721. // (NAO s_iassign_statement.file = s_files.id)
  5722. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5723. $dir_base = $this->get_dir_ilm('dir_base');
  5724. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5725. $countf = 0;
  5726. $array_files_id = array(); // all files from this context
  5727. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5728. //$filename = $item_fc->get_filename();
  5729. //$filepath = $item_fc->get_filepath();
  5730. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5731. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5732. // $array_files_aux[] = $item_fc;
  5733. $itemid = $item_fc->get_id();
  5734. if (!in_array($itemid, $array_files_id)) {
  5735. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5736. if ($fileuserid == $userid)
  5737. $filesfrommine[] = $item_fc;
  5738. else
  5739. $filesfromothers[] = $item_fc;
  5740. $array_files_id[] = $itemid;
  5741. $countf++;
  5742. }
  5743. }
  5744. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5745. return $countf;
  5746. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5747. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5748. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5749. function get_all_ilm_files_by_fileid ($fileid) {
  5750. global $DB, $USER;
  5751. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5752. //TODO Criar coluna 'authorid'
  5753. $str_query = "SELECT * FROM {iassign_statement} " .
  5754. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5755. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5756. return $array_iassign_ilm;
  5757. }
  5758. //NN
  5759. //NN
  5760. // Build string with JavaScript code with function to edit/remove/double iLM files
  5761. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5762. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5763. global $CFG;
  5764. $error_files_exists = get_string('error_file_exists', 'iassign');
  5765. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5766. $code_javascript_ilm = "
  5767. <script type='text/javascript'>
  5768. //<![CDATA[
  5769. function preview_ilm (fileid, ilmid) { //JavaScript function
  5770. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5771. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5772. }
  5773. function update_ilm (ilmid, fileid) { //JavaScript function
  5774. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5775. }
  5776. function delete_ilm (ilmid, fileid) { //JavaScript function
  5777. var msgAnswer;
  5778. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5779. if (msgAnswer) {
  5780. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5781. }
  5782. }
  5783. function delete_selected_ilm () { //JavaScript function
  5784. var msgAnswer;
  5785. var param = getCheckbox();
  5786. if (param.join() != '') {
  5787. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5788. if (msgAnswer)
  5789. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5790. }
  5791. else
  5792. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5793. }
  5794. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5795. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5796. }
  5797. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5798. var filenamecopy;
  5799. var i;
  5800. var files = new Array(" . $files_array . ");
  5801. do {
  5802. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5803. } while (filenamecopy == '');
  5804. if (filenamecopy == null)
  5805. return false;\n
  5806. else {
  5807. for (i=0;i<files.length;i++) {
  5808. if (files[i]==filenamecopy) {
  5809. alert('" . $error_files_exists . "');
  5810. return false;\n
  5811. }
  5812. }\n" .
  5813. // @see: function 'duplicate_file_ilm()' above
  5814. "
  5815. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5816. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5817. } // else
  5818. }
  5819. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5820. var filenamecopy;
  5821. var i;
  5822. var files = new Array($files_array);
  5823. do {
  5824. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5825. } while (filenamecopy == '');
  5826. if (filenamecopy == null)
  5827. return false;
  5828. else {
  5829. for (i=0;i<files.length;i++) {
  5830. if (files[i]==filenamecopy) {
  5831. alert('" . $error_files_exists . "');
  5832. return false;
  5833. }
  5834. }
  5835. 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;
  5836. }
  5837. }
  5838. function export_files_ilm () { //JavaScript function
  5839. var param = getCheckbox();
  5840. if (param.join() != '')
  5841. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5842. else
  5843. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5844. }
  5845. function select_all_ilm () { //JavaScript function
  5846. var checkBoxes = document.getElementsByTagName('input');
  5847. var selectAll = document.getElementById('select_all');
  5848. for (var counter=0; counter < checkBoxes.length; counter++) {
  5849. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5850. checkBoxes[counter].checked = selectAll.checked;
  5851. }
  5852. }
  5853. function getCheckbox () { //JavaScript function
  5854. var checkBoxes = document.getElementsByTagName('input');
  5855. var param = new Array();
  5856. for (var counter=0; counter < checkBoxes.length; counter++) {
  5857. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5858. param.push(checkBoxes[counter].value);
  5859. }
  5860. return param;
  5861. }
  5862. function new_dir_ilm () { //JavaScript function
  5863. var dirname = '';
  5864. var i;
  5865. var dirs = new Array(" . $dirs_array . ");
  5866. do {
  5867. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5868. } while (dirname == '');
  5869. if (dirname == null)
  5870. return false;\n
  5871. else {
  5872. for (i=0;i<dirs.length;i++) {
  5873. if (dirs[i]==dirname) {
  5874. alert('" . $error_dir_exists . "');
  5875. return false;\n
  5876. }
  5877. }
  5878. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5879. }
  5880. }
  5881. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5882. var msgAnswer;
  5883. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5884. if (msgAnswer) {
  5885. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5886. }
  5887. }
  5888. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5889. var dirnamecopy;
  5890. var i;
  5891. var dirs = new Array($dirs_array);
  5892. do {
  5893. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5894. } while (dirnamecopy == '');
  5895. if (dirnamecopy == null)
  5896. return false;\n
  5897. else {
  5898. for (i=0;i<dirs.length;i++) {
  5899. if (dirs[i]==dirnamecopy) {
  5900. alert('" . $error_dir_exists . "');
  5901. return false;\n
  5902. }
  5903. }
  5904. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5905. }
  5906. }
  5907. function move_selected_ilm (ilmid) { //JavaScript function
  5908. var param = getCheckbox();
  5909. if (param.join() != '')
  5910. 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();
  5911. else
  5912. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5913. }
  5914. function recover_files_ilm () { //JavaScript function
  5915. var msgAnswer;
  5916. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5917. if (msgAnswer) {
  5918. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5919. }
  5920. }
  5921. window.onload = function() { //JavaScript function
  5922. var xPosition = 0;
  5923. var yPosition = 0;
  5924. element=document.getElementById('new_file');
  5925. while(element) {
  5926. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5927. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5928. element = element.offsetParent;
  5929. }
  5930. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5931. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5932. location.hash = '#new_file';
  5933. };
  5934. //]]>
  5935. </script>\n"; // end of $code_javascript_ilm
  5936. return $code_javascript_ilm;
  5937. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5938. /// List iassign files from course directory
  5939. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5940. function view_files_ilm ($iassign_ilm_class, $extension) {
  5941. global $CFG, $DB, $USER, $OUTPUT;
  5942. $fs = get_file_storage();
  5943. $context = context_course::instance($this->id);
  5944. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5945. $dirid = $this->get_dir_ilm('dirid');
  5946. $dir_base = $this->get_dir_ilm('dir_base');
  5947. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5948. $files_array = '';
  5949. foreach ($files_course as $value) {
  5950. if (!$value->is_directory())
  5951. $files_array .= "'" . $value->get_filename() . "',";
  5952. }
  5953. $files_array .= "''";
  5954. $error_files_exists = get_string('error_file_exists', 'iassign');
  5955. $dirs_array = '';
  5956. foreach ($files_course as $value) {
  5957. if ($value->is_directory()) {
  5958. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5959. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5960. }
  5961. }
  5962. $dirs_array .= "''";
  5963. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5964. // TODO Rever o preview pois só deixar ver uma vez.
  5965. $code_javascript_ilm = "
  5966. <script type='text/javascript'>
  5967. //<![CDATA[
  5968. function preview_ilm (fileid, ilmid) {
  5969. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5970. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5971. }
  5972. function update_ilm (ilmid, fileid) {
  5973. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5974. }
  5975. function delete_ilm (ilmid, fileid) {
  5976. var msgAnswer;
  5977. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5978. if (msgAnswer) {
  5979. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5980. }
  5981. }
  5982. function delete_selected_ilm () {
  5983. var msgAnswer;
  5984. var param = getCheckbox();
  5985. if (param.join() != '') {
  5986. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5987. if (msgAnswer)
  5988. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5989. }
  5990. else
  5991. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5992. }
  5993. function add_ilm_iassign (ilmid, filename, fileid) {
  5994. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5995. }
  5996. function duplicate_ilm (ilmid, filename, fileid) {
  5997. var filenamecopy;
  5998. var i;
  5999. var files = new Array($files_array);
  6000. do {
  6001. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6002. } while (filenamecopy == '');
  6003. if (filenamecopy == null)
  6004. return false;\n
  6005. else {
  6006. for (i=0;i<files.length;i++) {
  6007. if (files[i]==filenamecopy) {
  6008. alert('$error_files_exists');
  6009. return false;\n
  6010. }
  6011. }\n" .
  6012. // @see: function 'duplicate_file_ilm()' above
  6013. "
  6014. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6015. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6016. } // else
  6017. }
  6018. function rename_ilm (ilmid, filename, fileid) {
  6019. var filenamecopy;
  6020. var i;
  6021. var files = new Array($files_array);
  6022. do {
  6023. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6024. } while (filenamecopy == '');
  6025. if (filenamecopy == null)
  6026. return false;
  6027. else {
  6028. for (i=0;i<files.length;i++) {
  6029. if (files[i]==filenamecopy) {
  6030. alert('$error_files_exists');
  6031. return false;
  6032. }
  6033. }
  6034. 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;
  6035. }
  6036. }
  6037. function export_files_ilm () {
  6038. var param = getCheckbox();
  6039. if (param.join() != '')
  6040. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6041. else
  6042. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6043. }
  6044. function select_all_ilm () {
  6045. var checkBoxes = document.getElementsByTagName('input');
  6046. var selectAll = document.getElementById('select_all');
  6047. for (var counter=0; counter < checkBoxes.length; counter++) {
  6048. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6049. checkBoxes[counter].checked = selectAll.checked;
  6050. }
  6051. }
  6052. function getCheckbox () {
  6053. var checkBoxes = document.getElementsByTagName('input');
  6054. var param = new Array();
  6055. for (var counter=0; counter < checkBoxes.length; counter++) {
  6056. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6057. param.push(checkBoxes[counter].value);
  6058. }
  6059. return param;
  6060. }
  6061. function new_dir_ilm () {
  6062. var dirname = '';
  6063. var i;
  6064. var dirs = new Array($dirs_array);
  6065. do {
  6066. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6067. } while (dirname == '');
  6068. if (dirname == null)
  6069. return false;\n
  6070. else {
  6071. for (i=0;i<dirs.length;i++) {
  6072. if (dirs[i]==dirname) {
  6073. alert('$error_dir_exists');
  6074. return false;\n
  6075. }
  6076. }
  6077. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6078. }
  6079. }
  6080. function delete_dir_ilm (ilmid, dirid) {
  6081. var msgAnswer;
  6082. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6083. if (msgAnswer) {
  6084. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6085. }
  6086. }
  6087. function rename_dir_ilm (ilmid, dirname, dirid) {
  6088. var dirnamecopy;
  6089. var i;
  6090. var dirs = new Array($dirs_array);
  6091. do {
  6092. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6093. } while (dirnamecopy == '');
  6094. if (dirnamecopy == null)
  6095. return false;\n
  6096. else {
  6097. for (i=0;i<dirs.length;i++) {
  6098. if (dirs[i]==dirnamecopy) {
  6099. alert('$error_dir_exists');
  6100. return false;\n
  6101. }
  6102. }
  6103. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6104. }
  6105. }
  6106. function move_selected_ilm (ilmid) {
  6107. var param = getCheckbox();
  6108. if (param.join() != '')
  6109. 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();
  6110. else
  6111. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6112. }
  6113. function recover_files_ilm () {
  6114. var msgAnswer;
  6115. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6116. if (msgAnswer) {
  6117. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6118. }
  6119. }
  6120. window.onload = function() {
  6121. var xPosition = 0;
  6122. var yPosition = 0;
  6123. element=document.getElementById('new_file');
  6124. while(element) {
  6125. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6126. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6127. element = element.offsetParent;
  6128. }
  6129. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6130. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6131. location.hash = '#new_file';
  6132. };
  6133. //]]>
  6134. </script>\n";
  6135. $output = "";
  6136. $select_all = "";
  6137. $count_files = 0;
  6138. $extensions_allow = array();
  6139. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6140. foreach ($iassign_ilm as $item_iassign_ilm)
  6141. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6142. foreach ($files_course as $value) {
  6143. $filename = $value->get_filename();
  6144. $filepath = $value->get_filepath();
  6145. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6146. $pathname = $pathname[count($pathname) - 1];
  6147. $fileid = $value->get_id();
  6148. $tmp = explode(".", $filename);
  6149. if (count($tmp)>1) // avoid error if the file has no extension
  6150. $filetype = $tmp[1];
  6151. else // probably error...
  6152. $filetype = '';
  6153. $author = $value->get_author();
  6154. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6155. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6156. $extensions = explode(",", $extension);
  6157. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6158. $count_files ++;
  6159. // buscar fileid nas tabelas do iassign
  6160. $list_filein_use = "";
  6161. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6162. if ($iassign_statement_activity_list) {
  6163. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6164. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6165. }
  6166. }
  6167. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6168. if (!$iassign_ilm) {
  6169. $iassign_ilm = new stdClass();
  6170. $iassign_ilm->id = $ilmid;
  6171. }
  6172. // Do not use $var inside "..." - problem with some "unusual" operational system
  6173. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6174. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6175. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6176. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6177. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6178. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6179. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6180. $check_select = "";
  6181. $link_rename = "";
  6182. $link_delete = "";
  6183. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6184. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6185. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6186. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6187. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6188. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6189. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6190. if ($value->get_userid() == $USER->id) {
  6191. if ($iassign_statement_activity_list) {
  6192. $check_select = "";
  6193. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6194. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6195. $link_rename = "";
  6196. } else {
  6197. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6198. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6199. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6200. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6201. }
  6202. }
  6203. if (!in_array($filetype, $extensions_allow)) {
  6204. $link_edit = "";
  6205. $link_add_ilm_iassign = "";
  6206. $link_add_ilm_tinymce = "";
  6207. $link_add_ilm_atto = "";
  6208. $link_filter = "";
  6209. }
  6210. if ($value->is_directory()) {
  6211. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6212. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6213. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6214. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6215. <td><center>$author</center></td>
  6216. <td><center>$timecreated</center></td>
  6217. <td><center>$timemodified</center></td></tr>\n";
  6218. }
  6219. else if ($this->from == 'iassign') {
  6220. $new_id = "";
  6221. $new_class = "";
  6222. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6223. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6224. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6225. }
  6226. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6227. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6228. <td><center>$author</center></td>
  6229. <td><center>$timecreated</center></td>
  6230. <td><center>$timemodified</center></td></tr>\n";
  6231. }
  6232. else if ($this->from == 'block') {
  6233. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6234. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6235. <td><center>$author</center></td>
  6236. <td><center>$timecreated</center></td>
  6237. <td><center>$timemodified</center></td></tr>\n";
  6238. }
  6239. else if ($this->from == 'tinymce') {
  6240. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6241. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6242. <td><center>$author</center></td>
  6243. <td><center>$timecreated</center></td>
  6244. <td><center>$timemodified</center></td></tr>\n";
  6245. }
  6246. else if ($this->from == 'atto') {
  6247. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6248. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6249. <td><center>$author</center></td>
  6250. <td><center>$timecreated</center></td>
  6251. <td><center>$timemodified</center></td></tr>\n";
  6252. }
  6253. }
  6254. }
  6255. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6256. $dir_base = "";
  6257. $header = "";
  6258. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6259. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6260. foreach ($basename as $value) {
  6261. $dir_base .= $value . "/";
  6262. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6263. if ($dir_id) {
  6264. if ($value == "") {
  6265. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6266. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6267. } else {
  6268. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6269. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6270. }
  6271. }
  6272. } // foreach ($basename as $value)
  6273. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6274. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6275. $html .= "
  6276. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6277. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6278. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6279. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6280. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6281. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6282. </table>\n";
  6283. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6284. $html .= "<table width='100%'><tr>\n";
  6285. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6286. if ($count_files != 0) {
  6287. $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";
  6288. $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";
  6289. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6290. }
  6291. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6292. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6293. $html .= "</form>\n";
  6294. print $code_javascript_ilm;
  6295. print $html;
  6296. } // function view_files_ilm($extension)
  6297. } // class ilm_manager
  6298. /// Class to insert of icons
  6299. class iassign_icons {
  6300. static function insert ($icon) {
  6301. global $CFG;
  6302. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6303. return $string;
  6304. }
  6305. }
  6306. /// Class with util functions for plugin manage
  6307. class iassign_utils {
  6308. /// Function to return the filename extension
  6309. // @param string The $filename as an string
  6310. // @return string Return an string (last group after '.')
  6311. static function filename_extension ($filename) {
  6312. if ($filename == null || $filename == '') {
  6313. return null;
  6314. }
  6315. $itens = explode('.', $filename);
  6316. $num = count($itens);
  6317. if ($num < 2) {
  6318. return null;
  6319. }
  6320. return $itens[$num - 1];
  6321. }
  6322. /// Use the PHP class/package ZipArchive to create a Zip file
  6323. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6324. // 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
  6325. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6326. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6327. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6328. $zip = new zip_archive(); //2
  6329. $res = $zip->open($full_path_zip_filename);
  6330. $total_vet = count($vet_student_filename);
  6331. for ($ii=0; $ii<$total_vet; $ii++) {
  6332. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6333. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6334. }
  6335. $ret = $zip->close();
  6336. iassign_utils::download_file($full_path_zip_filename);
  6337. $filenameZip = $zip->filename;
  6338. return array($ret, $zip);
  6339. }
  6340. static function download_file ($zip_filename) {
  6341. header("Pragma: public");
  6342. header("Expires: 0");
  6343. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6344. header("Cache-Control: private", false);
  6345. header("Content-Type: application/zip");
  6346. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6347. header("Content-Transfer-Encoding: binary");
  6348. header("Content-Length: " . @filesize($zip_filename));
  6349. set_time_limit(0);
  6350. @readfile("$zip_filename") || die("File not found.");
  6351. unlink($zip_filename);
  6352. }
  6353. /// Function for format filename remove special caracters
  6354. // @param string $text String for clean
  6355. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6356. // @return string Return an string in clean format
  6357. static function format_filename ($text) {
  6358. if ($text != '.') {
  6359. //D $text = htmlspecialchars(urldecode($text));
  6360. //D echo "locallib.php: format_filename: $text<br/>";
  6361. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6362. $text = json_decode($text)->{current_language()};
  6363. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6364. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6365. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6366. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6367. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6368. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6369. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6370. // E.g. text = "exerc_midpoint.course.geo"
  6371. // 0123456789012345678901234
  6372. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6373. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6374. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6375. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6376. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6377. //$ext = strrpos($text, ".");
  6378. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6379. //$text = str_replace($array1, $array2, $text);
  6380. }
  6381. return $text;
  6382. }
  6383. /// Function to filter characters to the file name to iLM content
  6384. // @param string $text String for clean
  6385. // @param string $ext String ot the extension of the iLM
  6386. // @return string Return an string in clean format
  6387. static function filter_filename_extension ($filename, $ext) {
  6388. if ($filename != '.') {
  6389. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6390. $arrTo = array("_","","","","","","","","","","","","");
  6391. $filename = str_replace($arrFrom, $arrTo, $filename);
  6392. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6393. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6394. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6395. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6396. $index_lastposition = strlen($filenameF);
  6397. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6398. $text = str_replace(".", "_", $text); // erase all other "."
  6399. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6400. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6401. }
  6402. else
  6403. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6404. return $filenameF;
  6405. }
  6406. /// Function for format pathname remove special caracters
  6407. // @param string $text String for clean
  6408. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6409. // @return string Return an string in clean format
  6410. static function format_pathname ($text, $is_lowercase = true) {
  6411. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6412. $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", "-", "_", "", "", "");
  6413. $text = str_replace($array1, $array2, $text);
  6414. if ($is_lowercase)
  6415. $text = strtolower($text);
  6416. return $text;
  6417. }
  6418. /// Function for format file name from iLM original name
  6419. // @param string $text String to build the file neam
  6420. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6421. // @return string Return an string in clean format
  6422. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6423. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6424. $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", "-", "_", "", "", "");
  6425. $index_firstposition_blank = strpos($ilm_name, " ");
  6426. if ($index_firstposition_blank) { // truncate the name!
  6427. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6428. }
  6429. $index_firstposition_dots = strpos($ilm_name, ":");
  6430. if ($index_firstposition_dots) { // truncate the name!
  6431. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6432. }
  6433. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6434. if ($is_lowercase)
  6435. $namefiltered = strtolower($namefiltered);
  6436. return $namefiltered;
  6437. }
  6438. /// Function for insert version in the filename
  6439. // @param string $filename Name of file
  6440. // @return string Return the filename with version
  6441. static function version_filename ($filename) {
  6442. $array_filename = explode('.', $filename);
  6443. if (count($array_filename) > 1)
  6444. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6445. else
  6446. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6447. return $filename;
  6448. }
  6449. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6450. static function remove_code_message ($string) {
  6451. $array = explode("&lt;ia_uc&gt;", $string);
  6452. return $array[0];
  6453. }
  6454. }
  6455. // class iassign_utils
  6456. /// Class with language functions for plugin manage
  6457. class iassign_language {
  6458. /// Function for return text in language or get default language (en)
  6459. // @param string $lang Code of language
  6460. // @param string $description JSON text content all languages
  6461. // @return string Return an string in the language selected
  6462. static function get_description_lang ($lang, $descriptions) {
  6463. $description_lang = "";
  6464. $description = json_decode($descriptions);
  6465. if ($description == null) {
  6466. $description_lang = $descriptions;
  6467. }
  6468. else {
  6469. if (isset($description->{$lang}))
  6470. $description_lang = $description->{$lang};
  6471. else
  6472. if (isset($description->en)) //MOOC2014
  6473. $description_lang = $description->en;
  6474. else //MOOC2014
  6475. $description_lang = "en"; //MOOC2014
  6476. }
  6477. return $description_lang;
  6478. }
  6479. /// Function for return all language supported by iLM
  6480. // @param string $descriptions JSON text content all languages
  6481. // @return string Return as string with all languages
  6482. static function get_all_lang ($descriptions) {
  6483. $langs = "";
  6484. $description = json_decode($descriptions);
  6485. if ($description) {
  6486. foreach ($description as $key => $value) {
  6487. $langs .= $key . " ; ";
  6488. }
  6489. $langs = substr($langs, 0, strlen($langs) - 3);
  6490. }
  6491. return $langs;
  6492. }
  6493. /// Function for convert json in xml //MOOC2014
  6494. // @param string $json JSON text
  6495. // @return string Return as string with xml tags
  6496. static function json_to_xml ($json) {
  6497. $xml = "";
  6498. $json = json_decode($json);
  6499. foreach ($json as $key => $value) {
  6500. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6501. }
  6502. return $xml;
  6503. }
  6504. }
  6505. // class iassign_language
  6506. /// Class with log functions for plugin manage.
  6507. class iassign_log {
  6508. /// Function for insert log event
  6509. // @param string $action Code action of event
  6510. // @param string $information Text for describe action of event
  6511. // @param int $cmid Id of context module
  6512. // @param int $ilmid Id of iLM
  6513. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6514. global $COURSE, $CFG, $USER, $DB;
  6515. $newentry = new stdClass();
  6516. $newentry->time = time();
  6517. $newentry->userid = $USER->id;
  6518. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6519. $newentry->course = $COURSE->id;
  6520. $newentry->cmid = $cmid;
  6521. $newentry->ilmid = $ilmid;
  6522. $newentry->action = $action;
  6523. $newentry->info = $information;
  6524. $newentry->language = current_language();
  6525. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6526. if (ini_get("browscap") && function_exists('get_browse')) {
  6527. $browser = get_browse(null, true);
  6528. $newentry->javascript = $browser['javascript'];
  6529. $newentry->java = $browser['javaapplets'];
  6530. }
  6531. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6532. print_error('error_add_log', 'iassign');
  6533. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6534. } // class iassign_log