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. console.log((grade), (actual_student_grade));
  611. if ((grade) == (actual_student_grade)) {
  612. $("#"+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>\');
  613. } else { // Notas diferem:
  614. $("#"+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>\');
  615. var mm = actual_exercise;
  616. $("#"+id_t).find(".details-button").click(function(e) {
  617. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  618. });
  619. // Enviar para o endpoint post_auto_eval_result verificar:
  620. $.ajax({
  621. dataType: "html",
  622. 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),
  623. success: function(d) {}
  624. });
  625. }
  626. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  627. }
  628. }
  629. updateProgressBar();
  630. // Pode continuar no mesmo exercício ou para?
  631. if (actual_student < students.length) {
  632. actual_student ++;
  633. run_individual_evaluation();
  634. } else {
  635. actual_student = 0;
  636. // Pode ir para o próximo exercício ou acabou?
  637. if (actual_exercise < selected_exercises.length) {
  638. actual_exercise++;
  639. run_individual_evaluation();
  640. } else {
  641. $("#evaluate_alerts").text("'.get_string('auto_evaluate_finished', 'iassign').'");
  642. }
  643. }
  644. }
  645. var original_propositions;
  646. function get_original_propositions () {
  647. original_propositions = [];
  648. var count = 0;
  649. for (var i = 0; i < exercises.length; i++) {
  650. if($("#ex_"+exercises[i]).is(":checked") == true) {
  651. $.ajax({
  652. dataType: "html",
  653. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=get_teacher_exercise&id='.$this->cm->id.'&iassign_exercise="+exercises[i],
  654. success: function(d) {
  655. original_propositions[count] = d;
  656. count ++;
  657. if (count == selected_exercises.length) {
  658. run_individual_evaluation();
  659. }
  660. }
  661. });
  662. }
  663. }
  664. }
  665. function stop_evaluation () {
  666. stoped = true;
  667. $("#button_start").prop("disabled", false);
  668. $("#button_stop").prop("disabled", true);
  669. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  670. $("input:checkbox").attr("disabled", false);
  671. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  672. clearInterval(var_interval);
  673. }
  674. var exercises = [ ';
  675. foreach ($exercises_list as $exercise) {
  676. print $exercise->id . ',';
  677. }
  678. print ' ];';
  679. print ' var students = [ ';
  680. foreach ($students_list as $student) {
  681. print $student->userid . ',';
  682. }
  683. print '];';
  684. print ' var ilms = [';
  685. foreach ($exercises_list as $exercise) {
  686. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  687. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  688. }
  689. print ']';
  690. print '</script>';
  691. print '
  692. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  693. <div class="modal-dialog modal-dialog-centered" role="document">
  694. <div class="modal-content">
  695. <div class="modal-header">
  696. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('auto_evaluate_details', 'iassign').'</h5>
  697. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  698. <span aria-hidden="true">&times;</span>
  699. </button>
  700. </div>
  701. <div class="modal-body">
  702. ...
  703. </div>
  704. <div class="modal-footer">
  705. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('close', 'iassign').'</button>
  706. </div>
  707. </div>
  708. </div>
  709. </div>';
  710. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  711. print '<table id="table-results" class="table table-hover m-t-1">
  712. <thead>
  713. <tr id="cols-exercises">
  714. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  715. </tr>
  716. </thead>
  717. <tbody>';
  718. foreach ($students_list as $student) {
  719. $user = $DB->get_record('user', array('id' => $student->userid));
  720. $avatar = new user_picture($user);
  721. $avatar->courseid = $COURSE->id;
  722. $avatar->link = true;
  723. print
  724. '<tr data-student="'.$student->userid.'">
  725. <td>'.$OUTPUT->render($avatar). ' <span class="student-name">'.$user->firstname.' '.$user->lastname.'</span></td>
  726. </tr>';
  727. }
  728. print '</tbody>
  729. </table>';
  730. print $OUTPUT->footer();
  731. }
  732. /// This method moves an iAssign activity
  733. function move_activity () {
  734. global $USER, $CFG, $DB, $COURSE;
  735. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  736. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  737. $update_entry_new_iassign = new stdClass();
  738. $update_entry_new_iassign->id = $iassign_id;
  739. $update_entry_new_iassign->iassignid = $iassign_destiny;
  740. // Update the iassign_statement
  741. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  742. // Update file context
  743. $c_i = context_module::instance($this->cm->id);
  744. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  745. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  746. $path_module = context_course::instance($COURSE->id);
  747. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  748. if ($context_file) {
  749. $id_context = $context_file->id;
  750. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  751. $fs = get_file_storage(); // Get reference to all files in Moodle data
  752. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  753. foreach ($files as $value) {
  754. if ($value->get_filename() != ".") {
  755. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  756. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  757. $updateentry = new stdClass();
  758. $updateentry->id = $iassign_id;
  759. $updateentry->file = $newfile->get_itemid();
  760. $DB->update_record("iassign_statement", $updateentry);
  761. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  762. break;
  763. }
  764. }
  765. }
  766. $this->return_home_course('moved_activity');
  767. exit;
  768. }
  769. /// This method duplicates an iAssign activity
  770. function duplicate_activity () {
  771. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  772. $id = $this->cm->id;
  773. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  774. $context = context_module::instance($this->cm->id);
  775. $contextuser = context_user::instance($USER->id);
  776. // Get the the iAssign acitivity to be duplicated
  777. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  778. // Remove the current id of activity
  779. $iassign_statement->id=0;
  780. // Get the information about current author, and add this information in author_modified field
  781. $author = $DB->get_record("user", array('id' => $USER->id));
  782. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  783. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  784. // Store the activity in the table
  785. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  786. // Duplicate activity file
  787. $fs = get_file_storage(); // Get reference to all files in Moodle data
  788. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  789. foreach ($files as $value) {
  790. if ($value->get_filename() != ".") {
  791. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  792. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  793. $updateentry = new stdClass();
  794. $updateentry->id = $id_;
  795. $updateentry->file = $newfile->get_itemid();
  796. // Update the duplicated iLM iAssign with new file id
  797. $DB->update_record("iassign_statement", $updateentry);
  798. }
  799. }
  800. }
  801. // log event --------------------------------------------------------------------------------------
  802. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  803. $this->return_home_course('duplicated_activity');
  804. exit;
  805. }
  806. /// This method gets the content from the iLM and register it
  807. // It could be the "exercise template" (teacher) or an answer (student)
  808. function get_answer () {
  809. global $USER, $CFG, $DB, $OUTPUT;
  810. $id = $this->cm->id;
  811. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  812. $comment = false;
  813. if ($submission_comment)
  814. $comment = $this->write_comment_submission();
  815. // receives data of iLM using the current activity
  816. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  817. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  818. // receives data of submission of current activity
  819. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  820. // receives post and get
  821. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  822. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  823. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  824. $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)
  825. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  826. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  827. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  828. $msg = '';
  829. // Feedback
  830. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  831. $str_action = "view"; // repeat
  832. if (strtolower($iassign_ilm->name) == "igeom") {
  833. }
  834. $title = get_string('evaluate_iassign', 'iassign');
  835. print $OUTPUT->header();
  836. print $OUTPUT->box_start();
  837. // Action = { view ; repeat ; viewsubmission }
  838. // * '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")
  839. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  840. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  841. $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;
  842. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  843. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  844. print '<table width=100% >';
  845. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  846. //TODO alterar aqui???
  847. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  848. // empty_answer_post = No solution was posted.
  849. if ($comment)
  850. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  851. else
  852. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  853. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  854. } else {
  855. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  856. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  857. // Correct answer!!
  858. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  859. $this->write_solution = 1; //
  860. $status = 3;
  861. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  862. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  863. // log record
  864. $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;
  865. // Trigger module viewed event.
  866. $event = \mod_iassign\event\submission_created::create(array(
  867. 'objectid' => $this->iassign->id,
  868. 'context' => $this->context,
  869. 'other' => $info
  870. ));
  871. $event->add_record_snapshot('course', $this->course);
  872. $event->trigger();
  873. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  874. // Wrong answer...: get_answer_incorrect
  875. $status = 2;
  876. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  877. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  878. // log record
  879. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  880. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  881. // Trigger module viewed event.
  882. $event = \mod_iassign\event\submission_created::create(array(
  883. 'objectid' => $this->iassign->id,
  884. 'context' => $this->context,
  885. 'other' => $info
  886. ));
  887. $event->add_record_snapshot('course', $this->course);
  888. $event->trigger();
  889. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  890. // Presents to the learner the result of the automatic evaluate?
  891. if ($this->activity->get_activity()->show_answer == 0) { // no...
  892. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  893. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  894. print '<tr>';
  895. // log record
  896. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  897. // Trigger module viewed event.
  898. $event = \mod_iassign\event\submission_created::create(array(
  899. 'objectid' => $this->iassign->id,
  900. 'context' => $this->context,
  901. 'other' => $info
  902. ));
  903. $event->add_record_snapshot('course', $this->course);
  904. $event->trigger();
  905. } else { // yes!!!
  906. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  907. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  908. print '<tr>';
  909. print $msg;
  910. }
  911. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  912. $status = 1;
  913. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  914. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  915. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  916. print '<tr>';
  917. // log record
  918. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  919. $event = \mod_iassign\event\submission_created::create(array(
  920. 'objectid' => $this->iassign->id,
  921. 'context' => $this->context,
  922. 'other' => $info
  923. ));
  924. $event->add_record_snapshot('course', $this->course);
  925. $event->trigger();
  926. } // if ($iassign_ilm->evaluate == 1)
  927. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  928. print '</tr></table>';
  929. print $OUTPUT->box_end();
  930. // add or update evaluate
  931. if ($this->write_solution == 1) {
  932. $timenow = time();
  933. // new record
  934. if (!$iassign_submission) {
  935. $newentry = new stdClass();
  936. $newentry->userid = $this->userid_iassign;
  937. // $newentry->userid = $USER->id;
  938. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  939. $newentry->timecreated = $timenow;
  940. $newentry->timemodified = $timenow;
  941. $newentry->answer = $iLM_PARAM_ArchiveContent;
  942. $newentry->grade = round($grade_student, 2);
  943. $newentry->status = $status;
  944. $newentry->experiment = 1;
  945. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  946. print_error('error_insert', 'iassign');
  947. } else {
  948. // Trigger module viewed event.
  949. $event = \mod_iassign\event\submission_created::create(array(
  950. 'objectid' => $this->iassign->id,
  951. 'context' => $this->context
  952. ));
  953. $event->add_record_snapshot('course', $this->course);
  954. $event->trigger();
  955. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  956. }
  957. } elseif ($iassign_submission->status != 3) {
  958. $newentry = new stdClass();
  959. $newentry->id = $iassign_submission->id;
  960. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  961. $newentry->userid = $iassign_submission->userid;
  962. $newentry->timecreated = $iassign_submission->timecreated;
  963. $newentry->timemodified = $timenow;
  964. $newentry->answer = $iLM_PARAM_ArchiveContent;
  965. $newentry->grade = round($grade_student, 2);
  966. $newentry->status = $status;
  967. $newentry->experiment = $iassign_submission->experiment + 1;
  968. if (!$DB->update_record("iassign_submission", $newentry)) {
  969. print_error('error_update', 'iassign');
  970. //D depurar...
  971. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  972. //D $fp = fopen("teste1.txt","w");
  973. //D fwrite($fp,$stringAux);
  974. } else {
  975. // Trigger module viewed event.
  976. $event = \mod_iassign\event\submission_updated::create(array(
  977. 'objectid' => $this->iassign->id,
  978. 'context' => $this->context
  979. ));
  980. $event->add_record_snapshot('course', $this->course);
  981. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  982. }
  983. } else {
  984. if ($return_get_answer == 1) {
  985. $newentry = new stdClass();
  986. $newentry->id = $iassign_submission->id;
  987. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  988. $newentry->userid = $iassign_submission->userid;
  989. $newentry->timecreated = $iassign_submission->timecreated;
  990. $newentry->timemodified = $timenow;
  991. $newentry->answer = $iLM_PARAM_ArchiveContent;
  992. $newentry->grade = round($grade_student, 2);
  993. $newentry->status = $status;
  994. $newentry->experiment = $iassign_submission->experiment + 1;
  995. if (!$DB->update_record("iassign_submission", $newentry))
  996. print_error('error_update', 'iassign');
  997. else {
  998. $event = \mod_iassign\event\submission_updated::create(array(
  999. 'objectid' => $this->iassign->id,
  1000. 'context' => $this->context
  1001. ));
  1002. $event->add_record_snapshot('course', $this->course);
  1003. $event->trigger();
  1004. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1005. print $OUTPUT->box_start();
  1006. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1007. print $OUTPUT->box_end();
  1008. }
  1009. } elseif ($return_get_answer == 2) {
  1010. print $OUTPUT->box_start();
  1011. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1012. print $OUTPUT->box_end();
  1013. } else {
  1014. print $OUTPUT->box_start();
  1015. print "
  1016. <script type='text/javascript'>
  1017. //<![CDATA[
  1018. function overwrite () {
  1019. document.formEnvio.return_get_answer.value = 1;
  1020. document.formEnvio.submit();
  1021. }
  1022. function nooverwrite () {
  1023. document.formEnvio.return_get_answer.value = 2;
  1024. document.formEnvio.submit();
  1025. }
  1026. //]]>
  1027. </script>";
  1028. $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;
  1029. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1030. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1031. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1032. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1033. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1034. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1035. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1036. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1037. <input type='hidden' name='return_get_answer'/> ";
  1038. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1039. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1040. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1041. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1042. print " </form>";
  1043. print $OUTPUT->box_end();
  1044. }
  1045. }
  1046. } // if ($this->write_solution == 1)
  1047. print $OUTPUT->footer();
  1048. die();
  1049. } // function get_answer()
  1050. /// Export in file the answer of student.
  1051. function export_file_answer () {
  1052. global $DB;
  1053. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1054. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1055. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1056. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1057. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1058. $extensions = explode(",", $iassign_ilm->extension);
  1059. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1060. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1061. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1062. header("Pragma: public");
  1063. header("Expires: 0");
  1064. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1065. header("Cache-Control: private", false);
  1066. header("Content-Type: document/unknown");
  1067. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1068. set_time_limit(0);
  1069. print($iassign_submission->answer);
  1070. exit;
  1071. } // function export_file_answer()
  1072. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1073. // @calledby $this->export_package_answer()
  1074. //TODO Precisa terminar! //TODO_HTML
  1075. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1076. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1077. <head>
  1078. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1079. $str_html .= " </head>
  1080. <body>\n";
  1081. $tam = sizeof($array_iassign_name);
  1082. for ($ii=0; $ii<$tam; $ii++) {
  1083. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1084. }
  1085. $str_html .= "
  1086. </body>\n</html>";
  1087. return $str_html;
  1088. }
  1089. /// Export an package (zip) with all answer of students
  1090. // @calledby $this->action()
  1091. function export_package_answer () {
  1092. global $DB, $CFG, $OUTPUT;
  1093. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1094. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1095. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1096. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1097. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1098. $userid = optional_param('userid', NULL, PARAM_INT);
  1099. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1100. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1101. //TODO_HTML echo "username=$username<br/>"; exit;
  1102. $current_date = date('Y_m_d_H');
  1103. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1104. // If temporary directory under Moodle data does not exists => create it
  1105. if (!is_dir($diretorio)) {
  1106. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1107. // created directory with permissions to be seen by everyone
  1108. }
  1109. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1110. if (!is_writable($diretorio)) { // send a highlighted message!
  1111. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1112. exit; // just in case
  1113. }
  1114. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1115. $zip = new zip_archive(); // create ZIP
  1116. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1117. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1118. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1119. $vet_student_filename = array();
  1120. $vet_student_content = array();
  1121. foreach ($iassign_statements as $iassign_statement) {
  1122. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1123. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1124. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1125. $extensions = explode(",", $iassign_ilm->extension);
  1126. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1127. if ($iassign_submission) {
  1128. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1129. $student_content = $iassign_submission->answer;
  1130. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1131. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1132. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1133. if ($resp) {
  1134. $vet_student_filename[] = $student_filename;
  1135. $vet_student_content[] = $student_content;
  1136. }
  1137. else { // send a highlighted message!
  1138. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1139. exit; // just in case
  1140. }
  1141. }
  1142. }
  1143. $zip->close(); // close the ZIP file
  1144. if (count($vet_student_filename)>0) {
  1145. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1146. $result_tf = $vet_result[0];
  1147. $filenameZip = $vet_result[1]->filename;
  1148. }
  1149. iassign_utils::download_file($zip_filename); // download the ZIP file
  1150. exit;
  1151. } // function export_package_answer()
  1152. /// Editing status of interactive activities
  1153. function edit_status () {
  1154. global $USER, $DB, $OUTPUT;
  1155. $newentry = new stdClass();
  1156. $newentry->id = $this->iassign_submission_current;
  1157. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1158. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1159. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1160. $newentry->status = $iassign_submission->status;
  1161. $newentry->teacher = $USER->id;
  1162. if (!$DB->update_record('iassign_submission', $newentry))
  1163. print_error('error_update', 'iassign');
  1164. else {
  1165. // Trigger module viewed event.
  1166. $event = \mod_iassign\event\submission_updated::create(array(
  1167. 'objectid' => $this->iassign->id,
  1168. 'context' => $this->context
  1169. ));
  1170. $event->add_record_snapshot('course', $this->course);
  1171. $event->trigger();
  1172. $this->action = 'viewsubmission';
  1173. $this->view_iassign_current();
  1174. } // if (!$DB->update_record('iassign_submission', $newentry))
  1175. } // function edit_status()
  1176. /// Editing grade of interactive activities
  1177. function edit_grade () {
  1178. global $USER, $DB, $OUTPUT;
  1179. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1180. if ($newgrade && $newgrade >= 0) {
  1181. $newentry = new stdClass();
  1182. $newentry->id = $this->iassign_submission_current;
  1183. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1184. $newentry->teacher = $USER->id;
  1185. if (!$DB->update_record('iassign_submission', $newentry))
  1186. print_error('error_update', 'iassign');
  1187. else {
  1188. // Trigger module viewed event.
  1189. $event = \mod_iassign\event\submission_updated::create(array(
  1190. 'objectid' => $this->iassign->id,
  1191. 'context' => $this->context
  1192. ));
  1193. $event->add_record_snapshot('course', $this->course);
  1194. $event->trigger();
  1195. }
  1196. } // if ($newgrade >= 0)
  1197. $this->action = 'viewsubmission';
  1198. $this->view_iassign_current();
  1199. }
  1200. /// Add or Edit interactive activities
  1201. // @calledby $this->action()
  1202. function add_edit_iassign () {
  1203. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1204. require_once('iassign_form.php');
  1205. $id = $this->cm->id;
  1206. $iassignid = $this->iassign->id;
  1207. $param = new stdClass();
  1208. $param->action = $this->action; // oculto
  1209. $param->id = $id; // oculto
  1210. $COURSE->cm = $id;
  1211. $COURSE->iassignid = $iassignid;
  1212. $COURSE->iassign_file_id = NULL;
  1213. $context = context_module::instance($this->cm->id);
  1214. $contextuser = context_user::instance($USER->id);
  1215. $component = 'mod_iassign';
  1216. $filearea = 'exercise';
  1217. if (!empty($this->iassign_current))
  1218. $COURSE->iassign_id = $this->iassign_current;
  1219. else
  1220. $COURSE->iassign_id = 0;
  1221. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1222. if ($this->action == 'add') {
  1223. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1224. $params = array('iassignid' => $iassignid);
  1225. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1226. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1227. $total_of_activities = count($iassign_statement);
  1228. $param->iassignid = $iassignid;
  1229. $param->name = "";
  1230. $param->oldname = "";
  1231. $param->type_iassign = 3;
  1232. $param->proposition = "";
  1233. $author = $DB->get_record("user", array("id" => $USER->id));
  1234. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1235. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1236. $param->author = $param->author_name;
  1237. $param->author_modified = $param->author_modified_name;
  1238. $COURSE->iassign_list = array();
  1239. $param->iassign_list = array();
  1240. if ($iassign_statement) {
  1241. foreach ($iassign_statement as $iassign) {
  1242. $iassignid = $iassign->id;
  1243. $param->iassign_list[$iassignid] = 0;
  1244. $COURSE->iassign_list[$iassignid] = new stdClass();
  1245. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1246. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1247. $COURSE->iassign_list[$iassignid]->enable = 1;
  1248. } // foreach ($iassign_statement as $iassign)
  1249. }
  1250. $param->iassign_ilmid = 0;
  1251. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1252. $param->file = 0;
  1253. $param->fileold = 0;
  1254. $param->filename = "";
  1255. $param->grade = $iassign_data->grade;
  1256. $param->timemodified = time();
  1257. $param->timecreated = time();
  1258. $param->timeavailable = $iassign_data->timeavailable;
  1259. $param->timedue = $iassign_data->timedue;
  1260. $param->preventlate = $iassign_data->preventlate;
  1261. $param->test = $iassign_data->test;
  1262. $param->special_param1 = 0;
  1263. $param->visible = 1;
  1264. $param->max_experiment = $iassign_data->max_experiment;
  1265. $param->dependency = 0;
  1266. $param->automatic_evaluate = 1;
  1267. $param->show_answer = 1;
  1268. } // if ($this->action == 'add')
  1269. elseif ($this->action == 'edit') {
  1270. $COURSE->iassign_list = array();
  1271. $this_activity = $this->activity->get_activity();
  1272. if ($this_activity != null) {
  1273. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1274. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1275. $param->iassign_id = $iassign_statement_current->id; // oculto
  1276. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1277. $param->name = $iassign_statement_current->name;
  1278. $param->oldname = $iassign_statement_current->name;
  1279. $param->type_iassign = $iassign_statement_current->type_iassign;
  1280. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1281. //2019 $param->proposition = $iassign_statement_current->proposition;
  1282. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1283. $param->author_name = $iassign_statement_current->author_name; // oculto
  1284. $param->author = $iassign_statement_current->author_name;
  1285. $author = $DB->get_record("user", array('id' => $USER->id));
  1286. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1287. $param->author_modified = $param->author_modified_name;
  1288. $dependency = explode(';', $iassign_statement_current->dependency);
  1289. $param->iassign_list = array();
  1290. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1291. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1292. $array_dependency = array();
  1293. $subdependency = "";
  1294. $sub_subdependency = "";
  1295. // dependent on this exercise
  1296. if ($iassign_statement_dependency) {
  1297. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1298. // to whom this exercise depends
  1299. foreach ($inter as $tmp)
  1300. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1301. $list_dependency = $subdependency . $sub_subdependency;
  1302. $array_dependency = explode(";", $list_dependency);
  1303. }
  1304. // Get all activity with the same iLM - iassignid
  1305. $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";
  1306. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1307. $total_of_activities = count($all_others_iassign_statement) + 1;
  1308. $inter = array();
  1309. if ($all_others_iassign_statement) {
  1310. foreach ($all_others_iassign_statement as $iassign)
  1311. if (in_array($iassign->id, $dependency))
  1312. $inter[] = $iassign->id;
  1313. }
  1314. if ($all_others_iassign_statement) {
  1315. foreach ($all_others_iassign_statement as $iassign) {
  1316. $iassignid = $iassign->id;
  1317. $COURSE->iassign_list[$iassignid] = new stdClass();
  1318. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1319. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1320. if (in_array($iassignid, $dependency))
  1321. $param->iassign_list[$iassignid] = 1;
  1322. else
  1323. $param->iassign_list[$iassignid] = 0;
  1324. if (in_array($iassignid, $array_dependency))
  1325. $COURSE->iassign_list[$iassignid]->enable = 0;
  1326. else
  1327. $COURSE->iassign_list[$iassignid]->enable = 1;
  1328. } // foreach ($all_others_iassign_statement as $iassign)
  1329. }
  1330. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1331. $param->fileold = 0;
  1332. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1333. $param->filename = '';
  1334. $param->grade = $iassign_statement_current->grade;
  1335. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1336. $param->timeavailable = $iassign_statement_current->timeavailable;
  1337. $param->timedue = $iassign_statement_current->timedue;
  1338. $param->preventlate = $iassign_statement_current->preventlate;
  1339. $param->test = $iassign_statement_current->test;
  1340. $param->special_param1 = $iassign_statement_current->special_param1;
  1341. $param->position = $iassign_statement_current->position; // oculto
  1342. $param->visible = $iassign_statement_current->visible;
  1343. $param->max_experiment = $iassign_statement_current->max_experiment;
  1344. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1345. $param->show_answer = $iassign_statement_current->show_answer;
  1346. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1347. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1348. if ($files) {
  1349. foreach ($files as $file) {
  1350. if ($file->get_filename() != '.') {
  1351. $param->filename = $file->get_filename();
  1352. $param->file = $file->get_id();
  1353. $param->fileold = $file->get_id();
  1354. $COURSE->iassign_file_id = $file->get_id();
  1355. }
  1356. }
  1357. }
  1358. //TODO //MOOC2014 -- inicio
  1359. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1360. //D if ($iassign_ilm_configs) {
  1361. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1362. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1363. //D } //MOOC2014 -- fim
  1364. } // if ($this_activity != null)
  1365. } // elseif ($this->action == 'edit')
  1366. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1367. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1368. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1369. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1370. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1371. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1372. $param->position = $total_of_activities;
  1373. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1374. $mform->set_data($param);
  1375. if ($mform->is_cancelled()) {
  1376. $this->return_home_course('iassign_cancel');
  1377. exit;
  1378. }
  1379. else { // if ($mform->is_cancelled())
  1380. $result = $mform->get_data();
  1381. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1382. if ($result) {
  1383. $result->context = $context;
  1384. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1385. $result->grade = 0;
  1386. if ($result->type_iassign == 1) {
  1387. $result->automatic_evaluate = 0;
  1388. $result->show_answer = 0;
  1389. }
  1390. elseif ($result->automatic_evaluate == 0)
  1391. $result->show_answer = 0;
  1392. // $_POST['iassign_list']
  1393. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1394. if ($result->iassign_list) {
  1395. foreach ($result->iassign_list as $key => $value)
  1396. $result->dependency .= $key . ';';
  1397. }
  1398. else
  1399. $result->dependency = 0;
  1400. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1401. //TODO Then get it directly from the form data $_POST!
  1402. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1403. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1404. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1405. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1406. if ($this->action == 'add') {
  1407. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1408. if ($iassign_statement_name) {
  1409. $this->return_home_course('error_iassign_name');
  1410. die();
  1411. }
  1412. // Really insert the new iActivity in table '*_iassign_statement'
  1413. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1414. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1415. // Trigger module viewed event.
  1416. $event = \mod_iassign\event\iassign_created::create(array(
  1417. 'objectid' => $iassignid,
  1418. 'context' => $context
  1419. ));
  1420. $event->add_record_snapshot('course', $this->course);
  1421. $event->trigger();
  1422. $this->return_home_course('iassign_add');
  1423. } // if ($this->action == 'add')
  1424. elseif ($this->action == 'edit') {
  1425. $iassignid = $this->activity->update_iassign($result);
  1426. $this->activity->update_calendar($iassignid, $result->oldname);
  1427. // Trigger module viewed event.
  1428. $event = \mod_iassign\event\iassign_updated::create(array(
  1429. 'objectid' => $iassignid,
  1430. 'context' => $context
  1431. ));
  1432. $event->add_record_snapshot('course', $this->course);
  1433. $event->trigger();
  1434. $this->return_home_course('iassign_update');
  1435. } // elseif ($this->action == 'edit')
  1436. die();
  1437. } // if ($result)
  1438. } // else if ($mform->is_cancelled())
  1439. print $OUTPUT->header();
  1440. $mform->display();
  1441. print $OUTPUT->footer();
  1442. die();
  1443. } // function add_edit_iassign()
  1444. /// Search for dependencies
  1445. function search_dependency ($search_iassing_id, $iassign_statement) {
  1446. global $DB, $OUTPUT;
  1447. $dependency = "";
  1448. if ($iassign_statement)
  1449. foreach ($iassign_statement as $iassign) {
  1450. $inter_dependency = explode(';', $iassign->dependency);
  1451. if (in_array($search_iassing_id, $inter_dependency)) {
  1452. $dependency .= $iassign->id . ";";
  1453. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1454. } // if (in_array($search_iassing_id, $inter_dependency))
  1455. } // foreach ($iassign_statement as $iassign)
  1456. return $dependency;
  1457. }
  1458. /// Search for "sub"dependency
  1459. function search_sub_dependency ($search_iassing_id) {
  1460. global $DB, $OUTPUT;
  1461. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1462. $dependency = "";
  1463. if ($iassign_statement) {
  1464. $inter_dependency = explode(';', $iassign_statement->dependency);
  1465. foreach ($inter_dependency as $tmp) {
  1466. if ($tmp != 0)
  1467. $dependency .= $tmp . ";";
  1468. $dependency .= $this->search_sub_dependency($tmp);
  1469. } // foreach ($inter_dependency as $tmp)
  1470. } // if ($iassign_statement)
  1471. return $dependency;
  1472. }
  1473. // Warning message
  1474. static function warning_message_iassign ($strcode) {
  1475. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1476. }
  1477. /// Update grade of iAssign
  1478. // Called always any iAssign activity is created
  1479. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1480. static function update_grade_iassign ($iassignid) {
  1481. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1482. require_once($CFG->libdir . '/gradelib.php');
  1483. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1484. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1485. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1486. // Each iAssign item is associated with one item on the "gradebook"
  1487. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1488. //$sum_grade = 0;
  1489. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1490. //foreach($grade as $tmp) {
  1491. // $sum_grade += $tmp->grade;
  1492. // }
  1493. //1 Solution 1
  1494. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1495. //1 $sum_grade = 0; //1
  1496. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1497. //2 Solution 2
  1498. $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
  1499. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1500. if (key($array_sum_grade))
  1501. $sum_grade = key($array_sum_grade); //2
  1502. else
  1503. $sum_grade = 0; //2
  1504. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1505. $grades = NULL;
  1506. $params = array('itemname' => $grade_iassign->name);
  1507. $params['iteminstance'] = $iassignid;
  1508. $params['gradetype'] = GRADE_TYPE_VALUE;
  1509. //2016 if ($sum_grade != 0) {
  1510. $params['grademax'] = $sum_grade;
  1511. $params['rawgrademax'] = $sum_grade;
  1512. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1513. $params['grademin'] = 0;
  1514. // @calls /lib/gradelib.php: call to grade_item->insert()
  1515. //TODO: is there any error here in Moodle version 3.0?
  1516. //TODO: Incorrect property 'grademax' found when inserting grade object
  1517. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1518. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1519. }
  1520. /// Update grade of student
  1521. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1522. global $CFG, $DB, $OUTPUT;
  1523. require_once($CFG->libdir . '/gradelib.php');
  1524. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1525. // Review all the student submission for this iAssign activity
  1526. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1527. $total_grade = 0;
  1528. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1529. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1530. if ($iassign_submission)
  1531. $total_grade += $iassign_submission->grade;
  1532. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1533. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1534. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1535. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1536. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1537. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1538. $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
  1539. if (key($array_sum_grade))
  1540. $sum_grade = key($array_sum_grade); //2
  1541. else
  1542. $sum_grade = 0; //2
  1543. $grades['userid'] = $userid;
  1544. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1545. $params = array('itemname' => $grade_iassign->name);
  1546. $params['iteminstance'] = $iassignid;
  1547. $params['gradetype'] = GRADE_TYPE_VALUE;
  1548. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1549. $params['grademax'] = $sum_grade;
  1550. $params['rawgrademax'] = $sum_grade;
  1551. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1552. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1553. }
  1554. /// Display caption of icons
  1555. function view_legend_icons () {
  1556. global $USER, $CFG, $DB, $OUTPUT;
  1557. $id = $this->cm->id;
  1558. if ($this->action == 'print')
  1559. print '<table border=1 width=100%><tr>';
  1560. else
  1561. print '<table width=100%><tr>';
  1562. print '<td >';
  1563. if ($this->action != 'print')
  1564. print $OUTPUT->help_icon('legend', 'iassign');
  1565. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1566. // $imagetext = '');
  1567. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1568. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1569. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1570. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1571. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1572. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1573. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1574. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1575. print '</td>' . "\n";
  1576. if ($this->action != 'print') {
  1577. $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>";
  1578. $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>";
  1579. $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>";
  1580. $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>";
  1581. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1582. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1583. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1584. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1585. } // if ($this->action != 'print')
  1586. print '</tr></table>' . "\n";
  1587. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1588. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1589. $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>";
  1590. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1591. print '</tr></table>' . "\n";
  1592. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1593. else
  1594. print '</td></tr></table>' . "\n";
  1595. } // function view_legend_icons()
  1596. /// Display activity current
  1597. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1598. function view_iassign_current () {
  1599. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1600. $id = $this->cm->id;
  1601. $iassignid = $this->iassign->id;
  1602. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1603. $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
  1604. // 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 ...
  1605. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1606. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1607. $ilm_name = '';
  1608. if ($ilm->ilm)
  1609. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1610. // 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
  1611. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1612. // log record
  1613. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1614. //Trigger module viewed event.
  1615. $event = \mod_iassign\event\submission_viewed::create(array(
  1616. 'objectid' => $iassign->id,
  1617. 'context' => $this->context,
  1618. 'other' => $info
  1619. ));
  1620. $event->add_record_snapshot('course', $this->course);
  1621. $event->trigger();
  1622. // Search of iLM data used in the current activity
  1623. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1624. // Add actual activity to navbar:
  1625. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1626. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1627. print $OUTPUT->header();
  1628. if ($this->action == 'viewsubmission') {
  1629. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1630. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1631. else
  1632. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1633. } else {
  1634. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1635. }
  1636. if ($iassign_submission)
  1637. $this->update_comment($iassign_submission->id);
  1638. $file = $iassign_statement_activity_item->file;
  1639. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1640. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1641. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1642. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1643. $this->bottonPost = 0; // hide submit button
  1644. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1645. $this->view_iassign = false; // disable visualization of activity
  1646. $repeat = "";
  1647. $last_iassign = "";
  1648. $student_answer = "";
  1649. $comment = "";
  1650. // *** Teacher access (view learner's submission)
  1651. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1652. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1653. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1654. // ---> access teacher for test
  1655. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1656. $this->bottonPost = 1;
  1657. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1658. $this->activity->view_dates();
  1659. $USER->iassignEdit = $this->bottonPost;
  1660. $this->activity->show_info_iassign();
  1661. if ($iassign_submission) {
  1662. //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;
  1663. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1664. } else {
  1665. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1666. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1667. }
  1668. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1669. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1670. // Prepare tags to present the iLM
  1671. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1672. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1673. // *** (end) Teacher access (view the activity)
  1674. // *** Teacher access (view learner's submission to the activity)
  1675. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1676. // It is teacher or 'nonediting teacher' that can evaluate
  1677. // ----> area teacher evaluate
  1678. $row = optional_param('row', 0, PARAM_INT);
  1679. $column = optional_param('column', 0, PARAM_INT);
  1680. $link_next = iassign_icons::insert('right_disable');
  1681. $link_previous = iassign_icons::insert('left_disable');
  1682. $link_up = iassign_icons::insert('up_disable');
  1683. $link_down = iassign_icons::insert('down_disable');
  1684. // next_activity
  1685. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1686. $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);
  1687. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1688. }
  1689. // previous_activity
  1690. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1691. $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);
  1692. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1693. }
  1694. // previous_student
  1695. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1696. $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);
  1697. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1698. }
  1699. // next_student
  1700. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1701. $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);
  1702. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1703. }
  1704. if ($iassign_submission) {
  1705. $student_answer = $iassign_submission->answer;
  1706. }
  1707. $last_iassign = get_string('last_iassign', 'iassign');
  1708. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1709. // Messages related to due date (and user role)
  1710. $this->activity->view_dates();
  1711. print $OUTPUT->box_start();
  1712. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1713. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1714. print $OUTPUT->user_picture($user_data);
  1715. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1716. print '</td>' . "\n";
  1717. print '<td width=20% align=right>' . "\n";
  1718. print '<table width=50 cellpadding="0">';
  1719. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1720. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1721. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1722. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1723. print '</table>' . "\n";
  1724. print '</td></tr></table>' . "\n";
  1725. print $OUTPUT->box_end();
  1726. print $OUTPUT->box_start();
  1727. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1728. print '<td width=60% valign="top">' . "\n";
  1729. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1730. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1731. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1732. $resp = get_string('yes');
  1733. else
  1734. $resp = get_string('no');
  1735. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1736. if ($iassign_statement_activity_item->show_answer == 1)
  1737. $resp = get_string('yes');
  1738. else
  1739. $resp = get_string('no');
  1740. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1741. print '</td>';
  1742. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1743. print '<td width=40% valign="top" align="left">';
  1744. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1745. // check status of solution sent by the student
  1746. if ($iassign_submission) {
  1747. switch ($iassign_submission->status) {
  1748. case 3 :
  1749. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1750. break;
  1751. case 2 :
  1752. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1753. break;
  1754. case 1 :
  1755. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1756. break;
  1757. default :
  1758. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1759. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1760. } // switch ($iassign_submission->status)
  1761. }
  1762. else { // if ($iassign_submission)
  1763. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1764. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1765. }
  1766. // update_status
  1767. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1768. $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);
  1769. print " <script type='text/javascript'>
  1770. //<![CDATA[
  1771. function overwriteStatus (newstatus) {
  1772. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1773. document.formEditStatus.return_status.value=newstatus;
  1774. document.formEditStatus.submit();
  1775. }
  1776. else
  1777. document.formEditStatus.return_status.value=-1;
  1778. }
  1779. //]]>
  1780. </script>";
  1781. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1782. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1783. 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";
  1784. print " <input type='hidden' name='return_status'>\n";
  1785. print "</form>\n";
  1786. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1787. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1788. $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);
  1789. print "
  1790. <script type='text/javascript'>
  1791. //<![CDATA[
  1792. function overwriteGrade (newgrade,maxgrade) {
  1793. if (newgrade<0 || newgrade>maxgrade) {
  1794. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1795. document.formEditGrade.return_grade.value=-1;
  1796. document.formEditGrade.submit();
  1797. }
  1798. else {
  1799. document.formEditGrade.return_grade.value=newgrade;
  1800. document.formEditGrade.submit();
  1801. }
  1802. }
  1803. //]]>
  1804. </script>";
  1805. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1806. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1807. print " <input type='text' name='grade' size='6'>";
  1808. print " <input type='hidden' name='return_grade'> ";
  1809. 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";
  1810. print "</form>";
  1811. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1812. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1813. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1814. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1815. if ($teacher)
  1816. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1817. } // if ($iassign_submission->experiment > 0)
  1818. print '</td>';
  1819. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1820. print '</tr></table>';
  1821. print $OUTPUT->box_end();
  1822. $USER->iassignEdit = $this->bottonPost;
  1823. if ($iassign_submission && $allow_resubmission) {
  1824. // Put the iLM to
  1825. print $OUTPUT->box_start();
  1826. print '<p><strong>' . $last_iassign . '</strong></p>';
  1827. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1828. $enderecoPOST = "";
  1829. // Prepare tags to present the iLM
  1830. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1831. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1832. print $OUTPUT->box_end();
  1833. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1834. // ATTENTION: exception used by iGeom (exercise with "script")
  1835. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1836. if (substr($ilm_name, 0, 5)=="igeom") {
  1837. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1838. $loadTeacherActivity = true;
  1839. }
  1840. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1841. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1842. // Prepare tags to present the iLM
  1843. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1844. }
  1845. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1846. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1847. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1848. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1849. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1850. // *** (end) Teacher access (view learner's submission to the activity)
  1851. // *** Student access (view the activity)
  1852. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1853. // It could be the learner (he could send or resend the activity)
  1854. // ---> access student
  1855. $time_now = time();
  1856. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1857. // activity of type example - not submit button for submission
  1858. $this->view_iassign = true;
  1859. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1860. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1861. // activity of type test - iLM automatic evaluator - submit button for submission
  1862. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1863. $this->bottonPost = 1;
  1864. $this->view_iassign = true;
  1865. } else
  1866. $this->view_iassign = false;
  1867. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1868. // activity of type exercise (learner can send his answer, if yet open...)
  1869. $this->view_iassign = true;
  1870. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1871. $this->view_iassign = false;
  1872. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1873. $this->bottonPost = 1; // allow the submit button
  1874. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1875. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1876. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1877. if (!$iassign_submission) {
  1878. $str_iassign_submission_id = '';
  1879. $str_iassign_submission_answer = '';
  1880. }
  1881. else {
  1882. $str_iassign_submission_id = $iassign_submission->id;
  1883. $str_iassign_submission_answer = $iassign_submission->answer;
  1884. }
  1885. if ($this->action != 'repeat') {
  1886. $repeat = "<a href='view.php?action=repeat&id="
  1887. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1888. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1889. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1890. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1891. }
  1892. $this->bottonPost = 1;
  1893. $this->write_solution = 1; // can register his submission
  1894. $student_answer = $str_iassign_submission_answer;
  1895. }
  1896. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1897. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1898. $last_iassign = get_string('last_iassign', 'iassign');
  1899. if ($iassign_submission) {
  1900. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1901. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1902. $student_answer = $iassign_submission->answer;
  1903. } else {
  1904. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1905. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1906. }
  1907. }
  1908. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1909. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1910. $this->bottonPost = 1;
  1911. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1912. } else {
  1913. $last_iassign = get_string('last_iassign', 'iassign');
  1914. if ($iassign_submission) {
  1915. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1916. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1917. $student_answer = $iassign_submission->answer;
  1918. } else {
  1919. // Symbol of "redo activity"
  1920. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1921. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1922. }
  1923. }
  1924. } // elseif ($iassign_statement_activity_item->test == 1)
  1925. elseif ($iassign_statement_activity_item->test == 0)
  1926. $this->view_iassign = false;
  1927. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1928. if ($iassign_submission)
  1929. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1930. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1931. else
  1932. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1933. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1934. $this->activity->view_dates();
  1935. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1936. print $OUTPUT->box_start();
  1937. print '<table width=100% border=0 valign="top">' . "\n";
  1938. print '<tr><td width=60% valign="top">' . "\n";
  1939. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1940. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1941. $flag_dependency = true;
  1942. if ($iassign_statement_activity_item->type_iassign == 3) {
  1943. if ($iassign_statement_activity_item->dependency == 0) {
  1944. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1945. } else {
  1946. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1947. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1948. foreach ($dependencys as $dependency) {
  1949. if ($dependency) {
  1950. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1951. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1952. if ($dependencysubmissions) {
  1953. if ($dependencysubmissions->status == 3)
  1954. $icon = iassign_icons::insert('correct');
  1955. elseif ($dependencysubmissions->status == 2) {
  1956. $icon = iassign_icons::insert('incorrect');
  1957. $flag_dependency = false;
  1958. } elseif ($dependencysubmissions->status == 1) {
  1959. $icon = iassign_icons::insert('post');
  1960. $flag_dependency = false;
  1961. } elseif ($dependencysubmissions->status == 0) {
  1962. $icon = iassign_icons::insert('not_post');
  1963. $flag_dependency = false;
  1964. }
  1965. } else {
  1966. $icon = iassign_icons::insert('not_post');
  1967. $flag_dependency = false;
  1968. } // if ($dependencysubmissions)
  1969. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1970. } // if ($dependency)
  1971. } // foreach ($dependencys as $dependency)
  1972. } // if ($iassign_statement_activity_item->dependency == 0)
  1973. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1974. if ($flag_dependency == false) {
  1975. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1976. $this->view_iassign = false;
  1977. print '</tr></table>' . "\n";
  1978. }
  1979. else {
  1980. $this->view_iassign = true;
  1981. print '</td>' . "\n";
  1982. } // if ($flag_dependency == false)
  1983. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1984. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1985. // receiver=1 - message to teacher
  1986. // receiver=2 - message to student
  1987. if ($iassign_submission) {
  1988. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1989. if ($verify_message)
  1990. $comment = iassign_icons::insert('comment_unread');
  1991. }
  1992. print '<td width=40% valign="top" align="left">';
  1993. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1994. if ($iassign_statement_activity_item->show_answer == 1) {
  1995. // check status of solution sent by the student
  1996. if ($iassign_submission) {
  1997. switch ($iassign_submission->status) {
  1998. case 3 :
  1999. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2000. break;
  2001. case 2 :
  2002. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2003. break;
  2004. case 1 :
  2005. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2006. break;
  2007. default :
  2008. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2009. $repeat = "";
  2010. $last_iassign = "";
  2011. } // switch ($iassign_submission->status)
  2012. } else {
  2013. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2014. $repeat = "";
  2015. $last_iassign = "";
  2016. }
  2017. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2018. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2019. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2020. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2021. if ($iassign_statement_activity_item->max_experiment == 0)
  2022. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2023. else {
  2024. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2025. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2026. $repeat = "";
  2027. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2028. $this->bottonPost = 0;
  2029. $this->write_solution = 0;
  2030. }
  2031. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2032. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2033. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2034. if ($teacher)
  2035. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2036. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2037. } // if ($iassign_statement_activity_item->show_answer==1)
  2038. else {
  2039. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2040. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2041. $repeat = "";
  2042. $last_iassign = "";
  2043. } elseif ($iassign_submission->status == 1) {
  2044. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2045. }
  2046. }
  2047. print '</td>';
  2048. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2049. print '</tr></table>' . "\n";
  2050. // Presents the iLM
  2051. print '<table width=100% border=0 valign="top">' . "\n";
  2052. print '<td width=80% align="left">';
  2053. 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\".
  2054. print '<td width=20% align="rigth">';
  2055. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2056. print $repeat; // symbol of "redo activity"
  2057. print '</td></tr></table>' . "\n";
  2058. //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)'
  2059. $output = '';
  2060. if (!$iassign_ilm) {
  2061. $iassign_ilm = new stdClass();
  2062. $iassign_ilm->file_jar = "";
  2063. }
  2064. $output .= $OUTPUT->box_start();
  2065. $USER->iassignEdit = $this->bottonPost;
  2066. // ---
  2067. // Presents the iLM
  2068. // Prepare tags to present the iLM
  2069. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2070. $student_answer = ""; //?
  2071. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2072. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2073. $student_answer = "";
  2074. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2075. } else {
  2076. // When student is redoing his activity
  2077. // ATTENTION: exception used by iGeom (exercise with "script")
  2078. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2079. if (substr($ilm_name, 0, 5)=="igeom") {
  2080. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2081. $loadTeacherActivity = true;
  2082. }
  2083. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2084. }
  2085. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2086. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2087. //1 $history_comment = '';
  2088. //1 if ($iassign_submission) {
  2089. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2090. //1 }
  2091. //1 if (!empty($history_comment)) {
  2092. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2093. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2094. //1 $output .= $history_comment;
  2095. //1 $output .= "</table>\n";
  2096. //1 }
  2097. //1 $output .= "</form></center>\n";
  2098. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2099. //1 }
  2100. $output .= $OUTPUT->box_end();
  2101. print $output;
  2102. } // if ($this->view_iassign)
  2103. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2104. } // if ($this->view_iassign)
  2105. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2106. else
  2107. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2108. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2109. print '<table width=100% border=0 valign="top">' . "\n";
  2110. print '<tr><td width=60% valign="top">' . "\n";
  2111. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2112. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2113. print '</tr></table>' . "\n";
  2114. $student_answer = "";
  2115. $enderecoPOST = "";
  2116. // Prepare tags to present the iLM
  2117. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2118. print $output;
  2119. }
  2120. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2121. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2122. 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
  2123. // Put a block with area to sent/answer comments
  2124. $output = '';
  2125. $history_comment = '';
  2126. $row = optional_param('row', 0, PARAM_INT);
  2127. $column = optional_param('column', 0, PARAM_INT);
  2128. if ($iassign_submission) {
  2129. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2130. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2131. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2132. }
  2133. else {
  2134. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2135. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2136. }
  2137. $output .= $OUTPUT->box_start();
  2138. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  2139. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2140. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2141. $output .= "</form></center>\n";
  2142. if (!empty($history_comment)) {
  2143. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2144. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2145. $output .= $history_comment;
  2146. $output .= "</table>";
  2147. }
  2148. $output .= $OUTPUT->box_end();
  2149. print $output;
  2150. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2151. // final block 'studant'
  2152. print $OUTPUT->footer();
  2153. die();
  2154. } // function view_iassign_current()
  2155. /// Export the data from performance report into CSV file format
  2156. function export_csv () {
  2157. global $USER, $CFG, $DB, $OUTPUT;
  2158. $str = "";
  2159. $fields = "student_id, student_name";
  2160. // Finding all iassign activities for the iassign:
  2161. $id = $this->cm->id;
  2162. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2163. $c = 1;
  2164. foreach ($iassign_list as $iassign) {
  2165. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2166. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2167. $c ++;
  2168. }
  2169. // Finding enrolled students:
  2170. $params = array('shortname' => 'student');
  2171. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2172. $context = context_course::instance($this->course->id);
  2173. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2174. $students = $DB->get_records_sql(
  2175. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2176. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2177. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2178. foreach ($students as $student) {
  2179. $str .= $student->userid . ',';
  2180. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2181. foreach ($iassign_list as $iassign) {
  2182. $str .= ',' . $iassign->id . ',';
  2183. $str .= '"' . $iassign->name . '",';
  2184. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2185. if ($student_submissions) {
  2186. $str .= $student_submissions->experiment . ',';
  2187. $str .= $student_submissions->grade . ',';
  2188. switch ($student_submissions->status) {
  2189. case 3:
  2190. $str .= '"correct",';
  2191. break;
  2192. case 2:
  2193. $str .= '"incorrect",';
  2194. break;
  2195. case 1:
  2196. $str .= '"post",';
  2197. break;
  2198. case 0:
  2199. $str .= '"not_post",';
  2200. break;
  2201. }
  2202. } else {
  2203. $str .= ',,"not_post",';
  2204. }
  2205. $str .= $iassign->iassign_ilmid . ',';
  2206. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2207. $str .= '"' . $ilm_activity->name . '"';
  2208. }
  2209. $str .= "\n";
  2210. }
  2211. $str = $fields . "\n" . $str;
  2212. header("Content-type: text/csv");
  2213. header("Content-disposition: attachment; filename=report.csv");
  2214. header("Pragma: no-cache");
  2215. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2216. header('Content-Length: ' . strlen($str));
  2217. header('Connection: close');
  2218. print $str;
  2219. flush();
  2220. } // function export_csv()
  2221. /// Display report of performance
  2222. function report () {
  2223. global $USER, $CFG, $DB, $OUTPUT;
  2224. $id = $this->cm->id;
  2225. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2226. if ($this->action != 'print') {
  2227. $title = get_string('report', 'iassign');
  2228. print $OUTPUT->header();
  2229. } // if ($this->action != 'print')
  2230. print $OUTPUT->box_start();
  2231. $this->view_legend_icons();
  2232. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2233. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2234. print $OUTPUT->box_end();
  2235. if ($this->action == 'print')
  2236. print '<table border=1 width="100%">' . "\n";
  2237. else
  2238. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2239. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2240. // $num = array();
  2241. $i = 1;
  2242. $num = array();
  2243. foreach ($iassign_list as $iassign) {
  2244. $test_exercise = "";
  2245. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2246. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2247. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2248. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2249. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2250. $num[$i] = new stdClass();
  2251. $num[$i]->name = $iassign->name;
  2252. $num[$i]->id = $i;
  2253. $num[$i]->iassignid = $iassign->id;
  2254. print ' <tr >' . "\n";
  2255. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2256. print "<td class=\"cell c0 actvity\">";
  2257. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2258. print ' </tr>' . "\n";
  2259. $i ++;
  2260. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2261. } // foreach ($iassign_list as $iassign)
  2262. print "</table>";
  2263. print "<p></p>";
  2264. if ($this->action == 'print')
  2265. print '<table border=1 width="100%">' . "\n";
  2266. else
  2267. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2268. $context = context_course::instance($this->course->id);
  2269. if ($i > 1) {
  2270. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2271. $params = array('shortname' => 'student');
  2272. $role = $DB->get_record_sql(
  2273. "SELECT s.id, s.shortname FROM {role} s " .
  2274. " WHERE s.shortname = :shortname", $params);
  2275. // $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");
  2276. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2277. $students = $DB->get_records_sql(
  2278. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2279. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2280. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2281. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2282. for ($j = 1; $j < $i; $j ++) {
  2283. $sum_iassign_correct[$j] = 0;
  2284. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2285. }
  2286. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2287. $sum_iassign = $j - 1;
  2288. print '</tr>' . "\n";
  2289. $total = 0;
  2290. $sum_student = 0;
  2291. $comment = iassign_icons::insert('comment_read');
  2292. $sum_comment = 0;
  2293. $sum_correct_iassign = array();
  2294. $sum_correct_student = array();
  2295. $USER->matrix_iassign = array();
  2296. if ($students) {
  2297. $w = 0;
  2298. foreach ($students as $tmp) {
  2299. $users_array[$w] = $tmp;
  2300. $w ++;
  2301. }
  2302. for ($x = 0; $x < $w; $x ++) {
  2303. print '<tr>' . "\n";
  2304. $sum_student ++;
  2305. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2306. print ' <td >' . $name . '</td>' . "\n";
  2307. $total_student = 0;
  2308. $tentativas = 0;
  2309. for ($j = 1; $j < $i; $j ++) {
  2310. $sum_comment = 0;
  2311. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2312. print ' <td valign="bottom" align="center">' . "\n";
  2313. if ($student_submissions) {
  2314. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2315. $tentativas = $student_submissions->experiment;
  2316. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2317. $params = array('iassign_submissionid' => $student_submissions->id);
  2318. $student_submissions_comment = $DB->get_record_sql(
  2319. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2320. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2321. if ($student_submissions_comment)
  2322. foreach ($student_submissions_comment as $tmp)
  2323. $sum_comment = $tmp;
  2324. // informations to previous activities
  2325. if ($j - 1 < 1 || $j == $i)
  2326. $iassign_previous = "-1";
  2327. else
  2328. $iassign_previous = $num[$j - 1]->iassignid;
  2329. if ($x - 1 < 0 || $x == $w)
  2330. $user_previous = "-1";
  2331. else
  2332. $user_previous = $users_array[$x - 1]->userid;
  2333. // next
  2334. if ($i - 1 > $j)
  2335. $iassign_next = $num[$j + 1]->iassignid;
  2336. else
  2337. $iassign_next = "-1";
  2338. if ($w - 1 > $x)
  2339. $user_next = $users_array[$x + 1]->userid;
  2340. else
  2341. $user_next = "-1";
  2342. $position = "&row= $x&column=$j";
  2343. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2344. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2345. $url .= $position;
  2346. // receiver=1 - message to teacher
  2347. // receiver=2 - message to student
  2348. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2349. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2350. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2351. $verify_message = $DB->get_record_sql(
  2352. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2353. "WHERE iassign_submissionid = :iassign_submissionid " .
  2354. " AND return_status= :return_status " .
  2355. " AND receiver= :receiver", $params);
  2356. if ($verify_message)
  2357. foreach ($verify_message as $tmp)
  2358. $sum_verify_message = $tmp;
  2359. if ($sum_verify_message > 0)
  2360. $comment = iassign_icons::insert('comment_unread');
  2361. else
  2362. $comment = iassign_icons::insert('comment_read');
  2363. if ($student_submissions->status == 3) {
  2364. $sum_iassign_correct[$j] ++;
  2365. $total_student ++;
  2366. $feedback = iassign_icons::insert('correct');
  2367. }
  2368. elseif ($student_submissions->status == 2) {
  2369. $feedback = iassign_icons::insert('incorrect');
  2370. }
  2371. elseif ($student_submissions->status == 1) {
  2372. $feedback = iassign_icons::insert('post');
  2373. }
  2374. elseif ($student_submissions->status == 0) {
  2375. $feedback = iassign_icons::insert('not_post');
  2376. }
  2377. if ($this->action != 'print') {
  2378. print '<table><tr>';
  2379. if ($tentativas > 0)
  2380. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2381. else
  2382. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2383. print '<td> &nbsp; </td>';
  2384. print '</tr>' . "\n";
  2385. if ($sum_comment > 0 && $sum_verify_message > 0)
  2386. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2387. else if ($sum_comment > 0)
  2388. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2389. print '</table>' . "\n";
  2390. }
  2391. if ($this->action == 'print')
  2392. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2393. } // if ($student_submissions)
  2394. else { // if ($student_submissions)
  2395. // informations to browse previous activities
  2396. if ($j - 1 < 1 || $j == $i)
  2397. $iassign_previous = "-1";
  2398. else
  2399. $iassign_previous = $num[$j - 1]->iassignid;
  2400. if ($x - 1 < 0 || $x == $w)
  2401. $user_previous = "-1";
  2402. else
  2403. $user_previous = $users_array[$x - 1]->userid;
  2404. // next
  2405. if ($i - 1 > $j)
  2406. $iassign_next = $num[$j + 1]->iassignid;
  2407. else
  2408. $iassign_next = "-1";
  2409. if ($w - 1 > $x)
  2410. $user_next = $users_array[$x + 1]->userid;
  2411. else
  2412. $user_next = "-1";
  2413. $position = "&row= $x&column=$j";
  2414. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2415. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2416. $url .= $position;
  2417. $feedback = iassign_icons::insert('not_post');
  2418. if ($this->action == 'print')
  2419. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2420. else {
  2421. print '<table><tr>';
  2422. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2423. print '<td> &nbsp; </td>';
  2424. print '</tr><tr>' . "\n";
  2425. print '<td> &nbsp;</td>';
  2426. if ($sum_comment > 0)
  2427. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2428. else
  2429. print '<td> &nbsp;</td>';
  2430. print '</tr></table>';
  2431. }
  2432. } // else if ($student_submissions)
  2433. $USER->matrix_iassign[$x][$j] = new stdClass();
  2434. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2435. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2436. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2437. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2438. if ($student_submissions)
  2439. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2440. else
  2441. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2442. print '</td>' . "\n";
  2443. } // for ($j=1; $j<$i; $j++)
  2444. $total = $total + $total_student;
  2445. $porcentagem = ($total_student / ($j - 1)) * 100;
  2446. if ($tentativas != 0 && $tentativas != null) {
  2447. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2448. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2449. }
  2450. else {
  2451. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2452. }
  2453. print '</tr>' . "\n";
  2454. $sum_correct_student[$sum_student] = new stdClass();
  2455. $sum_correct_student[$sum_student]->name = $name;
  2456. $sum_correct_student[$sum_student]->sum = $total_student;
  2457. } // for ($x = 0; $x < $w; $x ++)
  2458. for ($i = 1; $i < $j; $i ++) {
  2459. if (is_null($sum_iassign_correct[$i]))
  2460. $sum_iassign_correct[$i] = 0;
  2461. $sum_correct_iassign[$i] = new stdClass();
  2462. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2463. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2464. }
  2465. // print '</tr></table>' . "\n";
  2466. }
  2467. } // if ($i>1)
  2468. else {
  2469. print_string('no_activity', 'iassign');
  2470. }
  2471. print "</table>\n";
  2472. if ($this->action != 'print')
  2473. print $OUTPUT->footer();
  2474. die();
  2475. } // function report()
  2476. /// Display graphics of performance
  2477. function stats () {
  2478. global $USER, $CFG, $DB, $OUTPUT;
  2479. $id = $this->cm->id;
  2480. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2481. if ($this->action != 'printstats')
  2482. $title = get_string('graphic', 'iassign');
  2483. $num = array();
  2484. $sum_correct_iassign = array();
  2485. $sum_correct_student = array();
  2486. $sum_student = 0;
  2487. $i = 1;
  2488. foreach ($iassign_list as $iassign) {
  2489. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2490. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2491. $sum_iassign_correct[$i] = 0;
  2492. $num[$i] = new stdClass();
  2493. $num[$i]->name = $iassign->name;
  2494. $num[$i]->id = $i;
  2495. $num[$i]->iassignid = $iassign->id;
  2496. $i ++;
  2497. } // if ($iassign->type_iassign == 3)
  2498. } // foreach ($iassign_list as $iassign)
  2499. $sum_iassign = $i - 1;
  2500. $context = context_course::instance($this->course->id);
  2501. if ($i > 1) {
  2502. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2503. $params = array('shortname' => 'student');
  2504. $role = $DB->get_record_sql(
  2505. "SELECT s.id, s.shortname FROM {role} s " .
  2506. " WHERE s.shortname = :shortname", $params);
  2507. // $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");
  2508. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2509. $students = $DB->get_records_sql(
  2510. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2511. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2512. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2513. $total = 0;
  2514. $sum_student = 0;
  2515. $j = 0;
  2516. $sum_correct_iassign = array();
  2517. $sum_correct_student = array();
  2518. $sum_experiment = array();
  2519. if ($students) {
  2520. foreach ($students as $users) {
  2521. $sum_student ++;
  2522. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2523. // rows
  2524. $total_student = 0;
  2525. for ($j = 1; $j < $i; $j ++) {
  2526. $total_experiment = 0;
  2527. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2528. if ($student_submissions) {
  2529. if ($student_submissions->status == 3) {
  2530. $sum_iassign_correct[$j] ++;
  2531. $total_student ++;
  2532. } // if ($student_submissions->status == 3)
  2533. $total_experiment += $student_submissions->experiment;
  2534. }
  2535. $sum_experiment[$j] = $total_experiment;
  2536. } // for ($j=1; $j<$i; $j++)
  2537. $total = $total + $total_student;
  2538. $sum_correct_student[$sum_student] = new stdClass();
  2539. $sum_correct_student[$sum_student]->name = $name;
  2540. $sum_correct_student[$sum_student]->sum = $total_student;
  2541. } // foreach ($students as $users)
  2542. }
  2543. for ($i = 1; $i < $j; $i ++) {
  2544. if (is_null($sum_iassign_correct[$i]))
  2545. $sum_iassign_correct[$i] = 0;
  2546. $sum_correct_iassign[$i] = new stdClass();
  2547. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2548. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2549. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2550. } // for ($i = 1; $i < $j; $i++)
  2551. } // if ($i > 1)
  2552. if ($this->action != 'printstats') {
  2553. $title = get_string('graphic', 'iassign');
  2554. print $OUTPUT->header();
  2555. $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>";
  2556. $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>";
  2557. print '<table width=100%><tr>';
  2558. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2559. print '<td width=15% align="right">' . $link_report . '</td>';
  2560. print '</td></tr></table>' . "\n";
  2561. print "<br><br>";
  2562. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2563. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2564. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2565. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2566. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2567. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2568. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2569. print '</tr>' . "\n";
  2570. $sum_correct = 0;
  2571. if ($sum_correct_iassign) {
  2572. foreach ($sum_correct_iassign as $iassign) {
  2573. if (is_null($iassign->experiment))
  2574. $iassign->experiment = 0;
  2575. $bar = "";
  2576. $sum = $iassign->sum;
  2577. $percent = ($sum / $sum_student) * 100;
  2578. $text = number_format($percent, 1) . '%';
  2579. $sum_correct += $sum;
  2580. if ($sum > 0) {
  2581. for ($i = 1; $i < $percent * 2; $i ++)
  2582. $bar .= iassign_icons::insert('hbar_blue');
  2583. $bar .= iassign_icons::insert('hbar_blue_r');
  2584. } // if ($sum > 0)
  2585. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2586. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2587. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2588. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2589. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2590. print '</tr>' . "\n";
  2591. } // foreach ($sum_correct_iassign as $iassign)
  2592. }
  2593. print "</table>";
  2594. print "<br><br>";
  2595. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2596. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2597. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2598. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2599. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2600. print '</tr>' . "\n";
  2601. $sum_correct = 0;
  2602. foreach ($sum_correct_student as $student) {
  2603. $bar = "";
  2604. $sum = $student->sum;
  2605. $percent = ($sum / $sum_iassign) * 100;
  2606. $text = number_format($percent, 1) . '%';
  2607. $sum_correct += $sum;
  2608. if ($sum > 0) {
  2609. for ($i = 1; $i < $percent * 2; $i ++)
  2610. $bar .= iassign_icons::insert('hbar_blue');
  2611. $bar .= iassign_icons::insert('hbar_blue_r');
  2612. } // if ($sum > 0)
  2613. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2614. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2615. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2616. print '</tr>' . "\n";
  2617. } // foreach ($sum_correct_student as $student)
  2618. print "</table>\n";
  2619. print "<br><br>\n";
  2620. $var = 0;
  2621. $cv = 0;
  2622. $dv = 0;
  2623. $avg = 0;
  2624. if ($sum_correct_student) {
  2625. $avg = $sum_correct / $sum_student;
  2626. if ($avg > 0) {
  2627. foreach ($sum_correct_student as $student)
  2628. $var += pow($student->sum - $avg, 2);
  2629. $var = $var / $sum_student;
  2630. $dv = sqrt($var);
  2631. $cv = ($dv / $avg) * 100;
  2632. }
  2633. }
  2634. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2635. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2636. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2637. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2638. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2639. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2640. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2641. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2642. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2643. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2644. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2645. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2646. print "</table>\n";
  2647. print $OUTPUT->footer();
  2648. } else {
  2649. print "<STYLE TYPE='text/css'>
  2650. <!--
  2651. .boldtable {
  2652. font-family:sans-serif;
  2653. font-size:10pt;
  2654. }
  2655. -->
  2656. </STYLE>\n";
  2657. print '<table border=1 width=100%>' . "\n";
  2658. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2659. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2660. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2661. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2662. print '</tr>' . "\n";
  2663. $sum_correct = 0;
  2664. foreach ($sum_correct_iassign as $iassign) {
  2665. $bar = "";
  2666. $sum = $iassign->sum;
  2667. $percent = ($sum / $sum_student) * 100;
  2668. $text = number_format($percent, 1) . '%';
  2669. $sum_correct += $sum;
  2670. if ($sum > 0) {
  2671. for ($i = 1; $i < $percent * 2; $i ++)
  2672. $bar .= iassign_icons::insert('hbar_blue');
  2673. $bar .= iassign_icons::insert('hbar_blue_r');
  2674. } // if ($sum > 0)
  2675. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2676. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2677. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2678. print '</tr>' . "\n";
  2679. } // foreach ($sum_correct_iassign as $iassign)
  2680. print "</table>";
  2681. print "<br><br>";
  2682. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2683. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2684. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2685. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2686. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2687. print '</tr>' . "\n";
  2688. $sum_correct = 0;
  2689. foreach ($sum_correct_student as $student) {
  2690. $bar = "";
  2691. $sum = $student->sum;
  2692. $percent = ($sum / $sum_iassign) * 100;
  2693. $text = number_format($percent, 1) . '%';
  2694. $sum_correct += $sum;
  2695. if ($sum > 0) {
  2696. for ($i = 1; $i < $percent * 2; $i ++)
  2697. $bar .= iassign_icons::insert('hbar_blue');
  2698. $bar .= iassign_icons::insert('hbar_blue_r');
  2699. } // if ($sum > 0)
  2700. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2701. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2702. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2703. print '</tr>' . "\n";
  2704. } // foreach ($sum_correct_student as $student)
  2705. print "</table>\n";
  2706. print "<br/><br/>\n";
  2707. $var = 0;
  2708. $cv = 0;
  2709. $dv = 0;
  2710. $avg = 0;
  2711. if ($sum_correct_student) {
  2712. $avg = $sum_correct / $sum_student;
  2713. if ($avg > 0) {
  2714. foreach ($sum_correct_student as $student)
  2715. $var += pow($student->sum - $avg, 2);
  2716. $var = $var / $sum_student;
  2717. $dv = sqrt($var);
  2718. $cv = ($dv / $avg) * 100;
  2719. }
  2720. }
  2721. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2722. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2723. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2724. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2725. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2726. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2727. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2728. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2729. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2730. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2731. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2732. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2733. print "</table>\n";
  2734. } // if ($this->action != 'printstats')
  2735. die();
  2736. }
  2737. /// Display graphics of performance for students
  2738. function stats_students () {
  2739. global $USER, $CFG, $DB, $OUTPUT;
  2740. $id = $this->cm->id;
  2741. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2742. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2743. $title = get_string('results', 'iassign');
  2744. $sum_correct = 0;
  2745. $sum_incorrect = 0;
  2746. $sum_post = 0;
  2747. $sum_nopost = 0;
  2748. $sum_iassign = count($iassign_statement_list);
  2749. $bar_nopost = "";
  2750. $bar_correct = "";
  2751. $bar_incorrect = "";
  2752. $bar_post = "";
  2753. $text_nopost = "";
  2754. $text_correct = "";
  2755. $text_incorrect = "";
  2756. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2757. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2758. if ($iassign_submission) {
  2759. if ($iassign_submission->status == 3)
  2760. $sum_correct ++;
  2761. elseif ($iassign_submission->status == 2)
  2762. $sum_incorrect ++;
  2763. elseif ($iassign_submission->status == 1)
  2764. $sum_post ++;
  2765. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2766. $sum_nopost ++;
  2767. } // if ($iassign_submission)
  2768. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2769. if ($sum_iassign > 0) {
  2770. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2771. $text_correct = number_format($percent_correct, 1) . '%';
  2772. }
  2773. if ($sum_correct > 0) {
  2774. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2775. $bar_correct .= iassign_icons::insert('hbar_green');
  2776. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2777. } // if ($sum_correct > 0)
  2778. if ($sum_iassign > 0) {
  2779. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2780. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2781. }
  2782. if ($sum_incorrect > 0) {
  2783. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2784. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2785. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2786. } // if ($sum_incorrect > 0)
  2787. if ($sum_iassign > 0) {
  2788. $percent_post = ($sum_post / $sum_iassign) * 100;
  2789. $text_post = number_format($percent_post, 1) . '%';
  2790. }
  2791. if ($sum_post > 0) {
  2792. for ($i = 1; $i < $percent_post * 2; $i ++)
  2793. $bar_post .= iassign_icons::insert('hbar_blue');
  2794. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2795. } // if ($sum_post > 0)
  2796. if ($sum_iassign > 0) {
  2797. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2798. $text_nopost = number_format($percent_nopost, 1) . '%';
  2799. }
  2800. if ($sum_nopost > 0) {
  2801. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2802. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2803. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2804. } // if ($sum_nopost > 0)
  2805. print $OUTPUT->header();
  2806. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2807. print '<table width=100%><tr>';
  2808. print '<td align="right">' . $link_return . '</td>' . "\n";
  2809. print '</td></tr></table>' . "\n";
  2810. print "<br/><br/>\n";
  2811. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2812. print '<tr><th colspan=3 class="header c1">' . "\n";
  2813. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2814. // $imagetext = '');
  2815. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2816. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2817. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2818. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2819. print '</tr>' . "\n";
  2820. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2821. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2822. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2823. print '</tr>' . "\n";
  2824. if ($sum_post) {
  2825. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2826. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2827. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2828. print '</tr>' . "\n";
  2829. } // if ($sum_post)
  2830. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2831. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2832. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2833. print '</tr>' . "\n";
  2834. print "</table>";
  2835. print "<br><br>";
  2836. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2837. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2838. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2839. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2840. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2841. $sum_grade = 0;
  2842. $sum_grade_student = 0;
  2843. $avg = 0;
  2844. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2845. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2846. if (!$iassign_submission) {
  2847. $iassign_submission = new stdClass();
  2848. $iassign_submission->grade = 0;
  2849. }
  2850. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2851. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2852. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2853. print '</tr>' . "\n";
  2854. $sum_grade += $iassign_statement_activity_item->grade;
  2855. $sum_grade_student += $iassign_submission->grade;
  2856. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2857. if ($sum_grade > 0)
  2858. $avg = $sum_grade_student / $sum_grade * 100;
  2859. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2860. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2861. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2862. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2863. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2864. print "</table>";
  2865. print $OUTPUT->footer();
  2866. die();
  2867. } // function stats_students()
  2868. /// Display page of iAssign's activity
  2869. function view_iassigns () {
  2870. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2871. $id = $this->cm->id;
  2872. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2873. $notice = optional_param('notice', '', PARAM_TEXT);
  2874. if (strpos($notice, 'error'))
  2875. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2876. else if ($notice != '')
  2877. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2878. print $OUTPUT->box_start();
  2879. print '<table width=100% border=0><tr>' . "\n";
  2880. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2881. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2882. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2883. $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>";
  2884. $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>";
  2885. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2886. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2887. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2888. // Has capability to see "report": teacher or up
  2889. print '<td width=10% align="left">' . "\n";
  2890. print $link_help;
  2891. print '</td>' . "\n";
  2892. print '<td width=10% align="left">' . "\n";
  2893. print $link_report;
  2894. print '</td>' . "\n";
  2895. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2896. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2897. print '<td width=15% align="left">' . "\n";
  2898. print $link_add;
  2899. print "</td>\n";
  2900. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2901. //print '</tr></table>' . "\n";
  2902. print '<div style="float: right;">';
  2903. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2904. if ($iassign_list) {
  2905. print '<td align="right">' . "\n";
  2906. // $USER->iassignEdit == 0 view 'Turn editing off'
  2907. // $USER->iassignEdit == 1 view 'Turn editing on'
  2908. if (!isset($USER->iassignEdit))
  2909. $USER->iassignEdit = 0;
  2910. if ($USER->iassignEdit == 0) {
  2911. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2912. $botton = 1;
  2913. } // if ($USER->iassignEdit == 0)
  2914. elseif ($USER->iassignEdit == 1) {
  2915. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2916. $botton = 0;
  2917. } // elseif ($USER->iassignEdit == 1)
  2918. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2919. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2920. print " <input type=submit value='$bottonEdit_message'/>\n";
  2921. print "</form>\n";
  2922. print "</td>\n";
  2923. } // if ($iassign_list)
  2924. }
  2925. print '</tr></table>' . "\n";
  2926. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2927. // $this->view_legend_icons();
  2928. print $OUTPUT->box_end();
  2929. $iassign_array_exercise = array();
  2930. $i_exercise = 0;
  2931. $iassign_array_test = array();
  2932. $i_test = 0;
  2933. $iassign_array_example = array();
  2934. $i_example = 0;
  2935. $iassign_array_general = array();
  2936. $i_general = 0;
  2937. if ($iassign_list) {
  2938. if ($this->iassign->activity_group == 0) {
  2939. foreach ($iassign_list as $iassign) {
  2940. $iassign_array_general[$i_general] = $iassign;
  2941. $i_general ++;
  2942. }
  2943. } // if ($this->iassign->activity_group == 0)
  2944. else {
  2945. foreach ($iassign_list as $iassign) {
  2946. if ($iassign->type_iassign == 3) {
  2947. $iassign_array_exercise[$i_exercise] = $iassign;
  2948. $i_exercise ++;
  2949. } // if ($iassign->type_iassign == 3)
  2950. if ($iassign->type_iassign == 2) {
  2951. $iassign_array_test[$i_test] = $iassign;
  2952. $i_test ++;
  2953. } // if ($iassign->type_iassign == 2)
  2954. if ($iassign->type_iassign == 1) {
  2955. $iassign_array_example[$i_example] = $iassign;
  2956. $i_example ++;
  2957. } // if ($iassign->type_iassign == 1)
  2958. }
  2959. }
  2960. if ($iassign_array_exercise) {
  2961. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2962. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2963. }
  2964. if ($iassign_array_test) {
  2965. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2966. $this->show_iassign($title, $iassign_array_test, $i_test);
  2967. }
  2968. if ($iassign_array_example) {
  2969. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2970. $this->show_iassign($title, $iassign_array_example, $i_example);
  2971. }
  2972. if ($iassign_array_general) {
  2973. $title = "";
  2974. $this->show_iassign($title, $iassign_array_general, $i_general);
  2975. }
  2976. } else { // if ($iassign_list)
  2977. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2978. }
  2979. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2980. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2981. print $OUTPUT->box_start();
  2982. print '<table width=100% border=0><tr>' . "\n";
  2983. print '<td width=10% align="left">' . "\n";
  2984. print $link_report;
  2985. print '</td>' . "\n";
  2986. print '</tr></table>' . "\n";
  2987. print $OUTPUT->box_end();
  2988. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2989. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2990. print $OUTPUT->box_start();
  2991. print '<table width=100% border=0><tr>' . "\n";
  2992. print '<td align="left">' . "\n";
  2993. print $link_add;
  2994. print '</td>' . "\n";
  2995. print '</tr></table>' . "\n";
  2996. print $OUTPUT->box_end();
  2997. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2998. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2999. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3000. $this->view_legend_icons();
  3001. } // function view_iassigns()
  3002. /// Display all iAssigns
  3003. function show_iassign ($title, $iassign_array, $i) {
  3004. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3005. $id = $this->cm->id;
  3006. print $OUTPUT->box_start();
  3007. print " <script type='text/javascript'>
  3008. //<![CDATA[
  3009. function validate_move () {
  3010. var radios = document.getElementsByName('iassign_destiny');
  3011. var formValid = false;
  3012. //alert('aqui validate_move()');
  3013. var i = 0;
  3014. while (!formValid && i < radios.length) {
  3015. if (radios[i].checked) formValid = true;
  3016. i++;
  3017. }
  3018. if (!formValid) {
  3019. document.getElementById('move_dest').classList.add('alert-danger');
  3020. }
  3021. return formValid;
  3022. }
  3023. var modal;
  3024. function load_move(id_ias) {
  3025. document.form_move_activity.iassign_current.value = id_ias;
  3026. modal.style.display = 'block';
  3027. var radios = document.getElementsByName('iassign_destiny');
  3028. var i = 0;
  3029. while (i < radios.length) {
  3030. radios[i].checked = false;
  3031. i++;
  3032. }
  3033. document.getElementById('move_dest').classList.remove('alert-danger');
  3034. }
  3035. function load_modal_elements() {
  3036. modal = document.getElementById('myModal');
  3037. var span = document.getElementById('close_modal');
  3038. span.onclick = function() {
  3039. modal.style.display = 'none';
  3040. }
  3041. window.onclick = function(event) {
  3042. if (event.target == modal) {
  3043. modal.style.display = 'none';
  3044. }
  3045. }
  3046. }
  3047. window.onload = load_modal_elements;
  3048. //]]>
  3049. </script>\n";
  3050. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3051. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3052. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3053. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3054. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3055. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3056. <input type='hidden' name='iassign_current' value='' />";
  3057. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3058. $section = $course_sections[0];
  3059. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3060. for ($k = 0; $k < count($ids_sections); $k++) {
  3061. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3062. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3063. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3064. if ($c_cm) {
  3065. if ($ccm->instance == $c_cm->instance) {
  3066. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3067. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3068. }
  3069. else {
  3070. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3071. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3072. }
  3073. }
  3074. }
  3075. $radio_buttons .= "</ul>";
  3076. }
  3077. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3078. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3079. </form>
  3080. </div></div> </div></div>\n";
  3081. print " <style>.modal {
  3082. display: none;
  3083. position: fixed;
  3084. z-index: 1;
  3085. left: 0;
  3086. top: 0;
  3087. width: 100%;
  3088. height: 100%;
  3089. overflow: scroll;
  3090. background-color: rgb(0,0,0);
  3091. background-color: rgba(0,0,0,0.4);
  3092. }
  3093. .modal-content {
  3094. background-color: #fefefe;
  3095. margin: 15% auto;
  3096. padding: 10px 10px;
  3097. border: 1px solid #888;
  3098. width: 50%;
  3099. }
  3100. #close_modal {
  3101. color: #aaa;
  3102. float: right;
  3103. font-size: 28px;
  3104. font-weight: bold;
  3105. margin-top: -15px;
  3106. margin-right: -3px;
  3107. }
  3108. #close_modal:hover,
  3109. #close_modal:focus {
  3110. color: black;
  3111. text-decoration: none;
  3112. cursor: pointer;
  3113. }
  3114. #modal_title {
  3115. min-height: 3rem;
  3116. color: initial;
  3117. background: initial;
  3118. font-size: 1.5rem;
  3119. line-height: 1.5;
  3120. padding: 15px;
  3121. border-bottom: 1px solid #e5e5e5;
  3122. }
  3123. .input_move {
  3124. width: 90%;
  3125. padding: 2px;
  3126. }
  3127. .input_move:hover {
  3128. background: #eff0ef;
  3129. }
  3130. </style>";
  3131. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3132. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3133. for ($j = 0; $j < $i; $j ++) {
  3134. $iassign_current = $iassign_array[$j]->id;
  3135. // receiver=1 - message to teacher
  3136. // receiver=2 - message to student
  3137. $sum_comment = 0;
  3138. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3139. foreach ($iassign_submissions as $iassign_submission) {
  3140. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3141. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3142. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3143. if ($verify_message)
  3144. foreach ($verify_message as $tmp)
  3145. $sum_comment += $tmp;
  3146. } // foreach ($iassign_submissions as $iassign_submission)
  3147. if ($sum_comment == 0)
  3148. $comment_unread = "";
  3149. else {
  3150. $comment_unread_message = get_string('comment_unread', 'iassign');
  3151. if ($sum_comment == 1)
  3152. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3153. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3154. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3155. }
  3156. if ($j == $i - 1)
  3157. $iassign_down = $iassign_array[$j]->id;
  3158. else
  3159. $iassign_down = $iassign_array[$j + 1]->id;
  3160. if ($j > 0)
  3161. $iassign_up = $iassign_array[$j - 1]->id;
  3162. else
  3163. $iassign_up = $iassign_array[$j]->id;
  3164. if ($iassign_array[$j]->visible == 0)
  3165. $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>";
  3166. else
  3167. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3168. $links .= $comment_unread;
  3169. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3170. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3171. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3172. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3173. if ($j==0) // first activity
  3174. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3175. else
  3176. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3177. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3178. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3179. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3180. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3181. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3182. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3183. if (count($iassign_array) > 1) {
  3184. if ($j == 0)
  3185. $links .= $link_down;
  3186. elseif ($j == $i - 1)
  3187. $links .= $link_up;
  3188. else
  3189. $links .= $link_up . $link_down;
  3190. } // if (count($iassign_array) > 1)
  3191. $links .= $link_edit . $link_delete;
  3192. if ($iassign_array[$j]->visible == 0)
  3193. $links .= $link_visible_show;
  3194. else
  3195. $links .= $link_visible_hide;
  3196. $links .= $link_duplicate_activity . $link_move_activity;
  3197. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3198. print '<p>' . $links . '</p>' . "\n";
  3199. }
  3200. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3201. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3202. print '<table width=100% ><tr>' . "\n";
  3203. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3204. print '</tr></table>' . "\n";
  3205. for ($j = 0; $j < $i; $j ++) {
  3206. $icon_status = "";
  3207. $icon_comment = "";
  3208. if ($iassign_array[$j]->visible == 1) {
  3209. $iassign_current = $iassign_array[$j]->id;
  3210. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3211. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3212. $icon_status = "";
  3213. $icon_comment = "";
  3214. if ($iassign_submission) {
  3215. // receiver=1 - message to teacher
  3216. // receiver=2 - message to student
  3217. // $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");
  3218. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3219. $verify_message = $DB->get_record_sql(
  3220. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3221. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3222. if ($verify_message)
  3223. foreach ($verify_message as $tmp)
  3224. $sum_comment = $tmp;
  3225. if ($sum_comment > 0) {
  3226. $comment_unread_message = get_string('comment_unread', 'iassign');
  3227. if ($sum_comment == 1)
  3228. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3229. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3230. }
  3231. // $icon_comment = iassign_icons::insert('comment_unread');
  3232. if ($iassign_array[$j]->type_iassign == 3) {
  3233. if ($iassign_array[$j]->show_answer == 1) {
  3234. if ($iassign_submission->status == 3)
  3235. $icon_status = iassign_icons::insert('correct');
  3236. elseif ($iassign_submission->status == 2)
  3237. $icon_status = iassign_icons::insert('incorrect');
  3238. elseif ($iassign_submission->status == 1)
  3239. $icon_status = iassign_icons::insert('post');
  3240. elseif ($iassign_submission->status == 0)
  3241. $icon_status = iassign_icons::insert('not_post');
  3242. } // if ($iassign_array[$j]->show_answer==1)
  3243. else {
  3244. if ($iassign_submission->status == 0)
  3245. $icon_status = iassign_icons::insert('not_post');
  3246. else
  3247. $icon_status = iassign_icons::insert('post');
  3248. }
  3249. } // if ($iassign_array[$j]->type_iassign == 3)
  3250. } // if ($iassign_submission)
  3251. elseif ($iassign_array[$j]->type_iassign == 3) {
  3252. $icon_status = iassign_icons::insert('not_post');
  3253. } // if ($iassign_array[$j]->type_iassign == 3)
  3254. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3255. } // if ($iassign_array[$j]->visible == 1)
  3256. } // for ($j = 0; $j < $i; $j++)
  3257. } else if (isguestuser()) {
  3258. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3259. print '<table width=100% ><tr>' . "\n";
  3260. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3261. print '</tr></table>' . "\n";
  3262. for ($j = 0; $j < $i; $j ++) {
  3263. $icon_status = "";
  3264. $icon_comment = "";
  3265. if ($iassign_array[$j]->visible == 1) {
  3266. $iassign_current = $iassign_array[$j]->id;
  3267. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3268. print '<p>' . $links . '</p>' . "\n";
  3269. } // if ($iassign_array[$j]->visible == 1)
  3270. }
  3271. }
  3272. print $OUTPUT->box_end();
  3273. } // function show_iassign($title, $iassign_array, $i)
  3274. /// Show message of return
  3275. function return_home_course ($message) {
  3276. //D global $DB, $OUTPUT;
  3277. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3278. //D echo $OUTPUT->box_start();
  3279. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3280. //D echo '<tr><td align="left"><strong>' . "\n";
  3281. //D print_string($message, 'iassign');
  3282. //D echo '</strong></td>' . "\n";
  3283. //D echo '<td width=20% align="right">' . "\n";
  3284. //D echo $link_return;
  3285. //D echo '</td></tr></table>' . "\n";
  3286. //D echo $OUTPUT->box_end();
  3287. //D // echo $OUTPUT->footer();
  3288. redirect(new moodle_url($this->return . '&notice=' . $message));
  3289. exit;
  3290. }
  3291. /// Search comment of activity
  3292. function search_comment_submission ($iassign_submissionid) {
  3293. global $USER, $DB, $OUTPUT, $COURSE;
  3294. // $context = context_course::instance($COURSE->id);
  3295. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3296. $colorEdit2 = "#b7ceee";
  3297. $has_capability = 0;
  3298. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3299. $text = "";
  3300. if ($comments) {
  3301. $even = 1;
  3302. foreach ($comments as $tmp) {
  3303. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3304. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3305. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3306. // $text .= $tmp->comment . "</td></tr>";
  3307. //} else {
  3308. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3309. if ($even) {
  3310. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3311. $even = 0;
  3312. } else {
  3313. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3314. $even = 1;
  3315. }
  3316. $text .= $tmp->comment . "</td></tr>\n";
  3317. } // foreach ($comments as $tmp)
  3318. }
  3319. return $text;
  3320. }
  3321. /// Update comment of activity
  3322. function update_comment ($iassign_submissionid) {
  3323. global $USER, $DB, $OUTPUT;
  3324. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3325. $receiver = 1; // student message to teacher
  3326. else
  3327. $receiver = 2; // teacher message to student
  3328. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3329. if ($verify_message) {
  3330. foreach ($verify_message as $message) {
  3331. if ($message->receiver == $receiver) {
  3332. $newentry = new stdClass();
  3333. $newentry->id = $message->id;
  3334. $newentry->return_status = 1;
  3335. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3336. print_error('error_update', 'iassign');
  3337. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3338. } // if ($message->receiver == $receiver)
  3339. // Trigger module viewed event.
  3340. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3341. 'objectid' => $this->iassign->id,
  3342. 'context' => $this->context
  3343. ));
  3344. $event->add_record_snapshot('course', $this->course);
  3345. $event->trigger();
  3346. } // foreach ($verify_message as $message)
  3347. }
  3348. }
  3349. /// Record comment of activity
  3350. function write_comment_submission () {
  3351. global $USER, $CFG, $DB;
  3352. $id = $this->cm->id;
  3353. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3354. $row = optional_param('row', 0, PARAM_INT);
  3355. $column = optional_param('column', 0, PARAM_INT);
  3356. $sum_comment = 0;
  3357. $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);
  3358. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3359. $str1 = trim($submission_comment);
  3360. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3361. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3362. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3363. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3364. $receiver = 1; // student message to teacher
  3365. $this->action = 'view';
  3366. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3367. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3368. } else {
  3369. $receiver = 2; // teacher message to student
  3370. $this->action = 'viewsubmission';
  3371. //D $tousers = array(); //MOOC 2016
  3372. //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
  3373. }
  3374. //MOOC 2016: foi p/ 15 linhas acima:
  3375. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3376. if (!$iassign_submission) {
  3377. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3378. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3379. $this->iassign_submission_current = $id_submission;
  3380. } else {
  3381. $id_submission = $iassign_submission->id;
  3382. } // if (!$iassign_submission)
  3383. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3384. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3385. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3386. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3387. $comments = $DB->get_record_sql(
  3388. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3389. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3390. if ($comments)
  3391. foreach ($comments as $tmp)
  3392. $sum_comment = $tmp;
  3393. if ($sum_comment == 0) {
  3394. $newentry = new stdClass();
  3395. $newentry->iassign_submissionid = $id_submission;
  3396. $newentry->comment_authorid = $USER->id;
  3397. $newentry->timecreated = time();
  3398. $newentry->comment = $submission_comment;
  3399. $newentry->receiver = $receiver;
  3400. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3401. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3402. //T $eventdata = new stdClass();
  3403. //T $eventdata->component = 'mod_iassign'; //your component name
  3404. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3405. //T $eventdata->userfrom = $USER;
  3406. //T $eventdata->userto = $touser;
  3407. //T $eventdata->subject = "Teste de Subject";
  3408. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3409. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3410. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3411. //T $eventdata->smallmessage = "Teste de Mensagem";
  3412. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3413. //T // alteracao tulio faria
  3414. //T //message_send($eventdata);
  3415. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3416. // Trigger module viewed event.
  3417. $event = \mod_iassign\event\submission_comment_created::create(array(
  3418. 'objectid' => $this->iassign->id,
  3419. 'context' => $this->context
  3420. ));
  3421. $event->add_record_snapshot('course', $this->course);
  3422. $event->trigger();
  3423. }
  3424. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3425. // if ($this->action=='viewsubmission') {
  3426. // echo $OUTPUT->header();
  3427. // $this->return_last('confirm_add_comment', $link_return);
  3428. // die;
  3429. // }
  3430. return true;
  3431. } // function write_comment_submission()
  3432. /// Writes a new submission
  3433. // The first student answer is under 'function get_answer()'
  3434. function new_submission ($iassignid, $id_user, $receiver) {
  3435. global $USER, $DB, $OUTPUT;
  3436. $newentry = new stdClass();
  3437. $newentry->iassign_statementid = $iassignid;
  3438. $newentry->userid = $id_user;
  3439. $newentry->timecreated = time();
  3440. $newentry->timemodified = time();
  3441. $newentry->answer = 0; // student only submit message
  3442. if ($receiver == 2) // teacher message to student (write id teacher)
  3443. $newentry->teacher = $USER->id;
  3444. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3445. return_home_course('error_insert_submissions');
  3446. else {
  3447. // Trigger module view event
  3448. $event = \mod_iassign\event\submission_created::create(array(
  3449. 'objectid' => $this->iassign->id,
  3450. 'context' => $this->context
  3451. ));
  3452. $event->add_record_snapshot('course', $this->course);
  3453. $event->trigger();
  3454. }
  3455. return $newentry->id;
  3456. }
  3457. /// Return to a specific address of page
  3458. function return_last ($message, $link_return) {
  3459. global $DB, $OUTPUT;
  3460. print $OUTPUT->box_start();
  3461. print '<table width=100% border=0 valign="top">' . "\n";
  3462. print '<tr><td align="left"><strong>' . "\n";
  3463. print_string($message, 'iassign');
  3464. print '</strong></td>' . "\n";
  3465. print '<td width=20% align="right">' . "\n";
  3466. print $link_return;
  3467. print '</td></tr></table>' . "\n";
  3468. print $OUTPUT->box_end();
  3469. print $OUTPUT->footer();
  3470. die();
  3471. } // function return_last($message, $link_return)
  3472. } // class iassign
  3473. /// Class for manage activities
  3474. class activity {
  3475. var $activity;
  3476. /// Constructor of class.
  3477. // @param int $id Id of activity
  3478. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3479. //D public function activity($id) { self::__construct($id); }
  3480. function __construct ($id) {
  3481. global $DB;
  3482. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3483. if (empty($this->activity))
  3484. $this->activity = null;
  3485. }
  3486. /// Get an activity
  3487. // @return NULL
  3488. function get_activity () {
  3489. if ($this->activity != null)
  3490. return $this->activity;
  3491. else
  3492. return null;
  3493. }
  3494. /// Delete interactive activities
  3495. function delete ($return) {
  3496. global $USER, $CFG, $DB, $OUTPUT;
  3497. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3498. $output = $OUTPUT->header();
  3499. $output .= $OUTPUT->box_start();
  3500. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3501. if ($iassign_submission_currents) {
  3502. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3503. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3504. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3505. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3506. $output .= $OUTPUT->box_end();
  3507. $output .= $OUTPUT->footer();
  3508. print $output;
  3509. die();
  3510. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3511. } // if ($iassign_submission_currents)
  3512. else
  3513. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3514. $output .= '<table width=50% border=0>';
  3515. $output .= '<tr valign="top"><td>';
  3516. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3517. $output .= '</td><td>';
  3518. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3519. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3520. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3521. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3522. $output .= "</form>\n";
  3523. $output .= '</td><td>';
  3524. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3525. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3526. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3527. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3528. $output .= "</form>\n";
  3529. $output .= '</td></tr></table>' . "\n";
  3530. $output .= $OUTPUT->box_end();
  3531. $output .= $OUTPUT->footer();
  3532. print $output;
  3533. } // function delete($return)
  3534. /// Function for confirm the delete of activity
  3535. // @param String $return Url of return
  3536. // @param Object $iassign Object content an activity
  3537. function deleteyes ($return, $iassign) {
  3538. global $USER, $CFG, $DB, $OUTPUT;
  3539. $msg = '';
  3540. if (!empty($this->activity->id)) {
  3541. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3542. if ($iassign_submission_currents) {
  3543. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3544. foreach ($iassign_submission_currents as $iassign_submission)
  3545. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3546. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3547. } // if ($iassign_submission_currents)
  3548. }
  3549. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3550. $this->delete_calendar($this->activity->id);
  3551. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3552. iassign::update_grade_iassign($this->activity->iassignid);
  3553. if ($delete_iassign_current) {
  3554. $iassign->return_home_course('confirm_delete_iassign');
  3555. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3556. } else {
  3557. $iassign->return_home_course('error_confirm_delete_iassign');
  3558. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3559. }
  3560. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3561. }
  3562. }
  3563. /// Changes position of activities (between those inside a group of interactive activities)
  3564. // @param $move_action = must be "up" or "down"
  3565. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3566. function move_iassign ($move_action, $target, $return) {
  3567. global $DB, $OUTPUT;
  3568. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3569. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3570. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3571. if ($move_action=="firstdown") {
  3572. $final_position_source = 2;
  3573. $final_position_target = 1;
  3574. }
  3575. else
  3576. if ($move_action=="down") {
  3577. $final_position_target = $this->activity->position;
  3578. $final_position_source = $final_position_target + 1;
  3579. }
  3580. else
  3581. if ($move_action=="up") {
  3582. $final_position_target = $this->activity->position;
  3583. $final_position_source = $final_position_target - 1;
  3584. }
  3585. else { // error:
  3586. print_error('error_update_move_iassign', 'iassign');
  3587. exit;
  3588. }
  3589. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3590. $newentry->id = $this->activity->id; // ID of the "source activity"
  3591. $newentry->position = $final_position_source;
  3592. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3593. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3594. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3595. print_error('error_update_move_iassign', 'iassign');
  3596. }
  3597. else { // first update performed successfully
  3598. $newentry->id = $iassign_target->id;
  3599. $newentry->position = $final_position_target;
  3600. if (!$DB->update_record('iassign_statement', $newentry))
  3601. print_error('error_update_move_iassign', 'iassign');
  3602. }
  3603. redirect($return);
  3604. }
  3605. /// Enable or disable the display of interactive activities
  3606. function visible_iassign ($return) {
  3607. global $DB;
  3608. $newentry = new stdClass();
  3609. $newentry->id = $this->activity->id;
  3610. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3611. if (!$DB->update_record('iassign_statement', $newentry))
  3612. print_error('error_update_visible_iassign', 'iassign');
  3613. redirect($return);
  3614. }
  3615. /// Add news interactive activities (register in table 'iassign_statement')
  3616. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3617. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3618. function new_iassign ($param) {
  3619. global $DB;
  3620. $newentry = new stdClass();
  3621. $newentry->iassignid = $param->iassignid;
  3622. $newentry->name = $param->name;
  3623. $newentry->type_iassign = $param->type_iassign;
  3624. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3625. $proposition = $param->proposition;
  3626. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3627. else $proposition_text = $proposition;
  3628. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3629. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3630. //TODO Then get it directly from the form data $_POST!
  3631. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3632. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3633. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3634. $newentry->author_name = $param->author_name;
  3635. $newentry->author_modified_name = $param->author_modified_name;
  3636. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3637. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3638. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3639. $newentry->grade = $param->grade;
  3640. $newentry->timemodified = time();
  3641. $newentry->timecreated = time();
  3642. if ($param->type_iassign == 1) {
  3643. $newentry->timedue = 0;
  3644. $newentry->timeavailable = 0;
  3645. } // if ($param->type_iassign == 1)
  3646. else {
  3647. $newentry->timedue = $param->timedue;
  3648. $newentry->timeavailable = $param->timeavailable;
  3649. }
  3650. $newentry->preventlate = $param->preventlate;
  3651. $newentry->test = $param->test;
  3652. $newentry->special_param1 = $param->special_param1;
  3653. $newentry->visible = $param->visible;
  3654. $newentry->position = $param->position;
  3655. $newentry->max_experiment = $param->max_experiment;
  3656. $newentry->dependency = $param->dependency;
  3657. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3658. $newentry->show_answer = $param->show_answer;
  3659. $id = $DB->insert_record("iassign_statement", $newentry);
  3660. if ($id) {
  3661. $component = 'mod_iassign';
  3662. $filearea = 'exercise';
  3663. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3664. $file = $fs->get_file_by_id($param->file);
  3665. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3666. // File already inserted in other context!
  3667. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3668. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3669. $updateentry = new stdClass();
  3670. $updateentry->id = $id;
  3671. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3672. $updateentry->file = $newfile->get_itemid();
  3673. if (!$DB->update_record("iassign_statement", $updateentry))
  3674. print_error('error_add', 'iassign');
  3675. if ($param->type_iassign == 3)
  3676. iassign::update_grade_iassign($param->iassignid);
  3677. //TODO iLM_HTML5 :: //MOOC2014
  3678. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3679. //D if ($iassign_ilm_configs) {
  3680. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3681. //D if ($iassign_ilm_config->param_type != 'static') {
  3682. //D $newentry = new stdClass();
  3683. //D $newentry->iassign_statementid = $id;
  3684. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3685. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3686. //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});
  3687. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3688. //D print_error('error_add_param', 'iassign');
  3689. //D }
  3690. //D }
  3691. //D }
  3692. // log event --------------------------------------------------------------------------------------
  3693. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3694. // log event --------------------------------------------------------------------------------------
  3695. return $id;
  3696. }
  3697. else
  3698. print_error('error_add', 'iassign');
  3699. } // function new_iassign($param)
  3700. /// Add the calendar entries for this iassign
  3701. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3702. // @return bool
  3703. static function add_calendar ($iassignid) {
  3704. global $DB, $CFG;
  3705. require_once($CFG->dirroot . '/calendar/lib.php');
  3706. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3707. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3708. $event = new stdClass();
  3709. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3710. $event->description = $iassign_statement_activity_item->name;
  3711. $event->courseid = $iassign->course;
  3712. $event->groupid = 0;
  3713. $event->userid = 0;
  3714. $event->modulename = 'iassign';
  3715. $event->instance = $iassign->id;
  3716. $event->eventtype = 'due';
  3717. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3718. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3719. calendar_event::create($event);
  3720. }
  3721. /// Update the calendar entries for this iassign
  3722. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3723. // @return bool
  3724. function update_calendar ($iassignid, $olddescription) {
  3725. global $DB, $CFG;
  3726. require_once($CFG->dirroot . '/calendar/lib.php');
  3727. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3728. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3729. $event = new stdClass();
  3730. $event->id = 0;
  3731. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3732. if ($events) {
  3733. foreach ($events as $value) {
  3734. if ($value->description == $olddescription) {
  3735. $event->id = $value->id;
  3736. }
  3737. }
  3738. }
  3739. if ($event->id != 0) {
  3740. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3741. $event->description = $iassign_statement_activity_item->name;
  3742. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3743. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3744. $calendarevent = calendar_event::load($event->id);
  3745. $calendarevent->update($event);
  3746. } else
  3747. $this->add_calendar($iassignid);
  3748. }
  3749. /// Update the calendar entries for this iassign
  3750. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3751. // @return bool
  3752. function delete_calendar ($iassignid) {
  3753. global $DB, $CFG;
  3754. require_once($CFG->dirroot . '/calendar/lib.php');
  3755. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3756. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3757. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3758. if ($events) {
  3759. foreach ($events as $value) {
  3760. if ($value->description == $iassign_statement_activity_item->name) {
  3761. $DB->delete_records('event', array('id' => $value->id));
  3762. }
  3763. }
  3764. }
  3765. }
  3766. /// Update interactive activities
  3767. function update_iassign ($param) {
  3768. global $DB;
  3769. $component = 'mod_iassign';
  3770. $filearea = 'exercise';
  3771. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3772. $file = $fs->get_file_by_id($param->file);
  3773. $fileold = $fs->get_file_by_id($param->fileold);
  3774. if ($param->file != $param->fileold) {
  3775. if ($fileold) {
  3776. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3777. foreach ($fileoldarea as $value) {
  3778. $value->delete();
  3779. }
  3780. }
  3781. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3782. $itemid = $file->get_itemid() + $param->iassign_id;
  3783. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3784. $param->file = $newfile->get_itemid();
  3785. } else
  3786. $param->file = $file->get_itemid();
  3787. } else {
  3788. $param->file = $file->get_itemid();
  3789. }
  3790. $newentry = new stdClass();
  3791. $newentry->id = $param->iassign_id;
  3792. $newentry->name = $param->name;
  3793. $newentry->type_iassign = $param->type_iassign;
  3794. //2019 $newentry->proposition = $param->proposition;
  3795. $proposition = $param->proposition;
  3796. if (is_array($proposition))
  3797. $proposition_text = $proposition['text'];
  3798. else
  3799. $proposition_text = $proposition;
  3800. $newentry->proposition = $proposition_text;
  3801. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3802. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3803. $newentry->grade = $param->grade;
  3804. $newentry->author_modified_name = $param->author_modified_name;
  3805. $newentry->timemodified = time();
  3806. if ($param->type_iassign == 1) {
  3807. $newentry->timedue = 0;
  3808. $newentry->timeavailable = 0;
  3809. } // if ($param->type_iassign == 1)
  3810. else {
  3811. $newentry->timedue = $param->timedue;
  3812. $newentry->timeavailable = $param->timeavailable;
  3813. }
  3814. $newentry->preventlate = $param->preventlate;
  3815. $newentry->test = $param->test;
  3816. $newentry->special_param1 = $param->special_param1;
  3817. $newentry->visible = $param->visible;
  3818. $newentry->max_experiment = $param->max_experiment;
  3819. $newentry->dependency = $param->dependency;
  3820. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3821. $newentry->show_answer = $param->show_answer;
  3822. if (!$DB->update_record("iassign_statement", $newentry))
  3823. print_error('error_update', 'iassign');
  3824. if ($param->type_iassign == 3) {
  3825. iassign::update_grade_iassign($param->iassignid);
  3826. }
  3827. //$id = $newentry->id; // MOOC 2016 --- inicio
  3828. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3829. //if ($iassign_activity_item_configs) {
  3830. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3831. // $newentry = new stdClass();
  3832. // $newentry->id = $iassign_activity_item_config->id;
  3833. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3834. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3835. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3836. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3837. // print_error('error_edit_param', 'iassign');
  3838. // }
  3839. // } // MOOC 2016 --- final
  3840. // log event --------------------------------------------------------------------------------------
  3841. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3842. // log event --------------------------------------------------------------------------------------
  3843. return $newentry->id;
  3844. // if ($param->type_iassign==3)
  3845. // $this->update_grade_iassign($param->iassignid);
  3846. } // function update_iassign($param)
  3847. /// Show information of activity
  3848. function show_info_iassign () {
  3849. global $DB, $OUTPUT;
  3850. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3851. if ($this->activity->type_iassign == 3) {
  3852. if ($this->activity->dependency == 0) {
  3853. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3854. } else {
  3855. $dependencys = explode(';', $this->activity->dependency);
  3856. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3857. foreach ($dependencys as $dependency) {
  3858. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3859. if ($dependencyiassign)
  3860. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3861. } // foreach ($dependencys as $dependency)
  3862. } // if ($iassign_statement_activity_item->dependency == 0)
  3863. if ($this->activity->max_experiment == 0)
  3864. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3865. else
  3866. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3867. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3868. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3869. print $OUTPUT->box($output);
  3870. } // function show_info_iassign()
  3871. /// Shows date of opening and closing activities
  3872. function view_dates () {
  3873. global $USER, $CFG, $DB, $OUTPUT;
  3874. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3875. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3876. $status_iassign = "";
  3877. $status_iassign1 = "";
  3878. $status_iassign2 = "";
  3879. if ($this->activity->type_iassign == 1) // activity of type example
  3880. $type_iassign = get_string('example_iassign', 'iassign');
  3881. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3882. $type_iassign = get_string('test_iassign', 'iassign');
  3883. if ($this->activity->timeavailable > time()) {
  3884. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3885. } elseif ($this->activity->timedue < time()) {
  3886. $status_iassign = get_string('last_timedue', 'iassign');
  3887. }
  3888. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3889. $type_iassign = get_string('exercise_iassign', 'iassign');
  3890. if ($this->activity->timeavailable > time()) {
  3891. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3892. } elseif ($this->activity->timedue < time()) { // after delivery
  3893. $status_iassign = get_string('last_timedue', 'iassign');
  3894. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3895. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3896. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3897. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3898. if ($this->activity->test == 1) // allowed to test after of deadline
  3899. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3900. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3901. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3902. } // elseif ($iassign_statement_activity_item->test == 0)
  3903. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3904. } // elseif ($iassign_statement_activity_item->timedue < time())
  3905. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3906. $output = '<table width=100% >' . "\n";
  3907. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3908. $output .= '<tr>' . "\n";
  3909. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3910. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3911. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3912. // leo $output .= '<td width=80%>' . $type_iassign;
  3913. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3914. // $output .= '</td>' . "\n";
  3915. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3916. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3917. $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>";
  3918. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3919. } else {
  3920. $link_next = "";
  3921. $link_previous = "";
  3922. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3923. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3924. // previous_activity
  3925. if ($iassign_previous) {
  3926. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3927. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3928. } // next_activity
  3929. if ($iassign_next) {
  3930. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3931. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3932. }
  3933. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3934. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3935. $output .= '</tr></table>' . "\n";
  3936. $output .= '<table width=100% >' . "\n";
  3937. if ($this->activity->type_iassign > 1) {
  3938. if ($this->activity->timeavailable)
  3939. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3940. if ($this->activity->timedue)
  3941. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3942. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3943. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3944. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3945. $output .= '</table>' . "\n";
  3946. print $OUTPUT->box($output);
  3947. } // function view_dates()
  3948. } // class activity
  3949. /// Class to manage Interactive Learning Module (iLM)
  3950. class ilm {
  3951. var $ilm;
  3952. /// Constructor of class
  3953. // @param int $id Id of iLM
  3954. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3955. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3956. function __construct ($id) {
  3957. global $DB;
  3958. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3959. if (empty($this->ilm))
  3960. $this->ilm = null;
  3961. }
  3962. /// Shows activity in iLM
  3963. // @calledby view_iassign_current()
  3964. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3965. global $USER, $CFG, $DB;
  3966. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3967. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3968. $typec = strtolower($iassign_ilm->type);
  3969. require_once 'ilm_handlers/' . $typec . '.php';
  3970. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3971. return $retorno;
  3972. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3973. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3974. // @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);
  3975. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3976. // @param Object $file File in use in activity
  3977. // @return int Return the id of log
  3978. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3979. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3980. $newentry = new stdClass();
  3981. $newentry->iassign_statementid = $iassign_activity_itemid;
  3982. $newentry->userid = $USER->id;
  3983. $newentry->file = $content_or_id_from_ilm_security;
  3984. $newentry->timecreated = time();
  3985. $newentry->view = 1;
  3986. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3987. if (!$id_iLM_security) {
  3988. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3989. } // from (!$DB->insert_record("iassign_security", $newentry))
  3990. return $id_iLM_security;
  3991. }
  3992. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3993. // @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);
  3994. // @param int $userid
  3995. // @param int $iassign_activity_itemid Id of iassign statement
  3996. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3997. global $DB;
  3998. // 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")
  3999. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4000. }
  4001. } // class ilm
  4002. /// Class to manage settings of iLM.
  4003. class ilm_settings {
  4004. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4005. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4006. // @param int $ilm_id Id of iLM
  4007. // @param array $options An array with options for create dynamic tag html APPLET
  4008. // @return string Return with a tag html APPLET created
  4009. static function build_ilm_tags ($ilm_id, $options = array()) {
  4010. global $DB;
  4011. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4012. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4013. $typec = strtolower($iassign_ilm->type);
  4014. require_once 'ilm_handlers/' . $typec . '.php';
  4015. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  4016. return $retorno;
  4017. } // static function build_ilm_tags($ilm_id, $options = array())
  4018. /// Function for get modified date of iLM file
  4019. // @param string $file_jar String with Ids of iLM files
  4020. // @return string Return with the filenames and modified date
  4021. static function applet_filetime ($file_jar) {
  4022. $filetime = "";
  4023. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4024. $files_jar = explode(",", $file_jar);
  4025. foreach ($files_jar as $one_file) {
  4026. $file = $fs->get_file_by_id($one_file);
  4027. if ($file)
  4028. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4029. }
  4030. return $filetime;
  4031. }
  4032. /// Function for verify an default applet
  4033. // @param String $file_jar String containing an list de ids of applet files
  4034. // @return boolean Return true or fale if applet is default
  4035. static function applet_default ($file_jar) {
  4036. $is_default = true;
  4037. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4038. $files_jar = explode(",", $file_jar);
  4039. foreach ($files_jar as $one_file) {
  4040. $file = $fs->get_file_by_id($one_file);
  4041. if ($file)
  4042. $is_default &= ($file->get_itemid() == 0);
  4043. }
  4044. return $is_default;
  4045. }
  4046. /// Function for get form variables for add, edit, or copy iLM
  4047. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4048. // @see settings_form.php
  4049. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4050. // @param int $ilm_id Id of iLM
  4051. // @param string $action String with the action
  4052. // @return object Return an object with forms variables
  4053. static function add_edit_copy_ilm ($ilm_id, $action) {
  4054. global $USER, $DB, $CFG;
  4055. require_once('settings_form.php'); // put the form
  4056. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4057. $param = new stdClass();
  4058. $param->action = $action;
  4059. $param->ilm_id = $ilm_id;
  4060. $CFG->action_ilm = $action;
  4061. $CFG->ilm_id = $ilm_id;
  4062. if ($action == 'add') {
  4063. $param->title = get_string('add_ilm', 'iassign');
  4064. $param->name = "";
  4065. $param->version = "";
  4066. $param->url = "";
  4067. $param->description = "";
  4068. $param->extension = "";
  4069. $param->author = $USER->id;
  4070. $param->file_jar = "";
  4071. $param->file_jar_static = "";
  4072. $param->file_class = "";
  4073. $param->width = 800;
  4074. $param->height = 600;
  4075. $param->enable = 0; // 0 - hide / 1 - show
  4076. $param->timecreated = time();
  4077. $param->timemodified = time();
  4078. $param->evaluate = 0;
  4079. $param->parent = 0;
  4080. }
  4081. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4082. if ($iassign_ilm) {
  4083. $description = json_decode($iassign_ilm->description);
  4084. $param->title = get_string('edit_ilm', 'iassign');
  4085. $param->id = $iassign_ilm->id;
  4086. $param->name_ilm = $iassign_ilm->name;
  4087. $param->name = $iassign_ilm->name;
  4088. $param->version = $iassign_ilm->version;
  4089. $param->ilm_type = $iassign_ilm->type;
  4090. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4091. $param->url = $iassign_ilm->url;
  4092. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4093. if (!isset($description->{current_language()})) {
  4094. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4095. else
  4096. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4097. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4098. }
  4099. else
  4100. $param->description = $description->{current_language()};
  4101. $param->description_lang = $iassign_ilm->description;
  4102. $param->extension = $iassign_ilm->extension;
  4103. $param->author = $iassign_ilm->author;
  4104. $param->file_jar = $iassign_ilm->file_jar;
  4105. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4106. $param->file_class = $iassign_ilm->file_class;
  4107. $param->width = $iassign_ilm->width;
  4108. $param->height = $iassign_ilm->height;
  4109. $param->enable = $iassign_ilm->enable;
  4110. $param->timecreated = $iassign_ilm->timecreated;
  4111. $param->timemodified = time();
  4112. $param->evaluate = $iassign_ilm->evaluate;
  4113. $param->parent = $iassign_ilm->parent;
  4114. }
  4115. }
  4116. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4117. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4118. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4119. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4120. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4121. // echo "Sem dados<br/>"; exit;
  4122. return;
  4123. }
  4124. $description = json_decode($iassign_ilm->description);
  4125. if ($iassign_ilm) {
  4126. if ($iassign_ilm->parent == 0)
  4127. $iassign_ilm->parent = $ilm_id;
  4128. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4129. $param->title = get_string('new_version_ilm', 'iassign');
  4130. $param->name_ilm = $iassign_ilm->name;
  4131. $param->name = $iassign_ilm->name;
  4132. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4133. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4134. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4135. $param->ilm_type = $iassign_ilm->type;
  4136. $param->url = $iassign_ilm->url;
  4137. $param->description = $description->{current_language()};
  4138. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4139. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4140. $param->extension = $iassign_ilm->extension;
  4141. $param->author = $USER->id;
  4142. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4143. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4144. $param->file_jar_static = '';
  4145. $param->file_class = $iassign_ilm->file_class;
  4146. $param->width = $iassign_ilm->width;
  4147. $param->height = $iassign_ilm->height;
  4148. $param->enable = 0;
  4149. $param->timecreated = time();
  4150. $param->timemodified = time();
  4151. $param->evaluate = $iassign_ilm->evaluate;
  4152. $param->parent = $iassign_ilm->parent;
  4153. }
  4154. }
  4155. elseif ($action == 'copy') {
  4156. $description = json_decode($iassign_ilm->description);
  4157. if ($iassign_ilm) {
  4158. if ($iassign_ilm->parent == 0)
  4159. $iassign_ilm->parent = $ilm_id;
  4160. $param->title = get_string('copy_ilm', 'iassign');
  4161. $param->id = $iassign_ilm->id;
  4162. $param->name_ilm = $iassign_ilm->name;
  4163. $param->name = $iassign_ilm->name;
  4164. $param->version = "";
  4165. $param->ilm_type = $iassign_ilm->type;
  4166. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4167. $param->url = $iassign_ilm->url;
  4168. $param->description = $description->{current_language()};
  4169. $param->description_lang = $iassign_ilm->description;
  4170. $param->extension = $iassign_ilm->extension;
  4171. $param->author = $USER->id;
  4172. $param->file_jar = '';
  4173. $param->file_jar_static = '';
  4174. $param->file_class = $iassign_ilm->file_class;
  4175. $param->width = $iassign_ilm->width;
  4176. $param->height = $iassign_ilm->height;
  4177. $param->enable = 0;
  4178. $param->timecreated = time();
  4179. $param->timemodified = time();
  4180. $param->evaluate = $iassign_ilm->evaluate;
  4181. $param->parent = $iassign_ilm->parent;
  4182. }
  4183. }
  4184. return $param;
  4185. } // static function add_edit_copy_ilm($ilm_id, $action)
  4186. /// Function for save iLM file in moodledata
  4187. // @param int $itemid Itemid of file save in draft (upload file)
  4188. // @param int $ilm_id Id of iLM
  4189. // @return string Return an string with ids of iLM files
  4190. static function new_file_ilm ($itemid, $iassign_ilm) {
  4191. global $CFG, $USER, $DB;
  4192. $return = null;
  4193. $file_jar = array();
  4194. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4195. $contextuser = context_user::instance($USER->id);
  4196. $contextsystem = context_system::instance();
  4197. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4198. if ($files_ilm) {
  4199. foreach ($files_ilm as $value) {
  4200. // CHECK IF file is HTML type
  4201. if ($iassign_ilm->type == 1) {
  4202. // Check if the file extension is ZIP
  4203. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4204. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4205. if ((strtolower($ext) == 'zip')) {
  4206. // Coping...:
  4207. $destination = 'ilm_debug/' . $value->get_filename();
  4208. $value->copy_content_to($destination);
  4209. // Extracting content...:
  4210. $zip = new ZipArchive();
  4211. $extracted = './ilm';
  4212. $dir = "";
  4213. if ($zip->open($destination) === TRUE) {
  4214. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4215. if (is_dir($dir)) {
  4216. $i = 1;
  4217. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4218. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4219. $i ++;
  4220. }
  4221. $name = $previous . "_" . $i;
  4222. $dir = './ilm/' . $name . "/";
  4223. $j = 0;
  4224. while ($item_name = $zip->getNameIndex($j)) {
  4225. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4226. $j++;
  4227. }
  4228. $zip->close();
  4229. }
  4230. $zip->open($destination);
  4231. $zip->extractTo($extracted);
  4232. $zip->close();
  4233. // After the extraction, remove it from DEBUG
  4234. unlink($destination);
  4235. } else { // Error trying to open destination...
  4236. // After the extraction error, also remove it from DEBUG
  4237. unlink($destination);
  4238. print_error('error_add_ilm_zip', 'iassign');
  4239. }
  4240. return $dir;
  4241. }
  4242. } // if ($iassign_ilm->type == 1)
  4243. if ($value->get_filename() != '.') {
  4244. $file_ilm = array(
  4245. 'userid' => $USER->id,
  4246. 'contextid' => $contextsystem->id,
  4247. 'component' => 'mod_iassign',
  4248. 'filearea' => 'ilm',
  4249. 'itemid' => rand(1, 999999999),
  4250. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4251. 'filename' => $value->get_filename());
  4252. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4253. array_push($file_jar, $file_ilm->get_id());
  4254. }
  4255. }
  4256. if (!empty($file_jar)) {
  4257. $return = implode(",", $file_jar);
  4258. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4259. foreach ($old_file_jar as $value) {
  4260. $file = $fs->get_file_by_id($value);
  4261. if ($file)
  4262. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4263. }
  4264. }
  4265. }
  4266. else // if ($files_ilm)
  4267. $return = $iassign_ilm->file_jar;
  4268. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4269. return $return;
  4270. } // static function new_file_ilm($itemid, $iassign_ilm)
  4271. /// Function for save in database an new iLM
  4272. // @param object $param An object with iLM params
  4273. static function new_ilm ($itemid) {
  4274. global $CFG, $USER, $OUTPUT;
  4275. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4276. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4277. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4278. }
  4279. $pathtemp = $CFG->dataroot . '/temp/';
  4280. $contextuser = context_user::instance($USER->id);
  4281. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4282. $zip = new zip_packer();
  4283. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4284. foreach ($files as $file) {
  4285. if (!$file->is_directory())
  4286. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4287. }
  4288. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4289. // Verifica se o pacote possui o XML
  4290. if (!$application_xml) {
  4291. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4292. return;
  4293. } else {
  4294. $missing = "";
  4295. if (!isset($application_xml->name)) {
  4296. $missing .= "name";
  4297. }
  4298. if (!isset($application_xml->version)) {
  4299. $missing .= ", version";
  4300. }
  4301. if (!isset($application_xml->type)) {
  4302. $missing .= ", type";
  4303. }
  4304. if (!isset($application_xml->extension)) {
  4305. $missing .= ", extension";
  4306. }
  4307. if (!isset($application_xml->file_jar)) {
  4308. $missing .= ", file_jar";
  4309. }
  4310. if (!isset($application_xml->file_class)) {
  4311. $missing .= ", file_class";
  4312. }
  4313. if (!isset($application_xml->width)) {
  4314. $missing .= ", width";
  4315. }
  4316. if (!isset($application_xml->height)) {
  4317. $missing .= ", height";
  4318. }
  4319. if (!isset($application_xml->evaluate)) {
  4320. $missing .= ", evaluate";
  4321. }
  4322. if (strlen($missing) > 2) {
  4323. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4324. return;
  4325. }
  4326. }
  4327. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4328. $typec = strtolower($application_xml->type);
  4329. require_once 'ilm_handlers/' . $typec . '.php';
  4330. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4331. return $retorno;
  4332. } // static function new_ilm($itemid)
  4333. /// Function for save in database an iLM edit
  4334. // @param object $param An object with iLM params
  4335. static function edit_ilm ($param, $itemid) {
  4336. // Descobrir o tipo de iLM:
  4337. global $DB, $USER, $CFG;
  4338. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4339. $pathtemp = $CFG->dataroot . '/temp/';
  4340. $contextuser = context_user::instance($USER->id);
  4341. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4342. $zip = new zip_packer();
  4343. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4344. $files_extract = null;
  4345. foreach ($files as $file) {
  4346. if (!$file->is_directory())
  4347. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4348. }
  4349. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4350. $typec = strtolower($iassign_t->type);
  4351. require_once 'ilm_handlers/' . $typec . '.php';
  4352. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4353. }
  4354. /// Function for register the new iLM (in database and in the directory)
  4355. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4356. // @param object $param An object with iLM params
  4357. static function copy_new_version_ilm ($param) {
  4358. global $DB, $CFG, $USER;
  4359. $itemid = $param->file;
  4360. $pathtemp = $CFG->dataroot . '/temp/';
  4361. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4362. //D echo "pathtemp=$pathtemp<br/>";
  4363. $contextuser = context_user::instance($USER->id);
  4364. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4365. $zip = new zip_packer();
  4366. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4367. $files_extract = null;
  4368. foreach ($files as $file) {
  4369. if (!$file->is_directory())
  4370. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4371. }
  4372. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4373. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4374. $typec = strtolower($iassign_t->type);
  4375. require_once 'ilm_handlers/' . $typec . '.php';
  4376. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4377. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4378. } // static function copy_new_version_ilm($param)
  4379. //VER::
  4380. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4381. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4382. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4383. /// Function for change visibility of iLM
  4384. // @param int $ilm_id Id of iLM
  4385. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4386. static function visible_ilm ($ilm_id, $status) {
  4387. global $DB;
  4388. if ($status == 0)
  4389. $visible = 1;
  4390. else
  4391. $visible = 0;
  4392. $newentry = new stdClass();
  4393. $newentry->id = $ilm_id;
  4394. $newentry->enable = $visible;
  4395. if (!$DB->update_record("iassign_ilm", $newentry))
  4396. error(get_string('error_edit_ilm', 'iassign'));
  4397. }
  4398. /// Function for confirm change default iLM
  4399. // @param int $ilm_id Id of iLM
  4400. // @param int $ilm_parent Id of parent iLM
  4401. // @return string Return with an string for create default page confirmation
  4402. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4403. global $OUTPUT, $DB;
  4404. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4405. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4406. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4407. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4408. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4409. return $return;
  4410. }
  4411. /// Function for change the default iLM
  4412. // @see settings_ilm.php
  4413. // @param int $ilm_id Id of iLM
  4414. // @return int Return Id of default iLM
  4415. static function default_ilm ($ilm_id) {
  4416. global $DB;
  4417. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4418. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4419. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4420. $iassign_ilm_default->id = $iassign_ilm->id;
  4421. $iassign_ilm_default->parent = 0;
  4422. $iassign_ilm->parent = $iassign_ilm_default->id;
  4423. $iassign_ilm->id = 0;
  4424. $iassign_ilm_default->enable = 1;
  4425. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4426. print_error('error_edit_ilm', 'iassign');
  4427. }
  4428. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4429. if (!$inserted) {
  4430. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4431. print_error($msg_error);
  4432. //xx print_error('error_add_ilm', 'iassign');
  4433. }
  4434. return $iassign_ilm_default->id;
  4435. } // static function default_ilm ($ilm_id)
  4436. /// Function for confirm delete iLM
  4437. // @param int $ilm_id Id of iLM
  4438. // @param int $ilm_parent Id of parent iLM
  4439. // @return string Return with an string for create delete page confirmation
  4440. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4441. global $OUTPUT, $DB;
  4442. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4443. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4444. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4445. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4446. }
  4447. /// Function for delete directory where the iLM is allocated.
  4448. // @param string $dirPath
  4449. // @throws InvalidArgumentException
  4450. public static function delete_dir ($dirPath) {
  4451. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4452. $dirPath .= '/';
  4453. }
  4454. $files = glob($dirPath . '*', GLOB_MARK);
  4455. foreach ($files as $file) {
  4456. if (is_dir($file)) {
  4457. ilm_settings::delete_dir($file);
  4458. } else {
  4459. unlink($file);
  4460. }
  4461. }
  4462. rmdir($dirPath);
  4463. }
  4464. /// Function for delete iLM
  4465. // @param int $ilm_id Id of iLM
  4466. // @return int Return Id of parent iLM
  4467. static function delete_ilm ($ilm_id) {
  4468. global $DB;
  4469. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4470. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4471. $typec = strtolower($iassign_ilm->type);
  4472. require_once 'ilm_handlers/' . $typec . '.php';
  4473. $retorno = $typec::delete_ilm($ilm_id);
  4474. return $retorno;
  4475. }
  4476. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4477. // @param int $ilm_id Id of iLM
  4478. static function export_ilm ($ilm_id) {
  4479. global $DB;
  4480. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4481. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4482. $typec = strtolower($iassign_ilm->type);
  4483. require_once 'ilm_handlers/' . $typec . '.php';
  4484. $typec::export_ilm($ilm_id);
  4485. } // static function export_ilm($ilm_id)
  4486. //TODO iLM_HTML5 :: //MOOC 2016
  4487. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4488. // @param int $ilm_id Id of iLM
  4489. static function export_update_ilm ($ilm_id) {
  4490. global $DB, $CFG;
  4491. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4492. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4493. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4494. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4495. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4496. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4497. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4498. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4499. $upgrade_descriptor .= '</upgrade>' . "\n";
  4500. file_put_contents($xml_filename, $upgrade_descriptor);
  4501. header("Pragma: public");
  4502. header("Expires: 0");
  4503. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4504. header("Cache-Control: private", false);
  4505. header('Content-Type: application/xml; charset=utf-8');
  4506. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4507. header("Content-Length: " . @filesize($xml_filename));
  4508. set_time_limit(0);
  4509. @readfile("$xml_filename") || die("File not found.");
  4510. unlink($xml_filename);
  4511. exit;
  4512. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4513. /// Function for save iLM from XML descriptor
  4514. // @param array $application_xml Data of XML descriptor
  4515. // @param array $files_extract Filenames of extract files
  4516. // @return array Return an array content id of JAR files
  4517. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4518. global $CFG, $USER;
  4519. // Tratamento diferenciado se for do tipo HTML5:
  4520. $source = "";
  4521. $diretorio = "";
  4522. if (strtolower($application_xml->type) == 'html5') {
  4523. $i = 0;
  4524. foreach ($files_extract as $key => $value) {
  4525. $file = $CFG->dataroot . '/temp/' . $key;
  4526. // Verifica se já existe a pasta no diretório dos iLM:
  4527. if ($i == 0) {
  4528. $source = $file;
  4529. if (file_exists("ilm/" . basename($file))) {
  4530. $j = 1;
  4531. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4532. $j ++;
  4533. }
  4534. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4535. // mkdir($diretorio, 0777, true);
  4536. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4537. }
  4538. else {
  4539. $diretorio = 'ilm/' . basename($file);
  4540. // mkdir($diretorio, 0777, true);
  4541. mkdir($diretorio, 0755, true);
  4542. }
  4543. break;
  4544. }
  4545. $i ++;
  4546. }
  4547. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4548. if ($item->isDir()) {
  4549. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4550. }
  4551. else {
  4552. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4553. }
  4554. }
  4555. ilm_settings::delete_dir($source);
  4556. return "./" . $diretorio;
  4557. }
  4558. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4559. $file_jar = array();
  4560. $files_ilm = explode(",", $application_xml->file_jar);
  4561. $contextsystem = context_system::instance();
  4562. foreach ($files_ilm as $value) {
  4563. $file_ilm = array(
  4564. 'userid' => $USER->id,
  4565. 'contextid' => $contextsystem->id,
  4566. 'component' => 'mod_iassign',
  4567. 'filearea' => 'ilm',
  4568. 'itemid' => rand(1, 999999999),
  4569. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4570. 'filename' => $value);
  4571. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4572. array_push($file_jar, $file_ilm->get_id());
  4573. }
  4574. foreach ($files_extract as $key => $value) {
  4575. $file = $CFG->dataroot . '/temp/' . $key;
  4576. if (file_exists($file))
  4577. unlink($file);
  4578. }
  4579. return $file_jar;
  4580. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4581. /// Function for import the iLM from an package
  4582. // @param int $itemid Itemid of zip file
  4583. static function import_ilm ($itemid) {
  4584. global $CFG, $USER, $OUTPUT;
  4585. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4586. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4587. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4588. }
  4589. $pathtemp = $CFG->dataroot . '/temp/';
  4590. $contextuser = context_user::instance($USER->id);
  4591. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4592. $zip = new zip_packer();
  4593. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4594. foreach ($files as $file) {
  4595. if (!$file->is_directory())
  4596. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4597. }
  4598. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4599. // Verifica se o pacote possui o XML
  4600. if (!$application_xml) {
  4601. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4602. return;
  4603. } else {
  4604. $missing = "";
  4605. if (!isset($application_xml->name)) {
  4606. $missing .= "name";
  4607. }
  4608. if (!isset($application_xml->version)) {
  4609. $missing .= ", version";
  4610. }
  4611. if (!isset($application_xml->type)) {
  4612. $missing .= ", type";
  4613. }
  4614. if (!isset($application_xml->extension)) {
  4615. $missing .= ", extension";
  4616. }
  4617. if (!isset($application_xml->file_jar)) {
  4618. $missing .= ", file_jar";
  4619. }
  4620. if (!isset($application_xml->file_class)) {
  4621. $missing .= ", file_class";
  4622. }
  4623. if (!isset($application_xml->width)) {
  4624. $missing .= ", width";
  4625. }
  4626. if (!isset($application_xml->height)) {
  4627. $missing .= ", height";
  4628. }
  4629. if (!isset($application_xml->evaluate)) {
  4630. $missing .= ", evaluate";
  4631. }
  4632. if (strlen($missing) > 2) {
  4633. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4634. return;
  4635. }
  4636. }
  4637. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4638. $typec = strtolower($application_xml->type);
  4639. require_once 'ilm_handlers/' . $typec . '.php';
  4640. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4641. } // static function import_ilm($itemid)
  4642. /// Function for list iLM defaults
  4643. // @return string Return an string with a table of iLM
  4644. static function list_ilm () {
  4645. global $DB, $OUTPUT;
  4646. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4647. $str = '';
  4648. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4649. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4650. if ($iassign_ilm) {
  4651. foreach ($iassign_ilm as $ilm) {
  4652. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4653. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4654. $str .= '<tr><td>';
  4655. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4656. $str .= '<tr>';
  4657. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4658. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4659. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4660. $str .= '</tr>';
  4661. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4662. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4663. $str .= '</table>';
  4664. $str .= '</td></tr>';
  4665. }
  4666. }
  4667. $str .= '</table>';
  4668. return $str;
  4669. }
  4670. /// Function for download and install an upgrade of an iLM
  4671. // @param int $ilm_id Id of iLM
  4672. static function upgrade_ilm ($ilm_id) {
  4673. global $DB, $CFG, $USER;
  4674. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4675. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4676. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4677. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4678. if (!$result)
  4679. print_error('error_upgrade_ilm', 'iassign');
  4680. else {
  4681. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4682. $extension = explode(".", $zip_filename);
  4683. if ($extension[count($extension) - 1] != 'ipz') {
  4684. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4685. die;
  4686. }
  4687. $zip = new zip_packer();
  4688. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4689. $contextuser = context_user::instance($USER->id);
  4690. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4691. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4692. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4693. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4694. if (file_exists($zip_filename))
  4695. unlink($zip_filename);
  4696. if (empty($file_jar)) {
  4697. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4698. print_error($msg_error);
  4699. //xx print_error('error_add_ilm', 'iassign');
  4700. }
  4701. else {
  4702. $newentry = new stdClass();
  4703. $newentry->name = (String) $application_xml->name;
  4704. $newentry->version = (String) $application_xml->version;
  4705. $newentry->url = (String) $application_xml->url;
  4706. $newentry->description = $description_str;
  4707. $newentry->extension = strtolower((String) $application_xml->extension);
  4708. $newentry->file_jar = implode(",", $file_jar);
  4709. $newentry->file_class = (String) $application_xml->file_class;
  4710. $newentry->width = (String) $application_xml->width;
  4711. $newentry->height = (String) $application_xml->height;
  4712. $newentry->enable = 0;
  4713. $newentry->timemodified = time();
  4714. $newentry->author = $USER->id;
  4715. $newentry->timecreated = time();
  4716. $newentry->evaluate = (String) $application_xml->evaluate;
  4717. $newentry->parent = $ilm_id;
  4718. }
  4719. }
  4720. return $iassign_ilm->id;
  4721. } // static function upgrade_ilm($ilm_id)
  4722. //MOOC2014 -- inicio
  4723. //TODO: REVIEW
  4724. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4725. // static function move_iassign($ilm_id)
  4726. //MOOC2014 -- final
  4727. /// Function for list iLM versions with all informations
  4728. // @return string Return an string with a table of iLM
  4729. static function view_ilm ($ilmid, $from) {
  4730. global $DB;
  4731. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4732. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4733. $typec = strtolower($iassign_ilm->type);
  4734. require_once 'ilm_handlers/' . $typec . '.php';
  4735. $retorno = $typec::view_ilm($ilmid, $from);
  4736. return $retorno;
  4737. }
  4738. /// Function for get form variables for add, edit, or copy iLM params
  4739. // @param int $ilm_param_id Id of iLM param
  4740. // @param string $action String with the action
  4741. // @return object Return an object with forms variables
  4742. static function add_edit_copy_param ($ilm_param_id, $action) {
  4743. global $DB;
  4744. require_once('params_form.php');
  4745. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4746. $param = new stdClass();
  4747. $param->action = $action;
  4748. $param->ilm_param_id = $ilm_param_id;
  4749. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4750. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4751. $type = $iassign_ilm_config->param_type;
  4752. if ($action == 'add') {
  4753. $param->title = get_string('add_ilm', 'iassign');
  4754. $param->iassign_ilmid = $ilm_param_id;
  4755. $param->param_name = "";
  4756. $param->param_value = "";
  4757. $param->description = "";
  4758. $param->visible = 1;
  4759. }
  4760. elseif ($action == 'edit') {
  4761. if ($iassign_ilm_config) {
  4762. $param->title = get_string('edit_ilm', 'iassign');
  4763. $param->id = $iassign_ilm_config->id;
  4764. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4765. $param->param_type = $type; //MOOC2014
  4766. $param->param_name = $iassign_ilm_config->param_name;
  4767. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4768. $param->param_value = $iassign_ilm_config->param_value;
  4769. else //MOOC2014
  4770. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4771. $param->param_value = $iassign_ilm_config->param_value;
  4772. $param->description = $iassign_ilm_config->description;
  4773. $param->visible = $iassign_ilm_config->visible;
  4774. }
  4775. }
  4776. elseif ($action == 'copy') {
  4777. if ($iassign_ilm_config) {
  4778. $param->title = get_string('copy_ilm', 'iassign');
  4779. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4780. $param->param_type = $type; //MOOC2014
  4781. $param->param_name = $iassign_ilm_config->param_name;
  4782. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4783. $param->param_value = $iassign_ilm_config->param_value;
  4784. else //MOOC2014
  4785. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4786. $param->description = $iassign_ilm_config->description;
  4787. $param->visible = $iassign_ilm_config->visible;
  4788. }
  4789. }
  4790. return $param;
  4791. } // static function add_edit_copy_param($ilm_param_id, $action)
  4792. /// Function for change visibility of iLM param
  4793. // @param int $ilm_param_id Id of iLM param
  4794. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4795. static function visible_param ($ilm_param_id, $status) {
  4796. global $DB, $CFG;
  4797. if ($status == 0)
  4798. $visible = 1;
  4799. else
  4800. $visible = 0;
  4801. $newentry = new stdClass();
  4802. $newentry->id = $ilm_param_id;
  4803. $newentry->visible = $visible;
  4804. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4805. error(get_string('error_edit_param', 'iassign'));
  4806. }
  4807. /// Function for save in database an new iLM param
  4808. // @param object $param An object with iLM params
  4809. static function add_param ($param) {
  4810. global $DB;
  4811. $newentry = new stdClass();
  4812. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4813. //MOOC2014 $newentry->param_name = $param->param_name;
  4814. $newentry->param_type = $param->param_type; //MOOC2014
  4815. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4816. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4817. $newentry->param_value = $param->param_value;
  4818. else //MOOC2014
  4819. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4820. $newentry->description = $param->description;
  4821. $newentry->visible = $param->visible;
  4822. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4823. if (!$newentry->id) {
  4824. print_error('error_add_param', 'iassign');
  4825. }
  4826. }
  4827. /// Function for save in database a iLM param edit
  4828. // @param object $param An object with iLM params
  4829. static function edit_param ($param) {
  4830. global $DB;
  4831. $updentry = new stdClass();
  4832. $updentry->id = $param->id;
  4833. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4834. $updentry->param_type = $param->param_type; //MOOC2014
  4835. // $updentry->param_name = $param->param_name;
  4836. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4837. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4838. $updentry->param_value = $param->param_value;
  4839. else //MOOC2014
  4840. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4841. $updentry->description = $param->description;
  4842. $updentry->visible = $param->visible;
  4843. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4844. error(get_string('error_edit_param', 'iassign'));
  4845. }
  4846. }
  4847. /// Function for save in database a iLM param copy
  4848. // @param object $param An object with iLM params
  4849. static function copy_param ($param) {
  4850. global $DB;
  4851. $newentry = new stdClass();
  4852. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4853. //$newentry->param_name = $param->param_name;
  4854. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4855. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4856. $newentry->param_value = $param->param_value;
  4857. else //MOOC2014
  4858. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4859. $newentry->description = $param->description;
  4860. $newentry->visible = $param->visible;
  4861. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4862. if (!$newentry->id) {
  4863. print_error('error_add_param', 'iassign');
  4864. }
  4865. }
  4866. /// Function for delete iLM param of database
  4867. // @param int $param_id Id of iLM param
  4868. static function delete_param ($param_id) {
  4869. global $DB;
  4870. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4871. print_error('error_delete_param', 'iassign');
  4872. }
  4873. }
  4874. } // class ilm_settings
  4875. /// Class for manage iLM files (editor).
  4876. class ilm_manager {
  4877. var $id; // course id
  4878. var $url;
  4879. var $from;
  4880. /// Constructor for the base ilm_manager class
  4881. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4882. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4883. function __construct ($id, $url, $from) {
  4884. $this->id = $id; // course id
  4885. $this->url = $url;
  4886. $this->from = $from;
  4887. }
  4888. /// Function to get iAssign content file in Moodle data (exercise)
  4889. // @calledby x function preview_ilm($iassign_ilm) :
  4890. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4891. function get_file_ilm () {
  4892. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4893. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4894. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4895. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4896. $md_file = $fs->get_file_by_id($fileid);
  4897. $ilm_content_file = $md_file->get_content();
  4898. return $ilm_content_file;
  4899. }
  4900. /// Function for creating a new file from the iLM online editor
  4901. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4902. function ilm_editor_new () {
  4903. global $CFG, $DB, $OUTPUT, $PAGE;
  4904. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4905. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4906. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4907. $context = context_course::instance($this->id);
  4908. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4909. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4910. if (!$iassign) {
  4911. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4912. die();
  4913. }
  4914. $temp = explode(",", $iassign->extension);
  4915. $extension = $temp[0]; // default extension for this iLM
  4916. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4917. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4918. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4919. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4920. if ($stringArchiveContent != NULL) {
  4921. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4922. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4923. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4924. $filename = optional_param('filename', NULL, PARAM_RAW);
  4925. //Leo $filename = iassign_utils::format_filename($filename); //
  4926. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4927. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4928. //2019/02 $arrayfilename = explode(".", $filename);
  4929. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4930. //2019/02 $count_dots = count($arrayfilename);
  4931. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4932. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4933. //2019/02 if ($last_name != $extension)
  4934. //2019/02 $filename = $filename . '.' . $extension;
  4935. //2019/02 }
  4936. //2019/02 else { // no extension...
  4937. //2019/02 $filename = $filename . '.' . $extension;
  4938. //2019/02 }
  4939. // Store the name of recent created file
  4940. $_SESSION['file_name'] = $filename;
  4941. //$this->write_file_iassign($string, $filename);
  4942. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4943. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4944. die();
  4945. }
  4946. else { // if ($stringArchiveContent != NULL)
  4947. // iLM On-line editor
  4948. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4949. $str_get_iLM = "window.frames.iLM";
  4950. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4951. }
  4952. else { // otherwise it is JAR named 'iLM'
  4953. $str_get_iLM = "document.iLM";
  4954. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4955. }
  4956. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4957. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4958. $files_array = '';
  4959. foreach ($files as $value) {
  4960. if ($value->get_filename() != ".")
  4961. $files_array .= "'" . $value->get_filename() . "',";
  4962. }
  4963. $files_array .= "''";
  4964. $file = null;
  4965. $ia_content = "";
  4966. $filename = "";
  4967. $error_files_exists = get_string('error_file_exists', 'iassign');
  4968. $output = "<script type='text/javascript'>
  4969. //<![CDATA[
  4970. //D alert('locallib.php: ilm_editor_new');
  4971. function submit_iLM_Answer () {
  4972. var docFormOnLineEditor = document.formEnvio;
  4973. var resposta_exerc = new Array(3);
  4974. var valor_resposta = new Array(3);
  4975. var sessao = new Array(3);
  4976. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4977. resposta_exerc[0] = doc_iLM.getAnswer();
  4978. valor_resposta[0] = doc_iLM.getEvaluation();
  4979. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4980. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4981. var files = new Array(" . $files_array . ");
  4982. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4983. if (docFormOnLineEditor.filename.value=='') {
  4984. // ERROR: the file name is empty
  4985. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4986. return false;
  4987. }
  4988. // }
  4989. for (i=0; i<files.length; i++) {
  4990. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4991. alert('" . $error_files_exists . "');
  4992. return false;
  4993. }
  4994. }
  4995. docFormOnLineEditor.submit();
  4996. return true;
  4997. }
  4998. //]]>
  4999. </script>\n";
  5000. $output .= "
  5001. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5002. $output .= $OUTPUT->box_start();
  5003. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5004. $output .= "
  5005. <table width='100%' cellpadding='20'>
  5006. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5007. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5008. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5009. </tr>
  5010. </table>\n";
  5011. $output .= $OUTPUT->box_end();
  5012. $output .= "<center>\n";
  5013. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5014. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5015. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5016. $output .= $output_ilm;
  5017. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5018. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5019. </center>
  5020. </form>\n";
  5021. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5022. $PAGE->navbar->add($title);
  5023. $PAGE->set_title($title);
  5024. $PAGE->set_heading($title); // insert title above the navigation bar
  5025. print $OUTPUT->header();
  5026. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5027. print $output;
  5028. print $OUTPUT->footer();
  5029. }
  5030. die();
  5031. } // function ilm_editor_new()
  5032. /// Function for editing an file in online editor
  5033. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5034. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5035. global $CFG, $DB, $OUTPUT, $PAGE;
  5036. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5037. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5038. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5039. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5040. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5041. // If iLM is not registered, error!
  5042. if (!$iassign) {
  5043. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5044. die;
  5045. }
  5046. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5047. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5048. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5049. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5050. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5051. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5052. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5053. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5054. if ($stringArchiveContent != NULL) {
  5055. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5056. die();
  5057. } else { // if ($stringArchiveContent != NULL)
  5058. $end_file = '';
  5059. if ($content_file) {
  5060. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5061. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5062. }
  5063. $temp = explode(",", $iassign->extension);
  5064. $extension = $temp[0]; // default extension for this iLM
  5065. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  5066. $str_get_iLM = "window.frames.iLM";
  5067. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5068. } else { // otherwise it is JAR named 'iLM'
  5069. $str_get_iLM = "document.iLM";
  5070. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5071. }
  5072. $output = "<script type='text/javascript'>
  5073. //<![CDATA[
  5074. function submit_iLM_Answer () {
  5075. var docFormEditor = document.formEnvio;
  5076. var activityAnswer; // to get activity answer (text)
  5077. var activityValue; // to get activity answer value (float)
  5078. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5079. //activityAnswer = doc_iLM.getAnswer();
  5080. //activityValue = doc_iLM.getEvaluation();
  5081. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5082. activityValue = " . $str_get_iLM . ".getEvaluation();
  5083. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5084. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5085. docFormEditor.submit();
  5086. return true;
  5087. }
  5088. //]]>
  5089. </script>\n";
  5090. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5091. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5092. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5093. // return true;
  5094. // }
  5095. $output .= "
  5096. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5097. $output .= $OUTPUT->box_start();
  5098. $output .= "
  5099. <table width='100%' cellpadding='20'>
  5100. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5101. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5102. <input type='hidden' name='filename' value='$filename'/></td>
  5103. <td>
  5104. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5105. </tr>
  5106. </table>\n";
  5107. $output .= $OUTPUT->box_end();
  5108. $output .= " <center>\n";
  5109. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5110. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5111. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5112. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5113. </center>
  5114. </form>\n";
  5115. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5116. $PAGE->navbar->add($title);
  5117. $PAGE->set_title($title);
  5118. $PAGE->set_heading($title); // insert title above the navigation bar
  5119. print $OUTPUT->header();
  5120. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5121. print $output;
  5122. print $OUTPUT->footer();
  5123. } // else if ($stringArchiveContent != NULL)
  5124. die();
  5125. } // function ilm_editor_update()
  5126. /// Function for write iAssign file in Moodle data (exercise)
  5127. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5128. // @param string $stringArchiveContent Content of iassign file
  5129. // @param string $filename Filename of iassign file
  5130. function write_file_iassign ($stringArchiveContent, $filename) {
  5131. global $USER;
  5132. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5133. $context = context_course::instance($this->id);
  5134. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5135. $dirid = $this->get_dir_ilm('dirid');
  5136. $dir = $fs->get_file_by_id($dirid);
  5137. $fileinfo = array('contextid' => $context->id, // ID of course
  5138. 'component' => 'mod_iassign', // usually = table name
  5139. 'filearea' => 'activity', // usually = table name
  5140. 'itemid' => 0, // usually = ID of row in table
  5141. 'filepath' => '/', // any path beginning and ending whith '/'
  5142. 'userid' => $USER->id,
  5143. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5144. 'filename' => $filename); // any filename
  5145. // Create file containing text. '$stringArchiveContent'
  5146. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5147. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5148. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5149. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5150. // 'Activité interactive enregistrée avec succès sous le nom:';
  5151. // 'Atividade interativa gravada com sucesso sob o nome:'
  5152. $output = "
  5153. <script type='text/javascript'>
  5154. //<![CDATA[
  5155. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5156. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5157. //]]>
  5158. </script>";
  5159. print $output;
  5160. die();
  5161. }
  5162. /// Function for write iAssign file in Moodle data (exercise)
  5163. // @param string $stringArchiveContent Content of iassign file
  5164. // @param string $filename Filename of iassign file
  5165. // @param int $itemid Itemid of iassign file
  5166. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5167. global $OUTPUT, $USER;
  5168. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5169. $context = context_course::instance($this->id);
  5170. $dirid = $this->get_dir_ilm('dirid');
  5171. if ($stringArchiveContent != (-1)) {
  5172. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5173. $file = $fs->get_file_by_id($fileid);
  5174. if (!$file) {
  5175. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5176. die;
  5177. }
  5178. $fileinfo = array('contextid' => $context->id, // ID of context
  5179. 'component' => 'mod_iassign', // usually = table name
  5180. 'filearea' => 'activity', // usually = table name
  5181. 'itemid' => 0, // usually = ID of row in table
  5182. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5183. 'userid' => $USER->id,
  5184. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5185. 'license' => 'allrightsreserved', // allrightsreserved
  5186. 'timecreated' => $file->get_timecreated(),
  5187. 'filename' => $file->get_filename()); // any filename
  5188. $file->delete();
  5189. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5190. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5191. }
  5192. $output = "<script type='text/javascript'>
  5193. //<![CDATA[
  5194. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5195. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5196. //]]>
  5197. </script>";
  5198. print $output;
  5199. die();
  5200. }
  5201. /// Function for create an tag for iAssign filter
  5202. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5203. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5204. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5205. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5206. // @param int $fileid Id of file
  5207. // @return string Return an string with an tag of iassign filter
  5208. function tag_ilm ($fileid) {
  5209. global $DB;
  5210. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5211. $width = '600';
  5212. $height = '400';
  5213. $file = $fs->get_file_by_id($fileid);
  5214. $filetype = explode(".", $file->get_filename());
  5215. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5216. foreach ($iassign_ilm as $value) {
  5217. $extensions = explode(",", $value->extension);
  5218. if (in_array($filetype[1], $extensions)) {
  5219. $width = $value->width;
  5220. $height = $value->height;
  5221. }
  5222. }
  5223. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5224. }
  5225. /// Function for delete iAssign file in Moodle data (exercise)
  5226. function delete_file_ilm () {
  5227. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5228. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5229. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5230. $file = $fs->get_file_by_id($fileid);
  5231. if ($file)
  5232. $file->delete();
  5233. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5234. die();
  5235. }
  5236. /// Function for delete selected iAssign file in Moodle data (exercise)
  5237. function delete_selected_ilm () {
  5238. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5239. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5240. $context = context_course::instance($this->id);
  5241. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5242. $dirid = $this->get_dir_ilm('dirid');
  5243. foreach ($files_id as $file_id) {
  5244. $file = $fs->get_file_by_id($file_id);
  5245. if ($file) {
  5246. if (!$file->is_directory())
  5247. $file->delete();
  5248. else {
  5249. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5250. foreach ($files_delete as $value)
  5251. $value->delete();
  5252. $file->delete();
  5253. }
  5254. }
  5255. }
  5256. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5257. die();
  5258. }
  5259. /// Function for duplicate iAssign file from "online" edition
  5260. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5261. function duplicate_file_ilm () {
  5262. global $USER, $COURSE;
  5263. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5264. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5265. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5266. $filename = optional_param('filename', NULL, PARAM_RAW);
  5267. $file = $fs->get_file_by_id($fileid);
  5268. $context = context_course::instance($this->id);
  5269. $fileinfo = array(
  5270. 'contextid' => $context->id, // ID of context
  5271. 'component' => 'mod_iassign', // usually = table name
  5272. 'filearea' => 'activity', // usually = table name
  5273. 'itemid' => 0, // usually = ID of row in table
  5274. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5275. 'userid' => $USER->id,
  5276. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5277. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5278. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5279. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5280. die();
  5281. }
  5282. /// Function for rename iAssign file
  5283. function rename_file_ilm () {
  5284. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5285. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5286. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5287. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5288. $file = $fs->get_file_by_id($fileid);
  5289. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5290. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5291. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5292. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5293. die();
  5294. }
  5295. /// Function for get iassign file for iassign form
  5296. function add_ilm () {
  5297. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5298. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5299. $output = "
  5300. <script type='text/javascript'>
  5301. //<![CDATA[
  5302. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5303. iassign_file_link.innerHTML = '$filename';
  5304. window.opener.document.forms['mform1'].file.value='$fileid';
  5305. window.opener.document.forms['mform1'].filename.value='$filename';
  5306. window.close();
  5307. //]]>
  5308. </script>";
  5309. print $output;
  5310. die();
  5311. }
  5312. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5313. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5314. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5315. function preview_ilm ($courseid, $iassign_ilm) {
  5316. global $OUTPUT, $CFG, $USER;
  5317. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5318. $title = get_string('modulename', 'iassign'); // iAssign
  5319. print $OUTPUT->header();
  5320. print $OUTPUT->box_start();
  5321. $javascript = "
  5322. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5323. <script type='text/javascript'>
  5324. //<![CDATA[
  5325. function submit_close () {
  5326. window.opener.location.reload();
  5327. window.close();
  5328. }
  5329. //]]>
  5330. </script>\n";
  5331. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5332. // to the complete "applet" tag
  5333. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5334. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5335. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5336. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5337. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5338. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5339. if ($ilm_name != "ivprog") {
  5340. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5341. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5342. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5343. } else {
  5344. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5345. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5346. $timecreated = time();
  5347. $token = md5($timecreated);
  5348. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5349. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5350. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5351. $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)
  5352. }
  5353. $html = "
  5354. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5355. <table border='1'>
  5356. <tr><td>
  5357. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5358. <!-- iLM calls : end -->
  5359. </td></tr>
  5360. </table>
  5361. <table>
  5362. <tr>
  5363. <td align='center'>
  5364. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5365. </td></tr>
  5366. </table>
  5367. </form>\n";
  5368. print $javascript . $html;
  5369. print $OUTPUT->box_end();
  5370. //NAO echo format_string($html); // Moodle 3.X
  5371. die();
  5372. } // function preview_ilm($courseid, $iassign_ilm)
  5373. //r_ function preview_ilm ($iassign_ilm)
  5374. //r_ /// Function for preview iassign file from iassign filter.
  5375. //r_ function preview_ilm() {
  5376. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5377. //r_ $tag_filter = $this->tag_ilm($fileid);
  5378. //r_ $javascript = "<script type='text/javascript'>
  5379. //r_ //<![CDATA[
  5380. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5381. //r_ //]]>
  5382. //r_ </script>";
  5383. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5384. //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>
  5385. //r_ </table></form></body></html>";
  5386. //r_ echo $javascript . format_text($html);
  5387. //r_ die;
  5388. //r_ }
  5389. /// Function for export an package (zip) of iassign files
  5390. function export_files_ilm () {
  5391. global $CFG;
  5392. $context = context_course::instance($this->id);
  5393. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5394. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5395. $zip = new zip_archive();
  5396. $zip->open($zip_filename);
  5397. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5398. foreach ($files_id as $file_id) {
  5399. $file = $fs->get_file_by_id($file_id);
  5400. if (!$file->is_directory())
  5401. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5402. else {
  5403. $zip->add_directory($file->get_filepath());
  5404. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5405. foreach ($files_zip as $value) {
  5406. if (!$value->is_directory())
  5407. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5408. else
  5409. $zip->add_directory($value->get_filepath());
  5410. }
  5411. }
  5412. }
  5413. $zip->close();
  5414. header("Pragma: public");
  5415. header("Expires: 0");
  5416. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5417. header("Cache-Control: private", false);
  5418. header("Content-Type: application/zip");
  5419. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5420. header("Content-Transfer-Encoding: binary");
  5421. header("Content-Length: " . @filesize($zip_filename));
  5422. set_time_limit(0);
  5423. @readfile("$zip_filename") || die("File not found.");
  5424. unlink($zip_filename);
  5425. exit;
  5426. }
  5427. /// Function of execute a command in button editor tinymce
  5428. // @param int $fileid Id of file
  5429. function tinymce_ilm ($fileid) {
  5430. $tag_filter = $this->tag_ilm($fileid);
  5431. $output = "<script type='text/javascript'>
  5432. //<![CDATA[
  5433. var tag_filter = '$tag_filter';
  5434. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5435. // all right, insert it
  5436. } else {
  5437. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5438. }
  5439. // window.close();
  5440. //]]>
  5441. </script>\n";
  5442. print $output;
  5443. die();
  5444. }
  5445. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5446. /// Function to add content to the Editor Window
  5447. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5448. // @param int $fileid Id of file
  5449. function editor_ilm ($fileid, $editor) {
  5450. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5451. $output1 = "<script type='text/javascript'>
  5452. //<![CDATA[
  5453. var tag_filter = '$tag_filter';\n";
  5454. if ($editor == 'atto') {
  5455. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5456. } elseif ($editor == 'tinyMCE') {
  5457. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5458. } else
  5459. $output2 = "";
  5460. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5461. window.close();
  5462. //]]>
  5463. </script>\n";
  5464. //D var_dump($output);
  5465. print $output1 . $output2 . $output3;
  5466. die();
  5467. }
  5468. /// Function to add content to the Atto Editor Window
  5469. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5470. // @param int $fileid Id of file
  5471. function atto_ilm ($fileid) {
  5472. global $CFG, $DB;
  5473. $tag_filter = $this->tag_ilm($fileid);
  5474. $output = "<script type='text/javascript'>
  5475. //<![CDATA[
  5476. var tag_filter = '$tag_filter';
  5477. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5478. // all right, insert iLM tag to this editor
  5479. } else {
  5480. // error trying to insert
  5481. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5482. }
  5483. //window.close();
  5484. //]]>
  5485. </script>\n";
  5486. print $output;
  5487. die();
  5488. }
  5489. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5490. // @param string $key Key for return information
  5491. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5492. function get_dir_ilm ($key) {
  5493. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5494. $context = context_course::instance($this->id);
  5495. $dirid = optional_param('dirid', 0, PARAM_INT);
  5496. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5497. if ($dirid == 0) {
  5498. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5499. $dirid = $dir->get_id();
  5500. }
  5501. else {
  5502. $dir = $fs->get_file_by_id($dirid);
  5503. $dir_base = $dir->get_filepath();
  5504. }
  5505. $dir_parent = $dir->get_parent_directory();
  5506. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5507. return $data[$key];
  5508. }
  5509. /// Function for create an new dir
  5510. function new_dir_ilm () {
  5511. global $USER;
  5512. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5513. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5514. $dir_base = $this->get_dir_ilm('dir_base');
  5515. $context = context_course::instance($this->id);
  5516. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5517. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5518. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5519. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5520. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5521. }
  5522. /// Function for delete an dir
  5523. function delete_dir_ilm () { //
  5524. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5525. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5526. $context = context_course::instance($this->id);
  5527. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5528. $dir_parent = $this->get_dir_ilm('dir_parent');
  5529. if ($dir) {
  5530. if ($dir->is_directory()) {
  5531. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5532. foreach ($files_delete as $value)
  5533. $value->delete();
  5534. $dir->delete();
  5535. }
  5536. }
  5537. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5538. die();
  5539. }
  5540. /// Function for rename an dir
  5541. function rename_dir_ilm () {
  5542. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5543. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5544. $context = context_course::instance($this->id);
  5545. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5546. $dir_parent = $this->get_dir_ilm('dir_parent');
  5547. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5548. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5549. if ($dir->is_directory()) {
  5550. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5551. foreach ($files_rename_path as $value)
  5552. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5553. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5554. }
  5555. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5556. die();
  5557. }
  5558. /// Function for move an dir and your content for other dir
  5559. function selected_move_ilm () {
  5560. global $PAGE, $OUTPUT, $CFG;
  5561. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5562. $context = context_course::instance($this->id);
  5563. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5564. $dirid = $this->get_dir_ilm('dirid');
  5565. $dir_base = $this->get_dir_ilm('dir_base');
  5566. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5567. $code_javascript_ilm = "
  5568. <script type='text/javascript'>
  5569. //<![CDATA[
  5570. function getRadiobutton () {
  5571. var radioButtons = document.getElementsByTagName('input');
  5572. var param = '';
  5573. for (var counter=0; counter < radioButtons.length; counter++) {
  5574. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5575. param = radioButtons[counter].value;
  5576. }
  5577. return param;
  5578. }
  5579. function move_selected_ilm () {
  5580. var msgAnswer;
  5581. if (getRadiobutton() != '') {
  5582. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5583. if (msgAnswer)
  5584. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5585. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5586. }
  5587. else
  5588. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5589. }
  5590. function cancel_selected_ilm () {
  5591. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5592. }
  5593. //]]>
  5594. </script>\n";
  5595. $title = get_string('move_files', 'iassign');
  5596. $PAGE->set_title($title);
  5597. $PAGE->set_pagelayout('base');
  5598. print $OUTPUT->header();
  5599. print $OUTPUT->heading($title);
  5600. $dir_paths = array();
  5601. print $OUTPUT->box_start();
  5602. print "<center>";
  5603. foreach ($files_id as $file_id) {
  5604. $file = $fs->get_file_by_id($file_id);
  5605. if ($file) {
  5606. if (!$file->is_directory())
  5607. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5608. else {
  5609. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5610. array_push($dir_paths, $file->get_filepath());
  5611. }
  5612. }
  5613. }
  5614. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5615. if ($dir_base != '/') {
  5616. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5617. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5618. }
  5619. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5620. foreach ($files_tree as $file) {
  5621. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5622. $is_parent = false;
  5623. foreach ($dir_paths as $dir) {
  5624. $path = explode("/", $dir);
  5625. array_pop($path);
  5626. $path[count($path) - 1] = '';
  5627. $path = implode("/", $path);
  5628. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5629. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5630. }
  5631. if ($is_parent == false) {
  5632. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5633. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5634. }
  5635. }
  5636. }
  5637. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5638. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5639. print "</center>";
  5640. print $OUTPUT->box_end();
  5641. print $OUTPUT->footer();
  5642. print $code_javascript_ilm;
  5643. die;
  5644. }
  5645. /// Function for move files for an dir
  5646. function move_files_ilm () {
  5647. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5648. $context = context_course::instance($this->id);
  5649. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5650. $dirid = $this->get_dir_ilm('dirid');
  5651. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5652. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5653. foreach ($files_id as $file_id) {
  5654. $file = $fs->get_file_by_id($file_id);
  5655. if ($file) {
  5656. if ($file->is_directory()) {
  5657. $pathname = explode("/", $file->get_filepath());
  5658. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5659. foreach ($files_move_path as $value) {
  5660. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5661. $value->rename($path_move, $value->get_filename());
  5662. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5663. }
  5664. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5665. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5666. $file->rename($path_move, $file->get_filename());
  5667. } else {
  5668. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5669. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5670. }
  5671. }
  5672. }
  5673. //die;
  5674. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5675. die();
  5676. } // function move_files_ilm()
  5677. /// Function for recover files in use on all activities of a course
  5678. function recover_files_ilm () {
  5679. global $DB, $USER;
  5680. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5681. $courseid = optional_param('id', NULL, PARAM_INT);
  5682. $dirid = $this->get_dir_ilm('dirid');
  5683. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5684. $contextfile = context_course::instance($this->id);
  5685. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5686. foreach ($iassigns as $iassign) {
  5687. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5688. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5689. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5690. $context = context_module::instance($cm->id);
  5691. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5692. if ($files) {
  5693. foreach ($files as $value) {
  5694. $extension = explode(".", $value->get_filename());
  5695. if (!$value->is_directory()) {
  5696. $fileinfo = array('contextid' => $contextfile->id,
  5697. 'component' => 'mod_iassign',
  5698. 'filearea' => 'activity',
  5699. 'itemid' => 0,
  5700. 'filepath' => $this->get_dir_ilm('dir_base'),
  5701. 'userid' => $USER->id,
  5702. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5703. 'license' => 'allrightsreserved',
  5704. 'timecreated' => time(),
  5705. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5706. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5707. }
  5708. }
  5709. } // if ($files)
  5710. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5711. } // foreach ($iassigns as $iassign)
  5712. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5713. die();
  5714. } // function recover_files_ilm()
  5715. /// Auxiliary function the get all files in a given context
  5716. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5717. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5718. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5719. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5720. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5721. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5722. // (NAO s_iassign_statement.file = s_files.id)
  5723. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5724. $dir_base = $this->get_dir_ilm('dir_base');
  5725. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5726. $countf = 0;
  5727. $array_files_id = array(); // all files from this context
  5728. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5729. //$filename = $item_fc->get_filename();
  5730. //$filepath = $item_fc->get_filepath();
  5731. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5732. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5733. // $array_files_aux[] = $item_fc;
  5734. $itemid = $item_fc->get_id();
  5735. if (!in_array($itemid, $array_files_id)) {
  5736. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5737. if ($fileuserid == $userid)
  5738. $filesfrommine[] = $item_fc;
  5739. else
  5740. $filesfromothers[] = $item_fc;
  5741. $array_files_id[] = $itemid;
  5742. $countf++;
  5743. }
  5744. }
  5745. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5746. return $countf;
  5747. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5748. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5749. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5750. function get_all_ilm_files_by_fileid ($fileid) {
  5751. global $DB, $USER;
  5752. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5753. //TODO Criar coluna 'authorid'
  5754. $str_query = "SELECT * FROM {iassign_statement} " .
  5755. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5756. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5757. return $array_iassign_ilm;
  5758. }
  5759. //NN
  5760. //NN
  5761. // Build string with JavaScript code with function to edit/remove/double iLM files
  5762. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5763. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5764. global $CFG;
  5765. $error_files_exists = get_string('error_file_exists', 'iassign');
  5766. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5767. $code_javascript_ilm = "
  5768. <script type='text/javascript'>
  5769. //<![CDATA[
  5770. function preview_ilm (fileid, ilmid) { //JavaScript function
  5771. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5772. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5773. }
  5774. function update_ilm (ilmid, fileid) { //JavaScript function
  5775. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5776. }
  5777. function delete_ilm (ilmid, fileid) { //JavaScript function
  5778. var msgAnswer;
  5779. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5780. if (msgAnswer) {
  5781. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5782. }
  5783. }
  5784. function delete_selected_ilm () { //JavaScript function
  5785. var msgAnswer;
  5786. var param = getCheckbox();
  5787. if (param.join() != '') {
  5788. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5789. if (msgAnswer)
  5790. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5791. }
  5792. else
  5793. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5794. }
  5795. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5796. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5797. }
  5798. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5799. var filenamecopy;
  5800. var i;
  5801. var files = new Array(" . $files_array . ");
  5802. do {
  5803. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5804. } while (filenamecopy == '');
  5805. if (filenamecopy == null)
  5806. return false;\n
  5807. else {
  5808. for (i=0;i<files.length;i++) {
  5809. if (files[i]==filenamecopy) {
  5810. alert('" . $error_files_exists . "');
  5811. return false;\n
  5812. }
  5813. }\n" .
  5814. // @see: function 'duplicate_file_ilm()' above
  5815. "
  5816. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5817. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5818. } // else
  5819. }
  5820. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5821. var filenamecopy;
  5822. var i;
  5823. var files = new Array($files_array);
  5824. do {
  5825. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5826. } while (filenamecopy == '');
  5827. if (filenamecopy == null)
  5828. return false;
  5829. else {
  5830. for (i=0;i<files.length;i++) {
  5831. if (files[i]==filenamecopy) {
  5832. alert('" . $error_files_exists . "');
  5833. return false;
  5834. }
  5835. }
  5836. 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;
  5837. }
  5838. }
  5839. function export_files_ilm () { //JavaScript function
  5840. var param = getCheckbox();
  5841. if (param.join() != '')
  5842. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5843. else
  5844. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5845. }
  5846. function select_all_ilm () { //JavaScript function
  5847. var checkBoxes = document.getElementsByTagName('input');
  5848. var selectAll = document.getElementById('select_all');
  5849. for (var counter=0; counter < checkBoxes.length; counter++) {
  5850. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5851. checkBoxes[counter].checked = selectAll.checked;
  5852. }
  5853. }
  5854. function getCheckbox () { //JavaScript function
  5855. var checkBoxes = document.getElementsByTagName('input');
  5856. var param = new Array();
  5857. for (var counter=0; counter < checkBoxes.length; counter++) {
  5858. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5859. param.push(checkBoxes[counter].value);
  5860. }
  5861. return param;
  5862. }
  5863. function new_dir_ilm () { //JavaScript function
  5864. var dirname = '';
  5865. var i;
  5866. var dirs = new Array(" . $dirs_array . ");
  5867. do {
  5868. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5869. } while (dirname == '');
  5870. if (dirname == null)
  5871. return false;\n
  5872. else {
  5873. for (i=0;i<dirs.length;i++) {
  5874. if (dirs[i]==dirname) {
  5875. alert('" . $error_dir_exists . "');
  5876. return false;\n
  5877. }
  5878. }
  5879. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5880. }
  5881. }
  5882. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5883. var msgAnswer;
  5884. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5885. if (msgAnswer) {
  5886. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5887. }
  5888. }
  5889. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5890. var dirnamecopy;
  5891. var i;
  5892. var dirs = new Array($dirs_array);
  5893. do {
  5894. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5895. } while (dirnamecopy == '');
  5896. if (dirnamecopy == null)
  5897. return false;\n
  5898. else {
  5899. for (i=0;i<dirs.length;i++) {
  5900. if (dirs[i]==dirnamecopy) {
  5901. alert('" . $error_dir_exists . "');
  5902. return false;\n
  5903. }
  5904. }
  5905. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5906. }
  5907. }
  5908. function move_selected_ilm (ilmid) { //JavaScript function
  5909. var param = getCheckbox();
  5910. if (param.join() != '')
  5911. 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();
  5912. else
  5913. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5914. }
  5915. function recover_files_ilm () { //JavaScript function
  5916. var msgAnswer;
  5917. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5918. if (msgAnswer) {
  5919. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5920. }
  5921. }
  5922. window.onload = function() { //JavaScript function
  5923. var xPosition = 0;
  5924. var yPosition = 0;
  5925. element=document.getElementById('new_file');
  5926. while(element) {
  5927. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5928. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5929. element = element.offsetParent;
  5930. }
  5931. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5932. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5933. location.hash = '#new_file';
  5934. };
  5935. //]]>
  5936. </script>\n"; // end of $code_javascript_ilm
  5937. return $code_javascript_ilm;
  5938. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5939. /// List iassign files from course directory
  5940. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5941. function view_files_ilm ($iassign_ilm_class, $extension) {
  5942. global $CFG, $DB, $USER, $OUTPUT;
  5943. $fs = get_file_storage();
  5944. $context = context_course::instance($this->id);
  5945. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5946. $dirid = $this->get_dir_ilm('dirid');
  5947. $dir_base = $this->get_dir_ilm('dir_base');
  5948. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5949. $files_array = '';
  5950. foreach ($files_course as $value) {
  5951. if (!$value->is_directory())
  5952. $files_array .= "'" . $value->get_filename() . "',";
  5953. }
  5954. $files_array .= "''";
  5955. $error_files_exists = get_string('error_file_exists', 'iassign');
  5956. $dirs_array = '';
  5957. foreach ($files_course as $value) {
  5958. if ($value->is_directory()) {
  5959. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5960. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5961. }
  5962. }
  5963. $dirs_array .= "''";
  5964. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5965. // TODO Rever o preview pois só deixar ver uma vez.
  5966. $code_javascript_ilm = "
  5967. <script type='text/javascript'>
  5968. //<![CDATA[
  5969. function preview_ilm (fileid, ilmid) {
  5970. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5971. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5972. }
  5973. function update_ilm (ilmid, fileid) {
  5974. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5975. }
  5976. function delete_ilm (ilmid, fileid) {
  5977. var msgAnswer;
  5978. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5979. if (msgAnswer) {
  5980. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5981. }
  5982. }
  5983. function delete_selected_ilm () {
  5984. var msgAnswer;
  5985. var param = getCheckbox();
  5986. if (param.join() != '') {
  5987. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5988. if (msgAnswer)
  5989. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5990. }
  5991. else
  5992. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5993. }
  5994. function add_ilm_iassign (ilmid, filename, fileid) {
  5995. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5996. }
  5997. function duplicate_ilm (ilmid, filename, fileid) {
  5998. var filenamecopy;
  5999. var i;
  6000. var files = new Array($files_array);
  6001. do {
  6002. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6003. } while (filenamecopy == '');
  6004. if (filenamecopy == null)
  6005. return false;\n
  6006. else {
  6007. for (i=0;i<files.length;i++) {
  6008. if (files[i]==filenamecopy) {
  6009. alert('$error_files_exists');
  6010. return false;\n
  6011. }
  6012. }\n" .
  6013. // @see: function 'duplicate_file_ilm()' above
  6014. "
  6015. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6016. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6017. } // else
  6018. }
  6019. function rename_ilm (ilmid, filename, fileid) {
  6020. var filenamecopy;
  6021. var i;
  6022. var files = new Array($files_array);
  6023. do {
  6024. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6025. } while (filenamecopy == '');
  6026. if (filenamecopy == null)
  6027. return false;
  6028. else {
  6029. for (i=0;i<files.length;i++) {
  6030. if (files[i]==filenamecopy) {
  6031. alert('$error_files_exists');
  6032. return false;
  6033. }
  6034. }
  6035. 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;
  6036. }
  6037. }
  6038. function export_files_ilm () {
  6039. var param = getCheckbox();
  6040. if (param.join() != '')
  6041. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6042. else
  6043. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6044. }
  6045. function select_all_ilm () {
  6046. var checkBoxes = document.getElementsByTagName('input');
  6047. var selectAll = document.getElementById('select_all');
  6048. for (var counter=0; counter < checkBoxes.length; counter++) {
  6049. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6050. checkBoxes[counter].checked = selectAll.checked;
  6051. }
  6052. }
  6053. function getCheckbox () {
  6054. var checkBoxes = document.getElementsByTagName('input');
  6055. var param = new Array();
  6056. for (var counter=0; counter < checkBoxes.length; counter++) {
  6057. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6058. param.push(checkBoxes[counter].value);
  6059. }
  6060. return param;
  6061. }
  6062. function new_dir_ilm () {
  6063. var dirname = '';
  6064. var i;
  6065. var dirs = new Array($dirs_array);
  6066. do {
  6067. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6068. } while (dirname == '');
  6069. if (dirname == null)
  6070. return false;\n
  6071. else {
  6072. for (i=0;i<dirs.length;i++) {
  6073. if (dirs[i]==dirname) {
  6074. alert('$error_dir_exists');
  6075. return false;\n
  6076. }
  6077. }
  6078. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6079. }
  6080. }
  6081. function delete_dir_ilm (ilmid, dirid) {
  6082. var msgAnswer;
  6083. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6084. if (msgAnswer) {
  6085. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6086. }
  6087. }
  6088. function rename_dir_ilm (ilmid, dirname, dirid) {
  6089. var dirnamecopy;
  6090. var i;
  6091. var dirs = new Array($dirs_array);
  6092. do {
  6093. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6094. } while (dirnamecopy == '');
  6095. if (dirnamecopy == null)
  6096. return false;\n
  6097. else {
  6098. for (i=0;i<dirs.length;i++) {
  6099. if (dirs[i]==dirnamecopy) {
  6100. alert('$error_dir_exists');
  6101. return false;\n
  6102. }
  6103. }
  6104. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6105. }
  6106. }
  6107. function move_selected_ilm (ilmid) {
  6108. var param = getCheckbox();
  6109. if (param.join() != '')
  6110. 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();
  6111. else
  6112. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6113. }
  6114. function recover_files_ilm () {
  6115. var msgAnswer;
  6116. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6117. if (msgAnswer) {
  6118. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6119. }
  6120. }
  6121. window.onload = function() {
  6122. var xPosition = 0;
  6123. var yPosition = 0;
  6124. element=document.getElementById('new_file');
  6125. while(element) {
  6126. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6127. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6128. element = element.offsetParent;
  6129. }
  6130. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6131. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6132. location.hash = '#new_file';
  6133. };
  6134. //]]>
  6135. </script>\n";
  6136. $output = "";
  6137. $select_all = "";
  6138. $count_files = 0;
  6139. $extensions_allow = array();
  6140. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6141. foreach ($iassign_ilm as $item_iassign_ilm)
  6142. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6143. foreach ($files_course as $value) {
  6144. $filename = $value->get_filename();
  6145. $filepath = $value->get_filepath();
  6146. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6147. $pathname = $pathname[count($pathname) - 1];
  6148. $fileid = $value->get_id();
  6149. $tmp = explode(".", $filename);
  6150. if (count($tmp)>1) // avoid error if the file has no extension
  6151. $filetype = $tmp[1];
  6152. else // probably error...
  6153. $filetype = '';
  6154. $author = $value->get_author();
  6155. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6156. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6157. $extensions = explode(",", $extension);
  6158. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6159. $count_files ++;
  6160. // buscar fileid nas tabelas do iassign
  6161. $list_filein_use = "";
  6162. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6163. if ($iassign_statement_activity_list) {
  6164. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6165. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6166. }
  6167. }
  6168. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6169. if (!$iassign_ilm) {
  6170. $iassign_ilm = new stdClass();
  6171. $iassign_ilm->id = $ilmid;
  6172. }
  6173. // Do not use $var inside "..." - problem with some "unusual" operational system
  6174. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6175. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6176. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6177. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6178. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6179. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6180. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6181. $check_select = "";
  6182. $link_rename = "";
  6183. $link_delete = "";
  6184. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6185. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6186. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6187. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6188. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6189. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6190. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6191. if ($value->get_userid() == $USER->id) {
  6192. if ($iassign_statement_activity_list) {
  6193. $check_select = "";
  6194. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6195. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6196. $link_rename = "";
  6197. } else {
  6198. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6199. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6200. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6201. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6202. }
  6203. }
  6204. if (!in_array($filetype, $extensions_allow)) {
  6205. $link_edit = "";
  6206. $link_add_ilm_iassign = "";
  6207. $link_add_ilm_tinymce = "";
  6208. $link_add_ilm_atto = "";
  6209. $link_filter = "";
  6210. }
  6211. if ($value->is_directory()) {
  6212. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6213. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6214. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6215. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6216. <td><center>$author</center></td>
  6217. <td><center>$timecreated</center></td>
  6218. <td><center>$timemodified</center></td></tr>\n";
  6219. }
  6220. else if ($this->from == 'iassign') {
  6221. $new_id = "";
  6222. $new_class = "";
  6223. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6224. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6225. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6226. }
  6227. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6228. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6229. <td><center>$author</center></td>
  6230. <td><center>$timecreated</center></td>
  6231. <td><center>$timemodified</center></td></tr>\n";
  6232. }
  6233. else if ($this->from == 'block') {
  6234. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6235. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6236. <td><center>$author</center></td>
  6237. <td><center>$timecreated</center></td>
  6238. <td><center>$timemodified</center></td></tr>\n";
  6239. }
  6240. else if ($this->from == 'tinymce') {
  6241. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6242. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6243. <td><center>$author</center></td>
  6244. <td><center>$timecreated</center></td>
  6245. <td><center>$timemodified</center></td></tr>\n";
  6246. }
  6247. else if ($this->from == 'atto') {
  6248. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6249. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6250. <td><center>$author</center></td>
  6251. <td><center>$timecreated</center></td>
  6252. <td><center>$timemodified</center></td></tr>\n";
  6253. }
  6254. }
  6255. }
  6256. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6257. $dir_base = "";
  6258. $header = "";
  6259. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6260. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6261. foreach ($basename as $value) {
  6262. $dir_base .= $value . "/";
  6263. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6264. if ($dir_id) {
  6265. if ($value == "") {
  6266. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6267. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6268. } else {
  6269. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6270. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6271. }
  6272. }
  6273. } // foreach ($basename as $value)
  6274. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6275. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6276. $html .= "
  6277. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6278. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6279. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6280. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6281. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6282. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6283. </table>\n";
  6284. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6285. $html .= "<table width='100%'><tr>\n";
  6286. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6287. if ($count_files != 0) {
  6288. $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";
  6289. $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";
  6290. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6291. }
  6292. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6293. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6294. $html .= "</form>\n";
  6295. print $code_javascript_ilm;
  6296. print $html;
  6297. } // function view_files_ilm($extension)
  6298. } // class ilm_manager
  6299. /// Class to insert of icons
  6300. class iassign_icons {
  6301. static function insert ($icon) {
  6302. global $CFG;
  6303. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6304. return $string;
  6305. }
  6306. }
  6307. /// Class with util functions for plugin manage
  6308. class iassign_utils {
  6309. /// Function to return the filename extension
  6310. // @param string The $filename as an string
  6311. // @return string Return an string (last group after '.')
  6312. static function filename_extension ($filename) {
  6313. if ($filename == null || $filename == '') {
  6314. return null;
  6315. }
  6316. $itens = explode('.', $filename);
  6317. $num = count($itens);
  6318. if ($num < 2) {
  6319. return null;
  6320. }
  6321. return $itens[$num - 1];
  6322. }
  6323. /// Use the PHP class/package ZipArchive to create a Zip file
  6324. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6325. // 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
  6326. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6327. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6328. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6329. $zip = new zip_archive(); //2
  6330. $res = $zip->open($full_path_zip_filename);
  6331. $total_vet = count($vet_student_filename);
  6332. for ($ii=0; $ii<$total_vet; $ii++) {
  6333. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6334. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6335. }
  6336. $ret = $zip->close();
  6337. iassign_utils::download_file($full_path_zip_filename);
  6338. $filenameZip = $zip->filename;
  6339. return array($ret, $zip);
  6340. }
  6341. static function download_file ($zip_filename) {
  6342. header("Pragma: public");
  6343. header("Expires: 0");
  6344. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6345. header("Cache-Control: private", false);
  6346. header("Content-Type: application/zip");
  6347. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6348. header("Content-Transfer-Encoding: binary");
  6349. header("Content-Length: " . @filesize($zip_filename));
  6350. set_time_limit(0);
  6351. @readfile("$zip_filename") || die("File not found.");
  6352. unlink($zip_filename);
  6353. }
  6354. /// Function for format filename remove special caracters
  6355. // @param string $text String for clean
  6356. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6357. // @return string Return an string in clean format
  6358. static function format_filename ($text) {
  6359. if ($text != '.') {
  6360. //D $text = htmlspecialchars(urldecode($text));
  6361. //D echo "locallib.php: format_filename: $text<br/>";
  6362. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6363. $text = json_decode($text)->{current_language()};
  6364. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6365. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6366. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6367. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6368. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6369. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6370. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6371. // E.g. text = "exerc_midpoint.course.geo"
  6372. // 0123456789012345678901234
  6373. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6374. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6375. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6376. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6377. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6378. //$ext = strrpos($text, ".");
  6379. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6380. //$text = str_replace($array1, $array2, $text);
  6381. }
  6382. return $text;
  6383. }
  6384. /// Function to filter characters to the file name to iLM content
  6385. // @param string $text String for clean
  6386. // @param string $ext String ot the extension of the iLM
  6387. // @return string Return an string in clean format
  6388. static function filter_filename_extension ($filename, $ext) {
  6389. if ($filename != '.') {
  6390. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6391. $arrTo = array("_","","","","","","","","","","","","");
  6392. $filename = str_replace($arrFrom, $arrTo, $filename);
  6393. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6394. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6395. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6396. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6397. $index_lastposition = strlen($filenameF);
  6398. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6399. $text = str_replace(".", "_", $text); // erase all other "."
  6400. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6401. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6402. }
  6403. else
  6404. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6405. return $filenameF;
  6406. }
  6407. /// Function for format pathname remove special caracters
  6408. // @param string $text String for clean
  6409. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6410. // @return string Return an string in clean format
  6411. static function format_pathname ($text, $is_lowercase = true) {
  6412. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6413. $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", "-", "_", "", "", "");
  6414. $text = str_replace($array1, $array2, $text);
  6415. if ($is_lowercase)
  6416. $text = strtolower($text);
  6417. return $text;
  6418. }
  6419. /// Function for format file name from iLM original name
  6420. // @param string $text String to build the file neam
  6421. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6422. // @return string Return an string in clean format
  6423. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6424. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6425. $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", "-", "_", "", "", "");
  6426. $index_firstposition_blank = strpos($ilm_name, " ");
  6427. if ($index_firstposition_blank) { // truncate the name!
  6428. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6429. }
  6430. $index_firstposition_dots = strpos($ilm_name, ":");
  6431. if ($index_firstposition_dots) { // truncate the name!
  6432. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6433. }
  6434. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6435. if ($is_lowercase)
  6436. $namefiltered = strtolower($namefiltered);
  6437. return $namefiltered;
  6438. }
  6439. /// Function for insert version in the filename
  6440. // @param string $filename Name of file
  6441. // @return string Return the filename with version
  6442. static function version_filename ($filename) {
  6443. $array_filename = explode('.', $filename);
  6444. if (count($array_filename) > 1)
  6445. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6446. else
  6447. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6448. return $filename;
  6449. }
  6450. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6451. static function remove_code_message ($string) {
  6452. $array = explode("&lt;ia_uc&gt;", $string);
  6453. return $array[0];
  6454. }
  6455. }
  6456. // class iassign_utils
  6457. /// Class with language functions for plugin manage
  6458. class iassign_language {
  6459. /// Function for return text in language or get default language (en)
  6460. // @param string $lang Code of language
  6461. // @param string $description JSON text content all languages
  6462. // @return string Return an string in the language selected
  6463. static function get_description_lang ($lang, $descriptions) {
  6464. $description_lang = "";
  6465. $description = json_decode($descriptions);
  6466. if ($description == null) {
  6467. $description_lang = $descriptions;
  6468. }
  6469. else {
  6470. if (isset($description->{$lang}))
  6471. $description_lang = $description->{$lang};
  6472. else
  6473. if (isset($description->en)) //MOOC2014
  6474. $description_lang = $description->en;
  6475. else //MOOC2014
  6476. $description_lang = "en"; //MOOC2014
  6477. }
  6478. return $description_lang;
  6479. }
  6480. /// Function for return all language supported by iLM
  6481. // @param string $descriptions JSON text content all languages
  6482. // @return string Return as string with all languages
  6483. static function get_all_lang ($descriptions) {
  6484. $langs = "";
  6485. $description = json_decode($descriptions);
  6486. if ($description) {
  6487. foreach ($description as $key => $value) {
  6488. $langs .= $key . " ; ";
  6489. }
  6490. $langs = substr($langs, 0, strlen($langs) - 3);
  6491. }
  6492. return $langs;
  6493. }
  6494. /// Function for convert json in xml //MOOC2014
  6495. // @param string $json JSON text
  6496. // @return string Return as string with xml tags
  6497. static function json_to_xml ($json) {
  6498. $xml = "";
  6499. $json = json_decode($json);
  6500. foreach ($json as $key => $value) {
  6501. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6502. }
  6503. return $xml;
  6504. }
  6505. }
  6506. // class iassign_language
  6507. /// Class with log functions for plugin manage.
  6508. class iassign_log {
  6509. /// Function for insert log event
  6510. // @param string $action Code action of event
  6511. // @param string $information Text for describe action of event
  6512. // @param int $cmid Id of context module
  6513. // @param int $ilmid Id of iLM
  6514. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6515. global $COURSE, $CFG, $USER, $DB;
  6516. $newentry = new stdClass();
  6517. $newentry->time = time();
  6518. $newentry->userid = $USER->id;
  6519. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6520. $newentry->course = $COURSE->id;
  6521. $newentry->cmid = $cmid;
  6522. $newentry->ilmid = $ilmid;
  6523. $newentry->action = $action;
  6524. $newentry->info = $information;
  6525. $newentry->language = current_language();
  6526. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6527. if (ini_get("browscap") && function_exists('get_browse')) {
  6528. $browser = get_browse(null, true);
  6529. $newentry->javascript = $browser['javascript'];
  6530. $newentry->java = $browser['javaapplets'];
  6531. }
  6532. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6533. print_error('error_add_log', 'iassign');
  6534. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6535. } // class iassign_log