locallib.php 425 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.5 2021/12/28
  7. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  8. *
  9. * - v 4.9.4 2020/05/28
  10. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  11. *
  12. * - v 4.9.3 2020/01/16
  13. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  14. *
  15. * - v 4.9.2 2019/03/13
  16. * + Several fixes to allow iLM under HTML stack
  17. *
  18. * - v 4.9.1 2017/11/02
  19. * + 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")
  20. * + 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)'
  21. *
  22. * - v 4.9 2017/03/13
  23. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  24. *
  25. * - v 4.8 2016/05/12
  26. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  27. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  28. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  29. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  30. * replaced by
  31. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  32. * - v 4.7 2016/02/17
  33. * + 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(...)')
  34. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  35. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  36. * + 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)
  37. * + 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'
  38. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  39. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  40. *
  41. * --------------- (code bellow was used at our MOOC 2014)
  42. * - v 4.6 2014/02/25
  43. * + Fix bugs in filter function for open applets.
  44. * - v 4.5 2014/02/24
  45. * + Fix bugs in params.
  46. * + Insert new param type.
  47. * - v 4.4 2014/01/24
  48. * + Allow select type of params.
  49. * + Insert the use of applet params specific for activities.
  50. * - v 4.3 2014/01/23
  51. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  52. * - v 4.2 2016/02/13
  53. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  54. * --------------- (above code used at our MOOC 2014)
  55. *
  56. * - v 4.1 2013/12/13
  57. * + Insert log in iAssign actions.
  58. * + 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).
  59. * + Insert class for Log actions in system.
  60. * - v 4.0 2013/10/31
  61. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  62. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  63. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  64. * - v 3.9 2013/10/25
  65. * + Insert support of upgrade iLM.
  66. * + Insert support for more than one extension in iLM.
  67. * + Fix bugs in verion control.
  68. * - v 3.8 2013/09/19
  69. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  70. * - v 3.7 2013/09/12
  71. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  72. * + 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).
  73. * - v 3.6 2013/09/05
  74. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  75. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  76. * + Change tag APPLET in function ilm_settings::view_ilm.
  77. * - v 3.5 2013/08/26
  78. * + Fix bug in download package iassign without answers (iassign::report).
  79. * - v 3.4 2013/08/23
  80. * + Fix bug in export package iassign.
  81. * - v 3.3 2013/08/22
  82. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  83. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  84. * - v 3.2 2013/08/21
  85. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  86. * + Change functions for import files for ilm_manager.php.
  87. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  88. * - v 3.1 2013/08/15
  89. * + Change return file selected (ilm_manager::add_ilm).
  90. * + 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).
  91. * - v 3.0 2013/08/02
  92. * + 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).
  93. * - v 2.9 2013/08/01
  94. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  95. * - v 2.8 2013/07/25
  96. * + Insert the activity name in header of view (activity::view_dates).
  97. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  98. * - v 2.7 2013/07/24
  99. * + Create link previous and next for student view in one activity (activity::view_dates).
  100. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  101. * - v 2.6 2013/07/23
  102. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  103. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  104. * - v 2.5 2013/07/12
  105. * + 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).
  106. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  107. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  108. *
  109. * @author Patricia Alves Rodrigues
  110. * @author Leônidas O. Brandão
  111. * @contributor Igor Moreira Félix (2018-)
  112. * @contributor Márcio de Lima Passos (2014)
  113. * @version v 4.9.2 2019/03/13
  114. * @version v 4.8 2016/05/12
  115. * @package mod_iassign_lib
  116. * @since 2010/09/27
  117. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  118. *
  119. * <b>License</b>
  120. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  121. */
  122. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  123. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  124. //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"'
  125. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  126. /**
  127. * Standard base class for all iAssign
  128. */
  129. class iassign {
  130. var $cm;
  131. var $course;
  132. var $iassign;
  133. var $striassign;
  134. var $striassigns;
  135. var $context;
  136. var $activity;
  137. var $iassign_up;
  138. var $iassign_down;
  139. var $action;
  140. var $iassign_submission_current;
  141. var $userid_iassign;
  142. var $bottonPost;
  143. var $write_solution;
  144. var $view_iassign;
  145. // 3.1 update PHP 7.0 compatibility for all moodle versions
  146. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  147. /// Constructor for the base iassign class
  148. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  149. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  150. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  151. function __construct ($iassign, $cm, $course) {
  152. global $COURSE, $CFG, $USER, $DB;
  153. $botton = optional_param('botton', NULL, PARAM_TEXT);
  154. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  155. if (!is_null($botton))
  156. $USER->iassignEdit = $botton;
  157. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  158. // 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'
  159. $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"
  160. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  161. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  162. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  163. $this->action = optional_param('action', NULL, PARAM_TEXT);
  164. $this->cm = $cm;
  165. $this->context = context_module::instance($this->cm->id);
  166. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  167. $this->userid_iassign = $USER->id;
  168. if ($course) {
  169. $this->course = $course;
  170. }
  171. else if ($this->cm->course == $COURSE->id) {
  172. $this->course = $COURSE;
  173. }
  174. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  175. print_error('invalidid', 'iassign');
  176. }
  177. $this->coursecontext = context_course::instance($this->course->id);
  178. if ($iassign) {
  179. $this->iassign = $iassign;
  180. }
  181. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  182. print_error('invalidid', 'iassign');
  183. }
  184. $USER->context = context_module::instance($this->cm->id);
  185. $USER->cm = $this->cm->id;
  186. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  187. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  188. $this->context = context_module::instance($this->cm->id);
  189. $this->striassign = get_string('modulename', 'iassign');
  190. $this->striassigns = get_string('modulenameplural', 'iassign');
  191. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  192. $this->bottonPost = 0;
  193. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  194. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  195. $this->view();
  196. } // function __construct($iassign, $cm, $course)
  197. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  198. // This method provides the page to view each iLM with any interactive activity
  199. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  200. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  201. global $USER, $DB, $OUTPUT;
  202. // $iassign_statementid = $this->iassign->iassign_statementid;
  203. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  204. $iassign_statementid = $this->activity->get_activity()->id;
  205. else
  206. $iassign_statementid = "";
  207. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  208. // If this user has no capability to View 'iassign': stop here
  209. require_capability('mod/iassign:view', $this->context);
  210. // Trigger module view event
  211. $event = \mod_iassign\event\course_module_viewed::create(array(
  212. 'objectid' => $this->iassign->id,
  213. 'context' => $this->context
  214. ));
  215. $event->add_record_snapshot('course', $this->course);
  216. $event->trigger();
  217. if ($this->action) { // when student do/redo activity or teacher see student solution
  218. $this->action(); // calls '$this->view_iLM();'
  219. }
  220. else {
  221. print $OUTPUT->header();
  222. $this->view_iassigns(); // show the iLM with the content
  223. print $OUTPUT->footer();
  224. }
  225. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  226. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //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" }
  229. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  230. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  231. //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" }
  232. //D else echo "Apagou!<br/>";
  233. die();
  234. } // function view()
  235. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  236. function action () {
  237. global $USER;
  238. // action:
  239. // up - move up activity (mover atividade para cima)
  240. // down - move down activity (mover atividade para baixo)
  241. // visible - view/hide activity (exibir/ocultar atividade)
  242. // delete - delete activity (excluir atividade)
  243. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  244. // deleteno - does not erase activity (não apaga atividade)
  245. // add - add activity (adicionar atividade)
  246. // edit - edit activity (modificar atividade)
  247. $action_iassign = array(
  248. 'newcomment' => '$this->add_comment();',
  249. 'view' => '$this->view_iassign_current();',
  250. 'get_answer' => '$this->get_answer();',
  251. 'repeat' => '$this->view_iassign_current();',
  252. 'overwrite' => '$this->get_answer();',
  253. 'stats_student' => '$this->stats_students();',
  254. 'download_answer' => '$this->export_file_answer();',
  255. 'download_all_answer' => '$this->export_package_answer();',
  256. 'notifications' => '$this->view_notifications();');
  257. $action_iassign_limit = array(
  258. 'view' => '$this->view_iassign_current();',
  259. //'newcomment' => '$this->get_answer();',
  260. 'viewsubmission' => '$this->view_iassign_current();',
  261. 'edit_status' => '$this->edit_status();',
  262. 'edit_grade' => '$this->edit_grade();',
  263. 'export_csv' => '$this->export_csv();',
  264. 'report' => '$this->report();',
  265. 'print' => '$this->report();',
  266. 'stats' => '$this->stats();',
  267. 'printstats' => '$this->stats();');
  268. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  269. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  270. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  271. 'visible' => '$this->activity->visible_iassign($this->return);',
  272. 'delete' => '$this->activity->delete($this->return);',
  273. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  274. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  275. 'add' => '$this->add_edit_iassign();',
  276. 'edit' => '$this->add_edit_iassign();',
  277. 'get_answer' => '$this->get_answer();',
  278. 'duplicate_activity' => '$this->duplicate_activity();',
  279. 'move_activity' => '$this->move_activity();',
  280. 'auto_evaluate' => '$this->auto_evaluate();',
  281. 'all_submissions' => '$this->all_submissions();',
  282. 'delete_submissions' => '$this->delete_submissions();',
  283. 'download_submissions' => '$this->download_submissions();',
  284. 'open_individual_submission' => '$this->open_individual_submission();',
  285. 'get_individual_submission' => '$this->get_individual_submission();',
  286. 'get_student_submission' => '$this->get_student_submission();',
  287. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  288. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  289. 'import_activity' => '$this->import_activity();',
  290. 'import_activity_confirm' => '$this->import_activity_confirm();'
  291. );
  292. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  293. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  294. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  295. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  296. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  297. }
  298. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  299. eval($action_iassign_limit[$this->action]);
  300. }
  301. else { // Student reaches this point
  302. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  303. // Arrive here with: "get_answer"; "view"
  304. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  305. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  306. }
  307. } // function action()
  308. /// This method prints the student submission to a specific exercise
  309. function get_student_submission () {
  310. global $DB;
  311. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  312. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  313. if (!$student || !$exercise) exit;
  314. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  315. if ($iassign_submission)
  316. print($iassign_submission->answer);
  317. die();
  318. }
  319. /// This method prints the teacher exercise
  320. function get_teacher_exercise () {
  321. global $DB, $COURSE;
  322. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  323. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  324. $fs = get_file_storage(); // Get reference to all files in Moodle data
  325. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  326. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  327. foreach ($files as $file) {
  328. if ($file->get_filename() != ".") {
  329. print($file->get_content());
  330. }
  331. }
  332. die();
  333. }
  334. /// This method receives the data from auto_eval event
  335. /// @see auto_evaluate()
  336. function post_auto_eval_result () {
  337. global $COURSE, $CFG, $USER, $DB;
  338. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  339. exit;
  340. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  341. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  342. $student = optional_param('student', -1, PARAM_INT);
  343. $grade = optional_param('grade', 0, PARAM_FLOAT);
  344. // 1: Recuperar a nota atual:
  345. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  346. // 2: Atualizar a tabela:
  347. $update_entry = new stdClass();
  348. $update_entry->id = $actual->id;
  349. $update_entry->previous_grade = $actual->grade;
  350. $update_entry->grade = $grade;
  351. // Update the iassign_submission
  352. $DB->update_record("iassign_submission", $update_entry);
  353. }
  354. /// Function to help download all_submissions files
  355. function download_submissions_help ($list) {
  356. global $DB, $CFG, $OUTPUT;
  357. // Get list of iLMs
  358. $ilm_list = $DB->get_records("iassign_ilm");
  359. // Get list of enrolled students:
  360. $params_temp = array('shortname' => 'student');
  361. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  362. $context = context_course::instance($this->course->id);
  363. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  364. $students_list = $DB->get_records_sql(
  365. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  366. $json_obj = new stdclass();
  367. $json_obj->submissions = [];
  368. $csvfields = [];
  369. $csvfields[] = 'submissionid';
  370. $csvfields[] = 'file';
  371. $csvfields[] = 'filesize';
  372. $csvfields[] = 'timestamp';
  373. $csvfields[] = 'humandate';
  374. $csvfields[] = 'grade';
  375. $csvfields[] = 'userid';
  376. $csvfields[] = 'exerciseid';
  377. $json_obj->submissions[] = $csvfields;
  378. $exercise_dir = [];
  379. $exercises_list = [];
  380. foreach ($list as $item) {
  381. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  382. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  383. $exercises_list[] = $temp;
  384. $exercise_dir[] = $temp->id;
  385. }
  386. }
  387. $student_dir = [];
  388. $students_list = [];
  389. foreach ($list as $item) {
  390. if (!in_array($item->userid, $student_dir)) {
  391. $temp = $DB->get_record("user", array("id" => $item->userid));
  392. $students_list[] = $temp;
  393. $student_dir[] = $temp->id;
  394. }
  395. }
  396. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  397. //TODO: tem que criar moodledata/temp/iassign_files
  398. // Create $CFG->dataroot/temp/iassign_files
  399. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  400. if (!file_exists($tempfilespath)) {
  401. mkdir($tempfilespath, 0777, true);
  402. }
  403. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  404. if (!file_exists($iassignfilespath)) {
  405. mkdir($iassignfilespath, 0777, true);
  406. }
  407. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  408. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  409. if (!file_exists($diretorio)) {
  410. echo 'Não foi possível criar o diretório para preparar o arquivo com as submissões. Possivelmente o caminho está bloqueado para escrita.';
  411. exit;
  412. }
  413. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  414. $zip = new zip_archive(); // create ZIP
  415. if (!$zip->open($zip_filename)) {
  416. echo 'Não foi possível criar o arquivo zip com as submissões dos alunos, pois o diretório no servidor está bloqueado para escrita: ' . $diretorio;
  417. exit;
  418. }
  419. ;
  420. foreach ($exercises_list as $exercise) {
  421. $dir_ex = iassign_utils::format_filename($exercise->name);
  422. $zip->add_directory($dir_ex);
  423. $extension_ilm = '';
  424. foreach ($ilm_list as $ilm) {
  425. if ($exercise->iassign_ilmid == $ilm->id) {
  426. $extension_ilm = $ilm->extension;
  427. break;
  428. }
  429. }
  430. foreach ($students_list as $student) {
  431. $individual_dir =
  432. $dir_ex . DIRECTORY_SEPARATOR .
  433. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  434. $zip->add_directory($individual_dir);
  435. $i = 1;
  436. foreach($list as $item) {
  437. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  438. $date = new DateTime();
  439. $date->setTimestamp($item->timecreated);
  440. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  441. $zip->add_file_from_string($new_file, $item->answer);
  442. $temp_json = [];
  443. $temp_json[] = intval($item->id);
  444. $temp_json[] = $new_file;
  445. $temp_json[] = strlen($new_file);
  446. $temp_json[] = intval($item->timecreated);
  447. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  448. $temp_json[] = doubleval($item->grade);
  449. $temp_json[] = intval($item->userid);
  450. $temp_json[] = intval($exercise->id);
  451. $json_obj->submissions[] = $temp_json;
  452. }
  453. }
  454. }
  455. }
  456. $csv_str = "";
  457. foreach($json_obj->submissions as $sub) {
  458. $csv_str .= $this->csvstr($sub) . "\n";
  459. }
  460. $zip->add_file_from_string('index.csv', $csv_str);
  461. $zip->close();
  462. iassign_utils::download_file($zip_filename);
  463. exit;
  464. }
  465. function csvstr(array $fields) : string {
  466. $f = fopen('php://memory', 'r+');
  467. if (fputcsv($f, $fields) === false) {
  468. return false;
  469. }
  470. rewind($f);
  471. $csv_line = stream_get_contents($f);
  472. return rtrim($csv_line);
  473. }
  474. /// Download submissions from table iassign_allsubmissions
  475. function download_submissions () {
  476. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  477. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  478. exit;
  479. $type = optional_param('type', NULL, PARAM_TEXT);
  480. $item = optional_param('item', NULL, PARAM_TEXT);
  481. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  482. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  483. $sub_list = [];
  484. if ($type == 'individual') {
  485. $sub_list[] = $DB->get_record(
  486. 'iassign_allsubmissions', array('id' => $item));
  487. } elseif ($type == 'student') {
  488. $sub_list = $DB->get_records(
  489. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  490. } elseif ($type == 'exercise') {
  491. $sub_list = $DB->get_records(
  492. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  493. } elseif ($type == 'block') {
  494. $exercises_in_block = $DB->get_records(
  495. 'iassign_statement', array('iassignid' => $iassign_id));
  496. foreach ($exercises_in_block as $exercise) {
  497. $temp = $DB->get_records(
  498. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  499. $sub_list = array_merge($sub_list, $temp);
  500. }
  501. }
  502. $this->download_submissions_help($sub_list);
  503. }
  504. /// Delete submissions in table iassign_allsubmissions
  505. function delete_submissions () {
  506. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  507. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  508. exit;
  509. $type = optional_param('type', NULL, PARAM_TEXT);
  510. $item = optional_param('item', NULL, PARAM_TEXT);
  511. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  512. if ($type == 'individual') {
  513. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  514. } elseif ($type == 'student') {
  515. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  516. } elseif ($type == 'exercise') {
  517. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  518. }
  519. }
  520. function get_individual_submission () {
  521. global $DB, $USER;
  522. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  523. exit;
  524. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  525. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  526. print $submission->answer;
  527. }
  528. /// Open individual submission
  529. function open_individual_submission () {
  530. global $DB, $USER, $CFG;
  531. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  532. exit;
  533. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  534. $id = $this->cm->id;
  535. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  536. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  537. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  538. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  539. $all_submissions = $DB->get_records('iassign_allsubmissions',
  540. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  541. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  542. $previous = null;
  543. $next = null;
  544. $i = 0;
  545. $found = false;
  546. foreach($all_submissions as $individual) {
  547. if (!$found && $individual->id != $submissionid) {
  548. $previous = $individual;
  549. }
  550. if ($found) {
  551. $next = $individual;
  552. break;
  553. }
  554. if ($individual->id === $submissionid) {
  555. $found = true;
  556. }
  557. $i++;
  558. }
  559. print '<center>';
  560. print '<table cellpading=5 cellspacing=5 style="padding-bottom: 2rem;font-size: 1.1em;"><tr><td>' . get_string('exercise', 'iassign') . ':</td><td>' . $atual_statement->name . '</td></tr>';
  561. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>';
  562. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>';
  563. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>';
  564. print '</table>';
  565. if ($previous) {
  566. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  567. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  568. } else {
  569. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  570. }
  571. print ' (' . $i . '/' . count($all_submissions) . ')';
  572. if ($next) {
  573. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  574. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  575. } else {
  576. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  577. }
  578. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  579. //array("type" => "editor_new", "notSEND" => "true")
  580. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  581. print '</center>';
  582. } // function open_individual_submission()
  583. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  584. function import_activity_confirm () {
  585. global $USER, $DB;
  586. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  587. exit;
  588. if (!isset($_REQUEST['statements'])) exit;
  589. $iassign_destiny = $this->iassign->id;
  590. $activities_list = $_REQUEST['statements'];
  591. foreach($activities_list as $activity) {
  592. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  593. $activity_source->id = 0;
  594. $iassign_id_from = $activity_source->iassignid;
  595. $filesid_from = $activity_source->filesid;
  596. $activity_source->iassignid = $iassign_destiny;
  597. $author = $DB->get_record("user", array('id' => $USER->id));
  598. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  599. $activity_source->author_modified = $activity_source->author_modified_name;
  600. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  601. $fs = get_file_storage();
  602. // Duplicate activity file
  603. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  604. print 'Arquivos a serem copiados: ';
  605. print_r($files_ids);
  606. foreach ($files_ids as $fileid) {
  607. $source_file = $fs->get_file_by_id($fileid->id);
  608. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  609. $updateentry = new stdClass();
  610. $updateentry->id = $id_;
  611. $updateentry->filesid = $id_;
  612. // Update the duplicated iLM iAssign with new file id
  613. $DB->update_record("iassign_statement", $updateentry);
  614. }
  615. }
  616. }
  617. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  618. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  619. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  620. exit;
  621. }
  622. function import_activity () {
  623. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  624. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  625. exit;
  626. print '<script>
  627. function verify_selection () {
  628. document.getElementById("msg-error").classList.add("d-none");
  629. var checkboxes = document.getElementsByName("statements[]");
  630. for(var i = 0; i < checkboxes.length; i++)
  631. if (checkboxes[i].checked) return true;
  632. document.getElementById("msg-error").classList.remove("d-none");
  633. return false;
  634. }
  635. </script>';
  636. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  637. print $OUTPUT->header();
  638. $this->print_main_menu();
  639. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>';
  640. print '<form action="'.$destiny_url.'" method="post" onsubmit="return verify_selection()">';
  641. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  642. foreach ($courses_as_teacher as $course) {
  643. print '<a href="#item-'.$course->id.'" class="list-group-item list-group-item-action h5" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> ' . $course->fullname . ' </a>';
  644. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'">';
  645. $iassigns = $this->get_iassign_items_by_course($course->id);
  646. if ($iassigns) {
  647. foreach ($iassigns as $iassign) {
  648. print '<a href="#item-'.$course->id.'-'.$iassign->id.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'><i class="fa fa-caret-right"></i> '.$iassign->name.'</a>';
  649. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$course->id.'-'.$iassign->id.'">';
  650. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  651. print '<table class="table table-hover">';
  652. if ($statements) {
  653. foreach ($statements as $statement) {
  654. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="'.$statement->id.'" id="statement-' . $statement->id . '">';
  655. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  656. print '</label></div></td></tr>';
  657. }
  658. }
  659. else {
  660. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>';
  661. }
  662. print '</table></div>';
  663. }
  664. }
  665. else {
  666. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign').'</div>';
  667. }
  668. print '</div>';
  669. }
  670. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>';
  671. print '<div class="text-center text-danger d-none" id="msg-error">'.get_string('import_statement_no_exercise', 'iassign').'</div>';
  672. print "</form>\n";
  673. print $OUTPUT->footer();
  674. }
  675. function get_iassign_items_by_course ($courseid) {
  676. global $DB;
  677. return $DB->get_records("iassign", array("course" => $courseid));
  678. }
  679. function get_iassign_statement_by_iassign ($iassignid) {
  680. global $DB;
  681. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  682. }
  683. function get_courses_enroled_as_teacher($userid) {
  684. $all_enroled = enrol_get_users_courses($userid);
  685. $return = array();
  686. foreach ($all_enroled as $enroled) {
  687. $context_course = context_course::instance($enroled->id);
  688. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  689. array_push($return, $enroled);
  690. }
  691. }
  692. return $return;
  693. }
  694. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  695. /// Manage all submissions in exercises to table iassign_allsubmissions
  696. function all_submissions () {
  697. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  698. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  699. exit;
  700. print $OUTPUT->header();
  701. $this->print_main_menu();
  702. $id = $this->cm->id;
  703. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  704. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  705. print '
  706. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  707. <div class="modal-dialog modal-dialog-centered" role="document">
  708. <div class="modal-content">
  709. <div class="modal-header">
  710. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  711. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  712. <span aria-hidden="true">&times;</span>
  713. </button>
  714. </div>
  715. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  716. <div class="modal-footer">
  717. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  718. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  719. </div>
  720. </div>
  721. </div>
  722. </div>'; // "
  723. print '
  724. <script>
  725. var sub_type;
  726. var sub_item;
  727. var sub_el;
  728. var sub_exercise;
  729. function delete_submission (type, item, el, exercise = 0) {
  730. sub_type = type;
  731. sub_item = item;
  732. sub_exercise = exercise;
  733. sub_el = el.closest("tr");
  734. if (!sub_el) sub_el = el.closest("a");
  735. $("#modalConfirm").modal();
  736. }
  737. function confirm_delete () {
  738. var url = "'.$enderecoPOST.'&action=delete_submissions";
  739. var xhttp = new XMLHttpRequest();
  740. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  741. xhttp.send();
  742. $("#modalConfirm").modal("hide");
  743. if ($(sub_el).attr("href"))
  744. $($(sub_el).attr("href")).remove();
  745. if (sub_el) sub_el.remove();
  746. }
  747. function download_submission(type, item, exercise = 0, iassign = 0) {
  748. var url = "'.$enderecoPOST.'&action=download_submissions";
  749. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  750. document.location = url;
  751. }
  752. function open_submission(item) {
  753. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  754. var poupup = window.open(url, "popup", "width=900,height=900");
  755. }
  756. </script>' . chr(13); // '
  757. // Get list of exercises in the instance:
  758. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  759. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  760. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  761. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  762. // Get list of enrolled students:
  763. $params_temp = array('shortname' => 'student');
  764. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  765. $context = context_course::instance($this->course->id);
  766. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  767. $students_list = $DB->get_records_sql(
  768. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  769. print '<div>';
  770. foreach ($exercises_list as $exercise) {
  771. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  772. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  773. print '
  774. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  775. . $exercise->name
  776. . ' - ' . $iassign_ilm->name
  777. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  778. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  779. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  780. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  781. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  782. . '</a>';
  783. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  784. foreach ($students_list as $student) {
  785. $total = 0;
  786. $student_submissions = [];
  787. foreach ($submissions_list as $submission) {
  788. if ($submission->userid == $student->userid) {
  789. $student_submissions[] = $submission;
  790. $total++;
  791. }
  792. }
  793. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  794. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  795. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  796. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  797. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  798. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  799. . ' </a>';
  800. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  801. print '<table class="table table-striped table-hover"><thead>
  802. <tr>
  803. <th scope="col">#</th>
  804. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  805. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  806. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  807. </tr>
  808. </thead><tbody>'; // "
  809. $i = 1;
  810. foreach ($student_submissions as $individual) {
  811. $date = new DateTime();
  812. $date->setTimestamp($individual->timecreated);
  813. print '<tr>';
  814. print '<td>'.$i++.'</td>';
  815. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  816. print '<td>'.$individual->grade.'</td>';
  817. print '<td>
  818. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  819. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  820. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  821. print " </tr>\n";
  822. }
  823. print '</tbody></table>';
  824. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  825. print '</div>';
  826. }
  827. print '</div>';
  828. }
  829. print '</div>';
  830. print $OUTPUT->footer();
  831. } // function all_submissions()
  832. /// This method runs activities auto evaluation in teacher area
  833. function auto_evaluate () {
  834. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  835. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  836. exit;
  837. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  838. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  839. // Get list of exercises in the instance:
  840. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  841. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  842. // Get list of enrolled students:
  843. $params_temp = array('shortname' => 'student');
  844. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  845. $context = context_course::instance($this->course->id);
  846. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  847. $students_list = $DB->get_records_sql(
  848. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  849. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  850. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  851. print $OUTPUT->header();
  852. $this->print_main_menu();
  853. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  854. print '<ul style="list-style-type: none; margin: 1em;">';
  855. foreach ($exercises_list as $exercise) {
  856. $matches = [];
  857. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  858. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  859. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  860. if ($matches[0][0]) {
  861. 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>';
  862. } else {
  863. 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>';
  864. }
  865. } else {
  866. if ($matches[0][0]) {
  867. 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>';
  868. } else {
  869. 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>';
  870. }
  871. }
  872. }
  873. print '</ul>
  874. <center>
  875. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  876. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  877. <div id="evaluate_message" style="color: red"></div>
  878. <div id="evaluate_alerts"></div>
  879. <div>
  880. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  881. <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>
  882. </div>
  883. </center>'; // close "
  884. print ' </div>' . "\n";
  885. print ' <script>';
  886. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  887. print ' var submissions = [';
  888. // Get list of student id have submit for each exercise:
  889. foreach ($exercises_list as $exercise) {
  890. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  891. print '
  892. {
  893. "exerciseid": "' . $exercise->id . '",
  894. "grade": ' . $exercise->grade . ',
  895. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  896. "submited": ['; // "
  897. $params_temp = array('iassign_statementid' => $exercise->id);
  898. $submited = $DB->get_records_sql( // Get userid and his grade
  899. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  900. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  901. foreach ($submited as $ss) {
  902. print($ss->userid . ',');
  903. }
  904. print '],';
  905. print '"allgrades": [';
  906. foreach ($submited as $ss) {
  907. print( $ss->grade . ',');
  908. }
  909. print ']
  910. },'; // close "
  911. } // foreach ($exercises_list as $exercise)
  912. print " ];\n";
  913. print '
  914. var total_submissions = 0;
  915. var selected_exercises;
  916. var count_steps;
  917. var value_by_step;
  918. var stoped = false;
  919. var time_interval = 5000;
  920. var var_interval;
  921. function add_hover_th (id_th, id_li) { //AJAX
  922. $("#" + id_th).hover(function() {
  923. $("#" + id_li).css("background-color", "#d9d8d8");
  924. $(this).css("background-color", "#d9d8d8");
  925. }, function() {
  926. $("#" + id_li).css("background-color", "");
  927. $(this).css("background-color", "");
  928. });
  929. }
  930. function start_evaluation () {
  931. stoped = false;
  932. //AJAX
  933. $("#progress_bar").css("display", "none");
  934. $("#evaluate_message").text("");
  935. $("#evaluate_alerts").text("");
  936. $(".added-col").remove();
  937. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  938. selected_exercises = [];
  939. var c = 0;
  940. for (var i = 0; i < exercises.length; i++) {
  941. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  942. selected_exercises[c++] = exercises[i];
  943. }
  944. }
  945. if (selected_exercises.length == 0) {
  946. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  947. return;
  948. } else {
  949. $("input:checkbox").attr("disabled", true); //AJAX
  950. for (var i = 0; i < selected_exercises.length; i++) {
  951. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  952. //AJAX
  953. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  954. $("#table-results tbody tr").each(function(e) {
  955. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  956. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  957. });
  958. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  959. }
  960. //AJAX
  961. $("#button_start").prop("disabled", true);
  962. $("#button_stop").prop("disabled", false);
  963. $("#progress_bar").css("display", "block");
  964. }
  965. total_submissions = selected_exercises.length * students.length;
  966. count_steps = 0;
  967. value_by_step = 100/total_submissions;
  968. actual_exercise = 0;
  969. actual_student = 0;
  970. actual_submission = 0;
  971. get_original_propositions();
  972. var_interval = setInterval(verifyBreak, time_interval);
  973. } // function start_evaluation()
  974. var actual_exercise;
  975. var actual_student;
  976. var actual_submission;
  977. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  978. function run_individual_evaluation () {
  979. if (stoped) return;
  980. // Verify if student really sent his answer
  981. var found = false;
  982. for (var j = 0; j < submissions.length; j++) {
  983. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  984. for (var k = 0; k < submissions[j].submited.length; k++) {
  985. if (students[actual_student] == submissions[j].submited[k]) {
  986. found = true;
  987. break;
  988. }
  989. }
  990. break;
  991. }
  992. }
  993. if (found == false) {
  994. postResultAutoEval();
  995. } else {
  996. // If it was sent, search it...
  997. var final_url = "";
  998. 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];
  999. for (var j = 0; j < submissions.length; j++) {
  1000. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1001. final_url = submissions[j].ilm;
  1002. break;
  1003. }
  1004. }
  1005. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1006. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1007. window.frames["ifrm"].location=final_url;
  1008. }
  1009. } // function run_individual_evaluation()
  1010. var break_student = -1;
  1011. var break_exercise = -1;
  1012. function verifyBreak () {
  1013. if (actual_student == break_student && actual_exercise == break_exercise) {
  1014. postResultAutoEval(-6);
  1015. break_student = -1;
  1016. break_exercise = -1;
  1017. return;
  1018. } else {
  1019. break_student = actual_student;
  1020. break_exercise = actual_exercise;
  1021. }
  1022. }
  1023. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1024. function getStudentAnswerURL () {
  1025. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1026. }
  1027. // This function is called by the iLM!!!
  1028. function getAutoEvalOriginalData () {
  1029. return original_propositions[actual_exercise];
  1030. }
  1031. function updateProgressBar () {
  1032. if (stoped) return;
  1033. var temp = (count_steps * value_by_step)|0;
  1034. count_steps++;
  1035. temp = temp > 100 ? 100 : temp;
  1036. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1037. if (temp >= 100) {
  1038. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1039. $("#button_start").prop("disabled", false);
  1040. $("#button_stop").prop("disabled", true);
  1041. $("input:checkbox").attr("disabled", false);
  1042. clearInterval(var_interval);
  1043. }
  1044. }
  1045. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1046. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1047. function postResultAutoEval (grade = null) {
  1048. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1049. if (grade == null) {
  1050. $("#"+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>\');
  1051. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1052. } else {
  1053. // Verify if the re-evaluation grade is the of that one registered:
  1054. var actual_value = 0;
  1055. var actual_student_grade = 0;
  1056. for (var k = 0; k < submissions.length; k++) {
  1057. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1058. actual_value = submissions[k].grade;
  1059. for (var h = 0; h < submissions[k].submited.length; h++) {
  1060. if (submissions[k].submited[h] == students[actual_student]) {
  1061. actual_student_grade = submissions[k].allgrades[h];
  1062. break;
  1063. }
  1064. }
  1065. break;
  1066. }
  1067. }
  1068. // @FeedbackConvention
  1069. if (grade < 0) {
  1070. switch (grade) {
  1071. case -1:
  1072. // Test-cases are empty:
  1073. $("#"+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>\');
  1074. var mm = actual_exercise;
  1075. $("#"+id_t).find(".details-button").click(function(e) {
  1076. $(".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>\');
  1077. });
  1078. break;
  1079. case -2:
  1080. // Test-cases were manually altered by the student (fraud!):
  1081. $("#"+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>\');
  1082. var mm = actual_exercise;
  1083. $("#"+id_t).find(".details-button").click(function(e) {
  1084. $(".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>");
  1085. });
  1086. //AJAX
  1087. $.ajax({
  1088. dataType: "html",
  1089. 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",
  1090. success: function(d) {} });
  1091. break;
  1092. case -5:
  1093. // Execution failed:
  1094. $("#"+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>\');
  1095. var mm = actual_exercise;
  1096. //AJAX
  1097. $("#"+id_t).find(".details-button").click(function(e) {
  1098. $(".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>\');
  1099. });
  1100. break;
  1101. case -6: // iLM not answering was detected in "verifyBreak()"
  1102. // The iLM are not answering:
  1103. //AJAX
  1104. $("#"+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>\');
  1105. $("#"+id_t).find(".details-button").click(function(e) {
  1106. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1107. });
  1108. break;
  1109. }
  1110. //AJAX
  1111. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1112. } else {
  1113. console.log((grade), (actual_student_grade));
  1114. if ((grade) == (actual_student_grade)) {
  1115. $("#"+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>\');
  1116. } else { // Notas diferem:
  1117. $("#"+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>\');
  1118. var mm = actual_exercise;
  1119. //AJAX
  1120. $("#"+id_t).find(".details-button").click(function(e) {
  1121. $(".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>\');
  1122. });
  1123. //AJAX
  1124. // Send to the endpoint the post_auto_eval_result to verify:
  1125. $.ajax({
  1126. dataType: "html",
  1127. 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),
  1128. success: function(d) {}
  1129. });
  1130. }
  1131. //AJAX
  1132. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1133. }
  1134. }
  1135. updateProgressBar();
  1136. // Does it must continue in the same exercise or stop?
  1137. if (actual_student < students.length) {
  1138. actual_student++;
  1139. run_individual_evaluation();
  1140. } else {
  1141. actual_student = 0;
  1142. // Does it go to next exercise or is it finished?
  1143. if (actual_exercise < selected_exercises.length) {
  1144. actual_exercise++;
  1145. run_individual_evaluation();
  1146. } else {
  1147. //AJAX
  1148. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1149. }
  1150. }
  1151. }
  1152. var original_propositions;
  1153. function get_original_propositions () {
  1154. original_propositions = [];
  1155. var count = 0;
  1156. for (var i = 0; i < exercises.length; i++) {
  1157. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1158. //AJAX
  1159. $.ajax({
  1160. dataType: "html",
  1161. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1162. success: function(d) { // variable "d" has the iLM content
  1163. original_propositions[count] = d; // exercise original content
  1164. count++;
  1165. if (count == selected_exercises.length) {
  1166. run_individual_evaluation();
  1167. }
  1168. }
  1169. });
  1170. }
  1171. }
  1172. }
  1173. function stop_evaluation () {
  1174. stoped = true;
  1175. //AJAX
  1176. $("#button_start").prop("disabled", false);
  1177. $("#button_stop").prop("disabled", true);
  1178. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1179. $("input:checkbox").attr("disabled", false);
  1180. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1181. clearInterval(var_interval);
  1182. }
  1183. var exercises = [ '; // '
  1184. foreach ($exercises_list as $exercise) {
  1185. print $exercise->id . ',';
  1186. }
  1187. print ' ];';
  1188. print ' var students = [ ';
  1189. foreach ($students_list as $student) {
  1190. print $student->userid . ',';
  1191. }
  1192. print '];';
  1193. print ' var ilms = [';
  1194. foreach ($exercises_list as $exercise) {
  1195. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1196. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1197. }
  1198. print ']';
  1199. print '</script>';
  1200. print '
  1201. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1202. <div class="modal-dialog modal-dialog-centered" role="document">
  1203. <div class="modal-content">
  1204. <div class="modal-header">
  1205. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1206. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1207. <span aria-hidden="true">&times;</span>
  1208. </button>
  1209. </div>
  1210. <div class="modal-body">
  1211. ...
  1212. </div>
  1213. <div class="modal-footer">
  1214. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1215. </div>
  1216. </div>
  1217. </div>
  1218. </div>'; //
  1219. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1220. print '<table id="table-results" class="table table-hover m-t-1">
  1221. <thead>
  1222. <tr id="cols-exercises">
  1223. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1224. </tr>
  1225. </thead>
  1226. <tbody>'; // "
  1227. foreach ($students_list as $student) {
  1228. $user = $DB->get_record('user', array('id' => $student->userid));
  1229. $avatar = new user_picture($user);
  1230. $avatar->courseid = $COURSE->id;
  1231. $avatar->link = true;
  1232. print ' <tr data-student="' . $student->userid . '">
  1233. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1234. </tr>' . "\n"; // "
  1235. }
  1236. print " </tbody>
  1237. </table>\n";
  1238. print $OUTPUT->footer();
  1239. } // function auto_evaluate()
  1240. /// This method moves an iAssign activity
  1241. function move_activity () {
  1242. global $USER, $CFG, $DB, $COURSE;
  1243. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1244. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1245. $update_entry_new_iassign = new stdClass();
  1246. $update_entry_new_iassign->id = $iassign_id;
  1247. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1248. // Update the iassign_statement
  1249. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1250. // Update file context
  1251. $c_i = context_module::instance($this->cm->id);
  1252. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1253. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1254. $path_module = context_course::instance($COURSE->id);
  1255. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1256. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1257. if ($context_file) {
  1258. $id_context = $context_file->id;
  1259. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1260. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1261. $context = context_module::instance($USER->cm); //2021/12
  1262. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1263. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1264. foreach ($files as $value) {
  1265. if ($value->get_filename() != ".") {
  1266. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1267. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1268. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1269. $newfile = null; //TODO: desnecessario! Atribuicao 2 linhas abaixo!
  1270. $destiny_context = context_module::instance($course_module->id);
  1271. $newfile = $fs->create_file_from_string(array('contextid' => $destiny_context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id, 'filepath' => '/', 'filename' => $value->get_filename()), $value->get_content());
  1272. $updateentry = new stdClass();
  1273. $updateentry->id = $iassign_id;
  1274. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1275. $DB->update_record("iassign_statement", $updateentry);
  1276. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1277. break;
  1278. }
  1279. }
  1280. }
  1281. //2021/12 $this->return_home_course('moved_activity');
  1282. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1283. redirect($this->return, get_string('moved_activity', 'iassign').' <a href="'.$destiny_url.'">' . get_string('move_activity_access', 'iassign') . '\'' . $course_module->name . '\'</a>', null, \core\output\notification::NOTIFY_SUCCESS);
  1284. exit;
  1285. } // function move_activity()
  1286. /// This method duplicates an iAssign activity
  1287. function duplicate_activity () {
  1288. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1289. $id = $this->cm->id;
  1290. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1291. $context = context_module::instance($this->cm->id);
  1292. $contextuser = context_user::instance($USER->id);
  1293. // Get the the iAssign acitivity to be duplicated
  1294. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1295. // Remove the current id of activity
  1296. $id_source_copy = $iassign_statement->id;
  1297. $iassign_statement->id=0;
  1298. // Include prefix (Copy of ...)
  1299. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1300. // Get the information about current author, and add this information in author_modified field
  1301. $author = $DB->get_record("user", array('id' => $USER->id));
  1302. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1303. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1304. // Store the activity in the table
  1305. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1306. // Duplicate activity file
  1307. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1308. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1309. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1310. foreach ($files as $value) {
  1311. if ($value->get_filename() != ".") {
  1312. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1313. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1314. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1315. $updateentry = new stdClass();
  1316. $updateentry->id = $id_;
  1317. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1318. $updateentry->filesid = $id_;
  1319. // Update the duplicated iLM iAssign with new file id
  1320. $DB->update_record("iassign_statement", $updateentry);
  1321. }
  1322. }
  1323. }
  1324. // log event --------------------------------------------------------------------------------------
  1325. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1326. $this->return_home_course('duplicated_activity');
  1327. exit;
  1328. }
  1329. // / This method gets the content from comment and register it
  1330. function add_comment () {
  1331. global $USER, $DB;
  1332. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1333. $comment = false;
  1334. if ($submission_comment)
  1335. $comment = $this->write_comment_submission();
  1336. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1337. if (!$id_submission) {
  1338. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1339. if ($iassign_submission) {
  1340. $id_submission = $iassign_submission->id;
  1341. }
  1342. }
  1343. $content = $this->search_comment_submission($id_submission);
  1344. ob_end_clean();
  1345. header("Connection: close\r\n");
  1346. header("Content-Encoding: none\r\n");
  1347. header('Content-Type: text/html');
  1348. ob_start();
  1349. print $this->search_comment_submission($id_submission);
  1350. $size = ob_get_length();
  1351. header("Content-Length: $size");
  1352. ob_end_flush();
  1353. flush();
  1354. ob_end_clean();
  1355. // Send email to users:
  1356. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1357. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1358. }
  1359. /// This method alerts envolved to new comment sent
  1360. function send_alert_new_comment ($comment, $student_id = -1) {
  1361. global $USER, $DB, $COURSE, $SITE;
  1362. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1363. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1364. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1365. $url_curso;
  1366. $url_submissao;
  1367. $text = "<p style='margin-top: 1rem;'>\n";
  1368. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811;\n";
  1369. $modinfo = get_fast_modinfo($COURSE);
  1370. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1371. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1372. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1373. $text .= "<a href=\"" . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section) . "</a> &#8811;\n";
  1374. break;
  1375. }
  1376. }
  1377. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1378. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811;\n";
  1379. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1380. array(
  1381. 'id' => $this->cm->id,
  1382. 'action' => 'viewsubmission',
  1383. 'iassign_current' => $this->activity->get_activity()->id,
  1384. 'userid_iassign' => $USER->id));
  1385. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1386. $text .= "<div style='margin-left: .5rem;'>\n";
  1387. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1388. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1389. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1390. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1391. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1392. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1393. $text .= " - " . userdate(time());
  1394. $text .= "</div><div style='margin: 2rem;'>\n";
  1395. $text .= $comment;
  1396. $text .= "</div><div>\n";
  1397. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1398. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1399. $text .= "</div>\n";
  1400. // Who has to receive?
  1401. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1402. $userfrom = \core_user::get_noreply_user();
  1403. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1404. // other teachers receive also: (excepts the sender)
  1405. foreach ($teachers as $teacher) {
  1406. if ($teacher->id != $USER->id) {
  1407. email_to_user(
  1408. $teacher,
  1409. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1410. $subject,
  1411. "",
  1412. $text,
  1413. '',
  1414. '',
  1415. false,
  1416. $userfrom->email,
  1417. 'Não responda a esta mensagem' //TODO: internacionalizar
  1418. );
  1419. $message = new \core\message\message();
  1420. $message->component = 'mod_iassign';
  1421. $message->name = 'message';
  1422. $message->userfrom = core_user::get_noreply_user();
  1423. $message->userto = $teacher;
  1424. $message->subject = $subject;
  1425. $message->fullmessage = $text;
  1426. $message->fullmessageformat = FORMAT_MARKDOWN;
  1427. $message->fullmessagehtml = $text;
  1428. $message->smallmessage = $subject;
  1429. $message->notification = 1;
  1430. $message->contexturl = $url_submissao . '#comments';
  1431. $message->contexturlname = $this->activity->get_activity()->name;
  1432. $messageid = message_send($message);
  1433. }
  1434. } // foreach
  1435. // and student:
  1436. $student = $DB->get_record('user', array('id' => $student_id));
  1437. $formated_text = str_replace("viewsubmission", "view", $text);
  1438. email_to_user(
  1439. $student,
  1440. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1441. $subject,
  1442. "",
  1443. $formated_text,
  1444. '',
  1445. '',
  1446. false,
  1447. $userfrom->email,
  1448. 'Não responda a esta mensagem' //TODO: internacionalizar
  1449. );
  1450. $url_student = new moodle_url('/mod/iassign/view.php',
  1451. array(
  1452. 'id' => $this->cm->id,
  1453. 'action' => 'view',
  1454. 'iassign_current' => $this->activity->get_activity()->id));
  1455. $message = new \core\message\message();
  1456. $message->component = 'mod_iassign';
  1457. $message->name = 'message';
  1458. $message->userfrom = core_user::get_noreply_user();
  1459. $message->userto = $student;
  1460. $message->subject = $subject;
  1461. $message->fullmessage = $formated_text;
  1462. $message->fullmessageformat = FORMAT_MARKDOWN;
  1463. $message->fullmessagehtml = $formated_text;
  1464. $message->smallmessage = $subject;
  1465. $message->notification = 1;
  1466. $message->contexturl = $url_student . '#comments';
  1467. $message->contexturlname = $this->activity->get_activity()->name;
  1468. $messageid = message_send($message);
  1469. } else { // a student has sent the comment:
  1470. foreach ($teachers as $teacher) {
  1471. email_to_user(
  1472. $teacher,
  1473. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1474. $subject,
  1475. "",
  1476. $text,
  1477. '',
  1478. '',
  1479. false,
  1480. $userfrom->email,
  1481. 'Não responda a esta mensagem' //TODO: internacionalizar
  1482. );
  1483. $message = new \core\message\message();
  1484. $message->component = 'mod_iassign';
  1485. $message->name = 'message';
  1486. $message->userfrom = core_user::get_noreply_user();
  1487. $message->userto = $teacher;
  1488. $message->subject = $subject;
  1489. $message->fullmessage = $text;
  1490. $message->fullmessageformat = FORMAT_MARKDOWN;
  1491. $message->fullmessagehtml = $text;
  1492. $message->smallmessage = $subject;
  1493. $message->notification = 1;
  1494. $message->contexturl = $url_submissao . '#comments';
  1495. $message->contexturlname = $this->activity->get_activity()->name;
  1496. $messageid = message_send($message);
  1497. }
  1498. }
  1499. } // function send_alert_new_comment($comment, $student_id = -1)
  1500. /// This method gets the content from the iLM and register it
  1501. // It could be the "exercise template" (teacher) or an answer (student)
  1502. function get_answer () {
  1503. global $USER, $CFG, $DB, $OUTPUT;
  1504. $id = $this->cm->id;
  1505. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1506. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1507. if ($submission_ajax == 1) ob_start();
  1508. $comment = false;
  1509. if ($submission_comment)
  1510. $comment = $this->write_comment_submission();
  1511. // receives data of iLM using the current activity
  1512. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1513. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1514. // receives data of submission of current activity
  1515. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1516. // receives post and get
  1517. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1518. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1519. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1520. $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)
  1521. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1522. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1523. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1524. $msg = '';
  1525. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1526. $newentry = new stdClass();
  1527. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1528. $newentry->userid = $this->userid_iassign;
  1529. $newentry->timecreated = time();
  1530. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1531. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1532. $DB->insert_record("iassign_allsubmissions", $newentry);
  1533. }
  1534. // Feedback
  1535. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1536. $str_action = "view"; // repeat
  1537. if (strtolower($iassign_ilm->name) == "igeom") {
  1538. }
  1539. $title = get_string('evaluate_iassign', 'iassign');
  1540. print $OUTPUT->header();
  1541. print $OUTPUT->box_start();
  1542. // Action = { view ; repeat ; viewsubmission }
  1543. // * '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")
  1544. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1545. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1546. $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;
  1547. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1548. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1549. print '<table width=100% >';
  1550. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1551. //TODO alterar aqui???
  1552. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1553. // empty_answer_post = No solution was posted.
  1554. if ($comment)
  1555. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1556. else
  1557. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1558. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1559. } else {
  1560. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1561. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1562. // Correct answer!!
  1563. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1564. $this->write_solution = 1; //
  1565. $status = 3;
  1566. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1567. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1568. // log record
  1569. $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;
  1570. // Trigger module viewed event.
  1571. $event = \mod_iassign\event\submission_created::create(array(
  1572. 'objectid' => $this->iassign->id,
  1573. 'context' => $this->context,
  1574. 'other' => $info
  1575. ));
  1576. $event->add_record_snapshot('course', $this->course);
  1577. $event->trigger();
  1578. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1579. // Wrong answer...: get_answer_incorrect
  1580. $status = 2;
  1581. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1582. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1583. // log record
  1584. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1585. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1586. // Trigger module viewed event.
  1587. $event = \mod_iassign\event\submission_created::create(array(
  1588. 'objectid' => $this->iassign->id,
  1589. 'context' => $this->context,
  1590. 'other' => $info
  1591. ));
  1592. $event->add_record_snapshot('course', $this->course);
  1593. $event->trigger();
  1594. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1595. // Presents to the learner the result of the automatic evaluate?
  1596. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1597. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1598. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1599. print '<tr>';
  1600. // log record
  1601. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1602. // Trigger module viewed event.
  1603. $event = \mod_iassign\event\submission_created::create(array(
  1604. 'objectid' => $this->iassign->id,
  1605. 'context' => $this->context,
  1606. 'other' => $info
  1607. ));
  1608. $event->add_record_snapshot('course', $this->course);
  1609. $event->trigger();
  1610. } else { // yes!!!
  1611. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1612. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1613. print '<tr>';
  1614. print $msg;
  1615. }
  1616. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1617. $status = 1;
  1618. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1619. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1620. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1621. print '<tr>';
  1622. // log record
  1623. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1624. $event = \mod_iassign\event\submission_created::create(array(
  1625. 'objectid' => $this->iassign->id,
  1626. 'context' => $this->context,
  1627. 'other' => $info
  1628. ));
  1629. $event->add_record_snapshot('course', $this->course);
  1630. $event->trigger();
  1631. } // if ($iassign_ilm->evaluate == 1)
  1632. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1633. print '</tr></table>';
  1634. print $OUTPUT->box_end();
  1635. // add or update evaluate
  1636. if ($this->write_solution == 1) {
  1637. $timenow = time();
  1638. // new record
  1639. if (!$iassign_submission) {
  1640. $newentry = new stdClass();
  1641. $newentry->userid = $this->userid_iassign;
  1642. // $newentry->userid = $USER->id;
  1643. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1644. $newentry->timecreated = $timenow;
  1645. $newentry->timemodified = $timenow;
  1646. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1647. $newentry->grade = round($grade_student, 2);
  1648. $newentry->status = $status;
  1649. $newentry->experiment = 1;
  1650. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1651. print_error('error_insert', 'iassign');
  1652. } else {
  1653. // Trigger module viewed event.
  1654. $event = \mod_iassign\event\submission_created::create(array(
  1655. 'objectid' => $this->iassign->id,
  1656. 'context' => $this->context
  1657. ));
  1658. $event->add_record_snapshot('course', $this->course);
  1659. $event->trigger();
  1660. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1661. }
  1662. } elseif ($iassign_submission->status != 3) {
  1663. $newentry = new stdClass();
  1664. $newentry->id = $iassign_submission->id;
  1665. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1666. $newentry->userid = $iassign_submission->userid;
  1667. $newentry->timecreated = $iassign_submission->timecreated;
  1668. $newentry->timemodified = $timenow;
  1669. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1670. $newentry->grade = round($grade_student, 2);
  1671. $newentry->status = $status;
  1672. $newentry->experiment = $iassign_submission->experiment + 1;
  1673. if (!$DB->update_record("iassign_submission", $newentry)) {
  1674. print_error('error_update', 'iassign');
  1675. //D depurar...
  1676. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1677. //D $fp = fopen("teste1.txt","w");
  1678. //D fwrite($fp,$stringAux);
  1679. } else {
  1680. // Trigger module viewed event.
  1681. $event = \mod_iassign\event\submission_updated::create(array(
  1682. 'objectid' => $this->iassign->id,
  1683. 'context' => $this->context
  1684. ));
  1685. $event->add_record_snapshot('course', $this->course);
  1686. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1687. }
  1688. } else {
  1689. if ($return_get_answer == 1) {
  1690. $newentry = new stdClass();
  1691. $newentry->id = $iassign_submission->id;
  1692. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1693. $newentry->userid = $iassign_submission->userid;
  1694. $newentry->timecreated = $iassign_submission->timecreated;
  1695. $newentry->timemodified = $timenow;
  1696. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1697. $newentry->grade = round($grade_student, 2);
  1698. $newentry->status = $status;
  1699. $newentry->experiment = $iassign_submission->experiment + 1;
  1700. if (!$DB->update_record("iassign_submission", $newentry))
  1701. print_error('error_update', 'iassign');
  1702. else {
  1703. $event = \mod_iassign\event\submission_updated::create(array(
  1704. 'objectid' => $this->iassign->id,
  1705. 'context' => $this->context
  1706. ));
  1707. $event->add_record_snapshot('course', $this->course);
  1708. $event->trigger();
  1709. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1710. print $OUTPUT->box_start();
  1711. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1712. print $OUTPUT->box_end();
  1713. }
  1714. } elseif ($return_get_answer == 2) {
  1715. print $OUTPUT->box_start();
  1716. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1717. print $OUTPUT->box_end();
  1718. } else {
  1719. print $OUTPUT->box_start();
  1720. print "
  1721. <script type='text/javascript'>
  1722. //<![CDATA[
  1723. function overwrite () {
  1724. document.formEnvio.return_get_answer.value = 1;
  1725. document.formEnvio.submit();
  1726. }
  1727. function nooverwrite () {
  1728. document.formEnvio.return_get_answer.value = 2;
  1729. document.formEnvio.submit();
  1730. }
  1731. //]]>
  1732. </script>";
  1733. $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;
  1734. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1735. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1736. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1737. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1738. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1739. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1740. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1741. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1742. <input type='hidden' name='return_get_answer'/> ";
  1743. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1744. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1745. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1746. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1747. print " </form>";
  1748. print $OUTPUT->box_end();
  1749. }
  1750. }
  1751. } // if ($this->write_solution == 1)
  1752. print $OUTPUT->footer();
  1753. if ($submission_ajax == 1) {
  1754. ob_end_clean();
  1755. print 'OK';
  1756. }
  1757. die();
  1758. } // function get_answer()
  1759. /// Export in file the answer of student.
  1760. function export_file_answer () {
  1761. global $DB;
  1762. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1763. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1764. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1765. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1766. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1767. $extensions = explode(",", $iassign_ilm->extension);
  1768. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1769. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1770. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1771. header("Pragma: public");
  1772. header("Expires: 0");
  1773. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1774. header("Cache-Control: private", false);
  1775. header("Content-Type: document/unknown");
  1776. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1777. set_time_limit(0);
  1778. print($iassign_submission->answer);
  1779. exit;
  1780. } // function export_file_answer()
  1781. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1782. // @calledby $this->export_package_answer()
  1783. //TODO Precisa terminar! //TODO_HTML
  1784. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1785. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1786. <head>
  1787. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1788. $str_html .= " </head>
  1789. <body>\n";
  1790. $tam = sizeof($array_iassign_name);
  1791. for ($ii=0; $ii<$tam; $ii++) {
  1792. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1793. }
  1794. $str_html .= "
  1795. </body>\n</html>";
  1796. return $str_html;
  1797. }
  1798. /// Export an package (zip) with all answer of students
  1799. // @calledby $this->action()
  1800. function export_package_answer () {
  1801. global $DB, $CFG, $OUTPUT;
  1802. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1803. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1804. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1805. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1806. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1807. $userid = optional_param('userid', NULL, PARAM_INT);
  1808. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1809. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1810. //TODO_HTML echo "username=$username<br/>"; exit;
  1811. $current_date = date('Y_m_d_H');
  1812. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1813. // If temporary directory under Moodle data does not exists => create it
  1814. if (!is_dir($diretorio)) {
  1815. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1816. // created directory with permissions to be seen by everyone
  1817. }
  1818. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1819. if (!is_writable($diretorio)) { // send a highlighted message!
  1820. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1821. exit; // just in case
  1822. }
  1823. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1824. $zip = new zip_archive(); // create ZIP
  1825. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1826. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1827. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1828. $vet_student_filename = array();
  1829. $vet_student_content = array();
  1830. foreach ($iassign_statements as $iassign_statement) {
  1831. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1832. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1833. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1834. $extensions = explode(",", $iassign_ilm->extension);
  1835. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1836. if ($iassign_submission) {
  1837. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1838. $student_content = $iassign_submission->answer;
  1839. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1840. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1841. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1842. if ($resp) {
  1843. $vet_student_filename[] = $student_filename;
  1844. $vet_student_content[] = $student_content;
  1845. }
  1846. else { // send a highlighted message!
  1847. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1848. exit; // just in case
  1849. }
  1850. }
  1851. }
  1852. $zip->close(); // close the ZIP file
  1853. if (count($vet_student_filename)>0) {
  1854. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1855. $result_tf = $vet_result[0];
  1856. $filenameZip = $vet_result[1]->filename;
  1857. }
  1858. iassign_utils::download_file($zip_filename); // download the ZIP file
  1859. exit;
  1860. } // function export_package_answer()
  1861. /// Editing status of interactive activities
  1862. function edit_status () {
  1863. global $USER, $DB, $OUTPUT;
  1864. $newentry = new stdClass();
  1865. $newentry->id = $this->iassign_submission_current;
  1866. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1867. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1868. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1869. $newentry->status = $iassign_submission->status;
  1870. $newentry->teacher = $USER->id;
  1871. if (!$DB->update_record('iassign_submission', $newentry))
  1872. print_error('error_update', 'iassign');
  1873. else {
  1874. // Trigger module viewed event.
  1875. $event = \mod_iassign\event\submission_updated::create(array(
  1876. 'objectid' => $this->iassign->id,
  1877. 'context' => $this->context
  1878. ));
  1879. $event->add_record_snapshot('course', $this->course);
  1880. $event->trigger();
  1881. $this->action = 'viewsubmission';
  1882. $this->view_iassign_current();
  1883. } // if (!$DB->update_record('iassign_submission', $newentry))
  1884. } // function edit_status()
  1885. /// Editing grade of interactive activities
  1886. function edit_grade () {
  1887. global $USER, $DB, $OUTPUT;
  1888. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1889. if ($newgrade && $newgrade >= 0) {
  1890. $newentry = new stdClass();
  1891. $newentry->id = $this->iassign_submission_current;
  1892. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1893. $newentry->teacher = $USER->id;
  1894. if (!$DB->update_record('iassign_submission', $newentry))
  1895. print_error('error_update', 'iassign');
  1896. else {
  1897. // Trigger module viewed event.
  1898. $event = \mod_iassign\event\submission_updated::create(array(
  1899. 'objectid' => $this->iassign->id,
  1900. 'context' => $this->context
  1901. ));
  1902. $event->add_record_snapshot('course', $this->course);
  1903. $event->trigger();
  1904. }
  1905. } // if ($newgrade >= 0)
  1906. $this->action = 'viewsubmission';
  1907. $this->view_iassign_current();
  1908. }
  1909. /// Add or Edit interactive activities
  1910. // Get here when editing form and and submitted form data
  1911. // @calledby $this->action()
  1912. function add_edit_iassign () {
  1913. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1914. require_once('iassign_form.php');
  1915. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1916. $iassignid = $this->iassign->id;
  1917. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1918. $param->action = $this->action; // hidden
  1919. $param->id = $id; // hidden
  1920. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1921. $COURSE->cm = $id;
  1922. $COURSE->iassignid = $iassignid;
  1923. $COURSE->iassign_file_id = NULL;
  1924. $context = context_module::instance($this->cm->id);
  1925. $contextuser = context_user::instance($USER->id);
  1926. $component = 'mod_iassign';
  1927. $filearea = 'exercise';
  1928. if (!empty($this->iassign_current))
  1929. $COURSE->iassign_id = $this->iassign_current;
  1930. else
  1931. $COURSE->iassign_id = 0;
  1932. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1933. if ($this->action == 'add') {
  1934. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1935. $params_temp = array('iassignid' => $iassignid);
  1936. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1937. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1938. $total_of_activities = count($iassign_statement);
  1939. $param->iassignid = $iassignid;
  1940. $param->name = "";
  1941. $param->oldname = "";
  1942. $param->type_iassign = 3;
  1943. $param->proposition = "";
  1944. $author = $DB->get_record("user", array("id" => $USER->id));
  1945. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1946. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1947. $param->author = $param->author_name;
  1948. $param->author_modified = $param->author_modified_name;
  1949. $COURSE->iassign_list = array();
  1950. $param->iassign_list = array();
  1951. if ($iassign_statement) {
  1952. foreach ($iassign_statement as $iassign) {
  1953. $iassignid = $iassign->id;
  1954. $param->iassign_list[$iassignid] = 0;
  1955. $COURSE->iassign_list[$iassignid] = new stdClass();
  1956. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1957. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1958. $COURSE->iassign_list[$iassignid]->enable = 1;
  1959. } // foreach ($iassign_statement as $iassign)
  1960. }
  1961. $param->iassign_ilmid = 0;
  1962. $param->file = 0;
  1963. $param->fileold = 0;
  1964. $param->filename = "";
  1965. $param->grade = $iassign_data->grade;
  1966. $param->timemodified = time();
  1967. $param->timecreated = time();
  1968. $param->timeavailable = $iassign_data->timeavailable;
  1969. $param->timedue = $iassign_data->timedue;
  1970. $param->preventlate = $iassign_data->preventlate;
  1971. $param->test = $iassign_data->test;
  1972. $param->special_param1 = 0;
  1973. $param->visible = 1;
  1974. $param->max_experiment = $iassign_data->max_experiment;
  1975. $param->dependency = 0;
  1976. $param->automatic_evaluate = 1;
  1977. $param->show_answer = 1;
  1978. } // if ($this->action == 'add')
  1979. elseif ($this->action == 'edit') {
  1980. $COURSE->iassign_list = array();
  1981. $this_activity = $this->activity->get_activity();
  1982. if ($this_activity != null) { // first enter here: fill form data
  1983. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1984. $param->iassign_id = $iassign_statement_current->id; // oculto
  1985. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1986. $param->name = $iassign_statement_current->name;
  1987. $param->oldname = $iassign_statement_current->name;
  1988. $param->type_iassign = $iassign_statement_current->type_iassign;
  1989. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1990. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1991. $param->author_name = $iassign_statement_current->author_name; // oculto
  1992. $param->author = $iassign_statement_current->author_name;
  1993. $author = $DB->get_record("user", array('id' => $USER->id));
  1994. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1995. $param->author_modified = $param->author_modified_name;
  1996. $dependency = explode(';', $iassign_statement_current->dependency);
  1997. $param->iassign_list = array();
  1998. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1999. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2000. $array_dependency = array();
  2001. $subdependency = "";
  2002. $sub_subdependency = "";
  2003. // Dependents on this exercise
  2004. if ($iassign_statement_dependency) {
  2005. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2006. // to whom this exercise depends
  2007. foreach ($inter as $tmp)
  2008. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2009. $list_dependency = $subdependency . $sub_subdependency;
  2010. $array_dependency = explode(";", $list_dependency);
  2011. }
  2012. // Get all activities in the same iAssigment block:
  2013. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2014. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2015. $total_of_activities = count($all_others_iassign_statement) + 1;
  2016. $inter = array();
  2017. if ($all_others_iassign_statement) {
  2018. foreach ($all_others_iassign_statement as $iassign)
  2019. if (in_array($iassign->id, $dependency))
  2020. $inter[] = $iassign->id;
  2021. }
  2022. if ($all_others_iassign_statement) {
  2023. foreach ($all_others_iassign_statement as $iassign) {
  2024. $iassignid = $iassign->id;
  2025. $COURSE->iassign_list[$iassignid] = new stdClass();
  2026. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2027. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2028. if (in_array($iassignid, $dependency))
  2029. $param->iassign_list[$iassignid] = 1;
  2030. else
  2031. $param->iassign_list[$iassignid] = 0;
  2032. if (in_array($iassignid, $array_dependency))
  2033. $COURSE->iassign_list[$iassignid]->enable = 0;
  2034. else
  2035. $COURSE->iassign_list[$iassignid]->enable = 1;
  2036. } // foreach ($all_others_iassign_statement as $iassign)
  2037. } // if ($all_others_iassign_statement)
  2038. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2039. $param->fileold = 0;
  2040. $param->filesid = 0;
  2041. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2042. $param->filename = '';
  2043. $param->grade = $iassign_statement_current->grade;
  2044. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2045. $param->timeavailable = $iassign_statement_current->timeavailable;
  2046. $param->timedue = $iassign_statement_current->timedue;
  2047. $param->preventlate = $iassign_statement_current->preventlate;
  2048. $param->test = $iassign_statement_current->test;
  2049. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2050. $param->position = $iassign_statement_current->position; // hidden
  2051. $param->visible = $iassign_statement_current->visible;
  2052. $param->max_experiment = $iassign_statement_current->max_experiment;
  2053. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2054. $param->show_answer = $iassign_statement_current->show_answer;
  2055. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2056. //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2057. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
  2058. if ($files) {
  2059. foreach ($files as $file) {
  2060. if ($file->get_filename() != '.') {
  2061. $param->filename = $file->get_filename();
  2062. $param->file = $file->get_id();
  2063. $param->fileold = $file->get_id();
  2064. $COURSE->iassign_file_id = $file->get_id();
  2065. }
  2066. }
  2067. }
  2068. //TODO //MOOC2014 -- inicio
  2069. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2070. //D if ($iassign_ilm_configs) {
  2071. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2072. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2073. //D } //MOOC2014 -- fim
  2074. } // if ($this_activity != null)
  2075. } // elseif ($this->action == 'edit')
  2076. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2077. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2078. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2079. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2080. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2081. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2082. $param->position = $total_of_activities;
  2083. // Create form and associate its data
  2084. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2085. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2086. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2087. if (isset($param->iassign_ilmid)) {
  2088. // array is additional atributes to 'form'
  2089. // 'special_param1 == 1' => script of iGeom : <select class="custom-select" name="special_param1" id="id_special_param1"> "Assignment with script(algorithm)? (Applicable only to iGeom iLM)"
  2090. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2091. }
  2092. else {
  2093. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2094. }
  2095. $mform->set_data($param); // define data in the form
  2096. if ($mform->is_cancelled()) {
  2097. $this->return_home_course('iassign_cancel');
  2098. exit;
  2099. }
  2100. else { // else if ($mform->is_cancelled())
  2101. $result = $mform->get_data();
  2102. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2103. if ($result) {
  2104. $result->context = $context;
  2105. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2106. $result->grade = 0;
  2107. if ($result->type_iassign == 1) {
  2108. $result->automatic_evaluate = 0;
  2109. $result->show_answer = 0;
  2110. }
  2111. elseif ($result->automatic_evaluate == 0)
  2112. $result->show_answer = 0;
  2113. // $_POST['iassign_list']
  2114. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2115. if ($result->iassign_list) {
  2116. foreach ($result->iassign_list as $key => $value)
  2117. $result->dependency .= $key . ';';
  2118. }
  2119. else
  2120. $result->dependency = 0;
  2121. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2122. //TODO Then get it directly from the form data $_POST!
  2123. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2124. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2125. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2126. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2127. if ($this->action == 'add') {
  2128. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2129. if ($iassign_statement_name) {
  2130. $this->return_home_course('error_iassign_name');
  2131. die();
  2132. }
  2133. // Really insert the new iActivity in table '*_iassign_statement'
  2134. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2135. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2136. // Trigger module viewed event.
  2137. $event = \mod_iassign\event\iassign_created::create(array(
  2138. 'objectid' => $iassignid,
  2139. 'context' => $context
  2140. ));
  2141. $event->add_record_snapshot('course', $this->course);
  2142. $event->trigger();
  2143. $this->return_home_course('iassign_add');
  2144. } // if ($this->action == 'add')
  2145. elseif ($this->action == 'edit') {
  2146. $iassignid = $this->activity->update_iassign($result);
  2147. $this->activity->update_calendar($iassignid, $result->oldname);
  2148. // Trigger module viewed event.
  2149. $event = \mod_iassign\event\iassign_updated::create(array(
  2150. 'objectid' => $iassignid,
  2151. 'context' => $context
  2152. ));
  2153. $event->add_record_snapshot('course', $this->course);
  2154. $event->trigger();
  2155. $this->return_home_course('iassign_update');
  2156. } // elseif ($this->action == 'edit')
  2157. die();
  2158. } // if ($result)
  2159. } // else if ($mform->is_cancelled())
  2160. print $OUTPUT->header();
  2161. $mform->display();
  2162. print $OUTPUT->footer();
  2163. die();
  2164. } // function add_edit_iassign()
  2165. /// Search for dependencies
  2166. function search_dependency ($search_iassing_id, $iassign_statement) {
  2167. global $DB, $OUTPUT;
  2168. $dependency = "";
  2169. if ($iassign_statement)
  2170. foreach ($iassign_statement as $iassign) {
  2171. $inter_dependency = explode(';', $iassign->dependency);
  2172. if (in_array($search_iassing_id, $inter_dependency)) {
  2173. $dependency .= $iassign->id . ";";
  2174. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2175. } // if (in_array($search_iassing_id, $inter_dependency))
  2176. } // foreach ($iassign_statement as $iassign)
  2177. return $dependency;
  2178. }
  2179. /// Search for "sub"dependency
  2180. function search_sub_dependency ($search_iassing_id) {
  2181. global $DB, $OUTPUT;
  2182. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2183. $dependency = "";
  2184. if ($iassign_statement) {
  2185. $inter_dependency = explode(';', $iassign_statement->dependency);
  2186. foreach ($inter_dependency as $tmp) {
  2187. if ($tmp != 0)
  2188. $dependency .= $tmp . ";";
  2189. $dependency .= $this->search_sub_dependency($tmp);
  2190. } // foreach ($inter_dependency as $tmp)
  2191. } // if ($iassign_statement)
  2192. return $dependency;
  2193. }
  2194. // Warning message
  2195. static function warning_message_iassign ($strcode) {
  2196. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2197. }
  2198. /// Update grade of iAssign
  2199. // Called always any iAssign activity is created
  2200. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2201. static function update_grade_iassign ($iassignid) {
  2202. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2203. require_once($CFG->libdir . '/gradelib.php');
  2204. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2205. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2206. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2207. // Each iAssign item is associated with one item on the "gradebook"
  2208. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2209. //$sum_grade = 0;
  2210. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2211. //foreach($grade as $tmp) {
  2212. // $sum_grade += $tmp->grade;
  2213. // }
  2214. //1 Solution 1
  2215. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2216. //1 $sum_grade = 0; //1
  2217. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2218. //2 Solution 2
  2219. $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
  2220. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2221. if (key($array_sum_grade))
  2222. $sum_grade = key($array_sum_grade); //2
  2223. else
  2224. $sum_grade = 0; //2
  2225. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2226. $grades = NULL;
  2227. $params_temp = array('itemname' => $grade_iassign->name);
  2228. $params_temp['iteminstance'] = $iassignid;
  2229. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2230. //2016 if ($sum_grade != 0) {
  2231. $params_temp['grademax'] = $sum_grade;
  2232. $params_temp['rawgrademax'] = $sum_grade;
  2233. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2234. $params_temp['grademin'] = 0;
  2235. // @calls /lib/gradelib.php: call to grade_item->insert()
  2236. //TODO: is there any error here in Moodle version 3.0?
  2237. //TODO: Incorrect property 'grademax' found when inserting grade object
  2238. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2239. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2240. }
  2241. /// Update grade of student
  2242. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2243. global $CFG, $DB, $OUTPUT;
  2244. require_once($CFG->libdir . '/gradelib.php');
  2245. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2246. // Review all the student submission for this iAssign activity
  2247. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2248. $total_grade = 0;
  2249. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2250. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2251. if ($iassign_submission)
  2252. $total_grade += $iassign_submission->grade;
  2253. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2254. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2255. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2256. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2257. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2258. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2259. $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
  2260. if (key($array_sum_grade))
  2261. $sum_grade = key($array_sum_grade); //2
  2262. else
  2263. $sum_grade = 0; //2
  2264. $grades['userid'] = $userid;
  2265. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2266. $params_temp = array('itemname' => $grade_iassign->name);
  2267. $params_temp['iteminstance'] = $iassignid;
  2268. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2269. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2270. $params_temp['grademax'] = $sum_grade;
  2271. $params_temp['rawgrademax'] = $sum_grade;
  2272. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2273. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2274. }
  2275. /// Display caption of icons - to the bottom page of teacher's report
  2276. function view_legend_icons () {
  2277. global $USER, $CFG, $DB, $OUTPUT;
  2278. $id = $this->cm->id;
  2279. if ($this->action == 'print')
  2280. print '<table border=1 width=100%><tr>';
  2281. else
  2282. print '<table width=100%><tr>';
  2283. print '<td >';
  2284. //leo 2021/12 cortes: /home/leo/projetos/iMA/lms/itarefa/novo/alteracoes_2021/locallib_view_legend_icons_antes_corte.php
  2285. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2286. if ($this->action != 'print') {
  2287. $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>\n";
  2288. $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>\n";
  2289. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2290. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2291. } // if ($this->action != 'print')
  2292. print '</tr></table>' . "\n";
  2293. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2294. print '</td></tr></table>' . "\n";
  2295. } // function view_legend_icons()
  2296. /// Display activity current
  2297. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2298. function view_iassign_current () {
  2299. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2300. $id = $this->cm->id;
  2301. $iassignid = $this->iassign->id;
  2302. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2303. $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
  2304. // 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 ...
  2305. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2306. if (!$iassign_statement_activity_item) {
  2307. print $OUTPUT->header();
  2308. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2309. print $OUTPUT->footer();
  2310. exit;
  2311. }
  2312. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2313. $ilm_name = '';
  2314. if ($ilm->ilm)
  2315. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2316. // 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
  2317. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2318. // log record
  2319. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2320. //Trigger module viewed event.
  2321. $event = \mod_iassign\event\submission_viewed::create(array(
  2322. 'objectid' => $iassign->id,
  2323. 'context' => $this->context,
  2324. 'other' => $info
  2325. ));
  2326. $event->add_record_snapshot('course', $this->course);
  2327. $event->trigger();
  2328. // Search of iLM data used in the current activity
  2329. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2330. // Add actual activity to navbar:
  2331. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2332. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2333. print $OUTPUT->header();
  2334. if ($this->action == 'viewsubmission') {
  2335. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2336. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2337. else
  2338. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2339. } else {
  2340. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2341. }
  2342. if ($iassign_submission)
  2343. $this->update_comment($iassign_submission->id);
  2344. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2345. $file = $iassign_statement_activity_item->id;
  2346. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2347. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2348. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2349. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2350. $this->bottonPost = 0; // hide submit button
  2351. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2352. $this->view_iassign = false; // disable visualization of activity
  2353. $repeat = "";
  2354. $last_iassign = "";
  2355. $student_answer = "";
  2356. $comment = "";
  2357. // *** Teacher access (view learner's submission)
  2358. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2359. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2360. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2361. // ---> access teacher for test
  2362. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2363. $this->bottonPost = 1;
  2364. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2365. $this->activity->view_dates();
  2366. $USER->iassignEdit = $this->bottonPost;
  2367. $this->activity->show_info_iassign();
  2368. if ($iassign_submission) {
  2369. //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;
  2370. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2371. } else {
  2372. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2373. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2374. }
  2375. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2376. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2377. // Prepare tags to present the iLM
  2378. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2379. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2380. // *** (end) Teacher access (view the activity)
  2381. // *** Teacher access (view learner's submission to the activity)
  2382. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2383. // It is teacher or 'nonediting teacher' that can evaluate
  2384. // ----> area teacher evaluate
  2385. $row = optional_param('row', 0, PARAM_INT);
  2386. $column = optional_param('column', 0, PARAM_INT);
  2387. $link_next = iassign_icons::insert('right_disable');
  2388. $link_previous = iassign_icons::insert('left_disable');
  2389. $link_up = iassign_icons::insert('up_disable');
  2390. $link_down = iassign_icons::insert('down_disable');
  2391. // next_activity
  2392. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2393. $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);
  2394. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2395. }
  2396. // previous_activity
  2397. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2398. $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);
  2399. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2400. }
  2401. // previous_student
  2402. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2403. $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);
  2404. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2405. }
  2406. // next_student
  2407. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2408. $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);
  2409. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2410. }
  2411. if ($iassign_submission) {
  2412. $student_answer = $iassign_submission->answer;
  2413. }
  2414. $last_iassign = get_string('last_iassign', 'iassign');
  2415. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2416. // Messages related to due date (and user role)
  2417. $this->activity->view_dates();
  2418. print $OUTPUT->box_start();
  2419. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2420. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2421. print $OUTPUT->user_picture($user_data);
  2422. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2423. print '</td>' . "\n";
  2424. print '<td width=20% align=right>' . "\n";
  2425. print '<table width=50 cellpadding="0">';
  2426. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2427. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2428. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2429. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2430. print '</table>' . "\n";
  2431. print '</td></tr></table>' . "\n";
  2432. print $OUTPUT->box_end();
  2433. print $OUTPUT->box_start();
  2434. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2435. print '<td width=60% valign="top">' . "\n";
  2436. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2437. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2438. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2439. $resp = get_string('yes');
  2440. else
  2441. $resp = get_string('no');
  2442. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2443. if ($iassign_statement_activity_item->show_answer == 1)
  2444. $resp = get_string('yes');
  2445. else
  2446. $resp = get_string('no');
  2447. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2448. print '</td>';
  2449. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2450. print '<td width=40% valign="top" align="left">';
  2451. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2452. // check status of solution sent by the student
  2453. if ($iassign_submission) {
  2454. switch ($iassign_submission->status) {
  2455. case 3 :
  2456. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2457. break;
  2458. case 2 :
  2459. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2460. break;
  2461. case 1 :
  2462. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2463. break;
  2464. default :
  2465. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2466. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2467. } // switch ($iassign_submission->status)
  2468. }
  2469. else { // if ($iassign_submission)
  2470. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2471. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2472. }
  2473. // update_status
  2474. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2475. $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);
  2476. print " <script type='text/javascript'>
  2477. //<![CDATA[
  2478. function overwriteStatus (newstatus) {
  2479. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2480. document.formEditStatus.return_status.value=newstatus;
  2481. document.formEditStatus.submit();
  2482. }
  2483. else
  2484. document.formEditStatus.return_status.value=-1;
  2485. }
  2486. //]]>
  2487. </script>";
  2488. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2489. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2490. 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";
  2491. print " <input type='hidden' name='return_status'>\n";
  2492. print "</form>\n";
  2493. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2494. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2495. $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);
  2496. print "
  2497. <script type='text/javascript'>
  2498. //<![CDATA[
  2499. function overwriteGrade (newgrade,maxgrade) {
  2500. if (newgrade<0 || newgrade>maxgrade) {
  2501. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2502. document.formEditGrade.return_grade.value=-1;
  2503. document.formEditGrade.submit();
  2504. }
  2505. else {
  2506. document.formEditGrade.return_grade.value=newgrade;
  2507. document.formEditGrade.submit();
  2508. }
  2509. }
  2510. //]]>
  2511. </script>";
  2512. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2513. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2514. print " <input type='text' name='grade' size='6'>";
  2515. print " <input type='hidden' name='return_grade'> ";
  2516. 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";
  2517. print "</form>";
  2518. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2519. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2520. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2521. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2522. if ($teacher)
  2523. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2524. } // if ($iassign_submission->experiment > 0)
  2525. print '</td>';
  2526. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2527. print '</tr></table>';
  2528. print $OUTPUT->box_end();
  2529. $USER->iassignEdit = $this->bottonPost;
  2530. print activity::toggle_columns_script();
  2531. if ($iassign_submission && $allow_resubmission) {
  2532. // Put the iLM to
  2533. print $OUTPUT->box_start();
  2534. print '<p><strong>' . $last_iassign . '</strong></p>';
  2535. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2536. $enderecoPOST = "";
  2537. // Prepare tags to present the iLM
  2538. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2539. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2540. print $OUTPUT->box_end();
  2541. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2542. // ATTENTION: exception used by iGeom (exercise with "script")
  2543. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2544. if (substr($ilm_name, 0, 5)=="igeom") {
  2545. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2546. $loadTeacherActivity = true;
  2547. }
  2548. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2549. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2550. print activity::toggle_columns_script();
  2551. // Prepare tags to present the iLM
  2552. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2553. }
  2554. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2555. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2556. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2557. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2558. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2559. // *** (end) Teacher access (view learner's submission to the activity)
  2560. // *** Student access (view the activity)
  2561. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2562. // It could be the learner (he could send or resend the activity)
  2563. // ---> access student
  2564. $time_now = time();
  2565. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2566. // activity of type example - not submit button for submission
  2567. $this->view_iassign = true;
  2568. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2569. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2570. // activity of type test - iLM automatic evaluator - submit button for submission
  2571. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2572. $this->bottonPost = 1;
  2573. $this->view_iassign = true;
  2574. } else
  2575. $this->view_iassign = false;
  2576. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2577. // activity of type exercise (learner can send his answer, if yet open...)
  2578. $this->view_iassign = true;
  2579. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2580. $this->view_iassign = false;
  2581. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2582. $this->bottonPost = 1; // allow the submit button
  2583. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2584. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2585. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2586. if (!$iassign_submission) {
  2587. $str_iassign_submission_id = '';
  2588. $str_iassign_submission_answer = '';
  2589. }
  2590. else {
  2591. $str_iassign_submission_id = $iassign_submission->id;
  2592. $str_iassign_submission_answer = $iassign_submission->answer;
  2593. }
  2594. if ($this->action != 'repeat') {
  2595. $repeat = "<a href='view.php?action=repeat&id="
  2596. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2597. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2598. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2599. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2600. }
  2601. $this->bottonPost = 1;
  2602. $this->write_solution = 1; // can register his submission
  2603. $student_answer = $str_iassign_submission_answer;
  2604. }
  2605. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2606. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2607. $last_iassign = get_string('last_iassign', 'iassign');
  2608. if ($iassign_submission) {
  2609. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2610. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2611. $student_answer = $iassign_submission->answer;
  2612. } else {
  2613. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2614. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2615. }
  2616. }
  2617. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2618. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2619. $this->bottonPost = 1;
  2620. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2621. } else {
  2622. $last_iassign = get_string('last_iassign', 'iassign');
  2623. if ($iassign_submission) {
  2624. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2625. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2626. $student_answer = $iassign_submission->answer;
  2627. } else {
  2628. // Symbol of "redo activity"
  2629. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2630. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2631. }
  2632. }
  2633. } // elseif ($iassign_statement_activity_item->test == 1)
  2634. elseif ($iassign_statement_activity_item->test == 0)
  2635. $this->view_iassign = false;
  2636. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2637. if ($iassign_submission)
  2638. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2639. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2640. else
  2641. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2642. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2643. $this->activity->view_dates();
  2644. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2645. print $OUTPUT->box_start();
  2646. print '<table width=100% border=0 valign="top">' . "\n";
  2647. print '<tr><td width=60% valign="top">' . "\n";
  2648. $flag_dependency = true;
  2649. if ($iassign_statement_activity_item->type_iassign == 3) {
  2650. if ($iassign_statement_activity_item->dependency == 0) {
  2651. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2652. } else {
  2653. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2654. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2655. foreach ($dependencys as $dependency) {
  2656. if ($dependency) {
  2657. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2658. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2659. if ($dependencysubmissions) {
  2660. if ($dependencysubmissions->status == 3)
  2661. $icon = iassign_icons::insert('correct');
  2662. elseif ($dependencysubmissions->status == 2) {
  2663. $icon = iassign_icons::insert('incorrect');
  2664. $flag_dependency = false;
  2665. } elseif ($dependencysubmissions->status == 1) {
  2666. $icon = iassign_icons::insert('post');
  2667. $flag_dependency = false;
  2668. } elseif ($dependencysubmissions->status == 0) {
  2669. $icon = iassign_icons::insert('not_post');
  2670. $flag_dependency = false;
  2671. }
  2672. } else {
  2673. $icon = iassign_icons::insert('not_post');
  2674. $flag_dependency = false;
  2675. } // if ($dependencysubmissions)
  2676. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2677. } // if ($dependency)
  2678. } // foreach ($dependencys as $dependency)
  2679. } // if ($iassign_statement_activity_item->dependency == 0)
  2680. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2681. if ($flag_dependency == false) {
  2682. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2683. $this->view_iassign = false;
  2684. print '</tr></table>' . "\n";
  2685. }
  2686. else {
  2687. $this->view_iassign = true;
  2688. print '</td>' . "\n";
  2689. } // if ($flag_dependency == false)
  2690. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2691. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2692. // receiver=1 - message to teacher
  2693. // receiver=2 - message to student
  2694. if ($iassign_submission) {
  2695. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2696. if ($verify_message)
  2697. $comment = iassign_icons::insert('comment_unread');
  2698. }
  2699. print '<td width=40% valign="top" align="left">';
  2700. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2701. if ($iassign_statement_activity_item->show_answer == 1) {
  2702. // check status of solution sent by the student
  2703. if ($iassign_submission) {
  2704. switch ($iassign_submission->status) {
  2705. case 3 :
  2706. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2707. break;
  2708. case 2 :
  2709. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2710. break;
  2711. case 1 :
  2712. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2713. break;
  2714. default :
  2715. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2716. $repeat = "";
  2717. $last_iassign = "";
  2718. } // switch ($iassign_submission->status)
  2719. } else {
  2720. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2721. $repeat = "";
  2722. $last_iassign = "";
  2723. }
  2724. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2725. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2726. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2727. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2728. if ($iassign_statement_activity_item->max_experiment == 0)
  2729. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2730. else {
  2731. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2732. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2733. $repeat = "";
  2734. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2735. $this->bottonPost = 0;
  2736. $this->write_solution = 0;
  2737. }
  2738. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2739. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2740. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2741. if ($teacher)
  2742. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2743. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2744. } // if ($iassign_statement_activity_item->show_answer==1)
  2745. else {
  2746. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2747. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2748. $repeat = "";
  2749. $last_iassign = "";
  2750. } elseif ($iassign_submission->status == 1) {
  2751. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2752. }
  2753. }
  2754. print '</td>';
  2755. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2756. print '</tr></table>' . "\n";
  2757. // Presents the iLM
  2758. print '<table width=100% border=0 valign="top">' . "\n";
  2759. print '<td width=80% align="left">';
  2760. 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\".
  2761. print '<td width=20% align="rigth">';
  2762. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2763. print $repeat; // symbol of "redo activity"
  2764. print '</td></tr></table>' . "\n";
  2765. //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)'
  2766. print activity::toggle_columns_script();
  2767. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2768. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2769. $output = '';
  2770. if (!$iassign_ilm) {
  2771. $iassign_ilm = new stdClass();
  2772. $iassign_ilm->file_jar = "";
  2773. }
  2774. $output .= $OUTPUT->box_start();
  2775. $USER->iassignEdit = $this->bottonPost;
  2776. // ---
  2777. // Presents the iLM
  2778. // Prepare tags to present the iLM
  2779. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2780. $student_answer = ""; //?
  2781. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2782. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2783. $student_answer = "";
  2784. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2785. } else {
  2786. // When student is redoing his activity
  2787. // ATTENTION: exception used by iGeom (exercise with "script")
  2788. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2789. if (substr($ilm_name, 0, 5)=="igeom") {
  2790. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2791. $loadTeacherActivity = true;
  2792. }
  2793. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2794. }
  2795. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2796. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2797. //1 $history_comment = '';
  2798. //1 if ($iassign_submission) {
  2799. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2800. //1 }
  2801. //1 if (!empty($history_comment)) {
  2802. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2803. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2804. //1 $output .= $history_comment;
  2805. //1 $output .= "</table>\n";
  2806. //1 }
  2807. //1 $output .= "</form></center>\n";
  2808. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2809. //1 }
  2810. $output .= $OUTPUT->box_end();
  2811. print $output;
  2812. } // if ($this->view_iassign)
  2813. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2814. } // if ($this->view_iassign)
  2815. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2816. else
  2817. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2818. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2819. print '<table width=100% border=0 valign="top">' . "\n";
  2820. print '<tr><td width=60% valign="top">' . "\n";
  2821. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2822. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2823. print '</tr></table>' . "\n";
  2824. $student_answer = "";
  2825. $enderecoPOST = "";
  2826. // Prepare tags to present the iLM
  2827. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2828. print $output;
  2829. }
  2830. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2831. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2832. 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
  2833. // Put a block with area to sent/answer comments
  2834. $output = '';
  2835. $history_comment = '';
  2836. $row = optional_param('row', 0, PARAM_INT);
  2837. $column = optional_param('column', 0, PARAM_INT);
  2838. if ($iassign_submission) {
  2839. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2840. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2841. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2842. }
  2843. else {
  2844. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2845. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2846. }
  2847. $output .= $OUTPUT->box_start();
  2848. //if (!empty($history_comment)) {
  2849. $output .= "<a id='comments'></a>";
  2850. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2851. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2852. $output .= "</table>";
  2853. print " <script type='text/javascript'>
  2854. //<![CDATA[
  2855. function submit_comment(url) {
  2856. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2857. var formData = new FormData();
  2858. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2859. var request = new XMLHttpRequest();
  2860. request.open('POST', url);
  2861. document.getElementById('comments_history').innerHTML = '';
  2862. request.onload = function (e) {
  2863. if (request.readyState === 4) {
  2864. if (request.status === 200) {
  2865. document.getElementById('comments_history').innerHTML = request.responseText;
  2866. document.getElementById('check-message-success').style.visibility = 'visible';
  2867. setTimeout(function(){
  2868. document.getElementById('check-message-success').style.visibility = 'hidden';
  2869. }, 3000);
  2870. }
  2871. }
  2872. };
  2873. document.formEnvioComment.submission_comment.value = '';
  2874. request.send(formData);
  2875. }
  2876. function event_text_area (event) {
  2877. if (event.ctrlKey && event.keyCode == 13)
  2878. submit_comment('" . $enderecoPOSTcomment . "');
  2879. }
  2880. //]]>
  2881. </script>";
  2882. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2883. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2884. $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
  2885. $output .= "</form> </center>\n";
  2886. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2887. // }
  2888. $output .= $OUTPUT->box_end();
  2889. print $output;
  2890. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2891. // final block 'studant'
  2892. print $OUTPUT->footer();
  2893. die();
  2894. } // function view_iassign_current()
  2895. /// Export the data from performance report into CSV file format
  2896. function export_csv () {
  2897. global $USER, $CFG, $DB, $OUTPUT;
  2898. $str = "";
  2899. $fields = "student_id, student_name";
  2900. // Finding all iassign activities for the iassign:
  2901. $id = $this->cm->id;
  2902. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2903. $c = 1;
  2904. foreach ($iassign_list as $iassign) {
  2905. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2906. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2907. $c++;
  2908. }
  2909. // Finding enrolled students:
  2910. $params_temp = array('shortname' => 'student');
  2911. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2912. $context = context_course::instance($this->course->id);
  2913. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2914. $students = $DB->get_records_sql(
  2915. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2916. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2917. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2918. foreach ($students as $student) {
  2919. $str .= $student->userid . ',';
  2920. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2921. foreach ($iassign_list as $iassign) {
  2922. $str .= ',' . $iassign->id . ',';
  2923. $str .= '"' . $iassign->name . '",';
  2924. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2925. if ($student_submissions) {
  2926. $str .= $student_submissions->experiment . ',';
  2927. $str .= $student_submissions->grade . ',';
  2928. switch ($student_submissions->status) {
  2929. case 3:
  2930. $str .= '"correct",';
  2931. break;
  2932. case 2:
  2933. $str .= '"incorrect",';
  2934. break;
  2935. case 1:
  2936. $str .= '"post",';
  2937. break;
  2938. case 0:
  2939. $str .= '"not_post",';
  2940. break;
  2941. }
  2942. }
  2943. else {
  2944. $str .= ',,"not_post",';
  2945. }
  2946. $str .= $iassign->iassign_ilmid . ',';
  2947. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2948. $str .= '"' . $ilm_activity->name . '"';
  2949. }
  2950. $str .= "\n";
  2951. }
  2952. $str = $fields . "\n" . $str;
  2953. header("Content-type: text/csv");
  2954. header("Content-disposition: attachment; filename=report.csv");
  2955. header("Pragma: no-cache");
  2956. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2957. header('Content-Length: ' . strlen($str));
  2958. header('Connection: close');
  2959. print $str;
  2960. flush();
  2961. } // function export_csv()
  2962. /// Display report of performance
  2963. function report () {
  2964. global $USER, $CFG, $DB, $OUTPUT;
  2965. $id = $this->cm->id;
  2966. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2967. if ($this->action != 'print') {
  2968. $title = get_string('report', 'iassign');
  2969. print $OUTPUT->header();
  2970. } // if ($this->action != 'print')
  2971. $this->print_main_menu();
  2972. print $OUTPUT->box_start();
  2973. $this->view_legend_icons();
  2974. print $OUTPUT->box_end();
  2975. if ($this->action == 'print')
  2976. print '<table border=1 width="100%">' . "\n";
  2977. else
  2978. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  2979. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2980. // $num = array();
  2981. $i = 1;
  2982. $num = array();
  2983. $stylebutton = "background: none; -webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75);box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.75); min-width: 4.5rem;";
  2984. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2985. $test_exercise = "";
  2986. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2987. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2988. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2989. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2990. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2991. $num[$i] = new stdClass();
  2992. $num[$i]->name = $iassign->name;
  2993. $num[$i]->id = $i;
  2994. $num[$i]->iassignid = $iassign->id;
  2995. print ' <tr >' . "\n";
  2996. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2997. print "<td class=\"cell c0 actvity\">";
  2998. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2999. print ' </tr>' . "\n";
  3000. $i++;
  3001. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3002. } // foreach ($iassign_list as $iassign)
  3003. $num_exerc = $i; // total of exercises
  3004. print "</table>";
  3005. print "<p></p>";
  3006. if ($this->action == 'print')
  3007. print '<table border=1 width="100%">' . "\n";
  3008. else // ./theme/boost/style/moodle.css: .generaltable
  3009. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3010. $context = context_course::instance($this->course->id);
  3011. if ($num_exerc > 1) {
  3012. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3013. $params_temp = array('shortname' => 'student');
  3014. $role = $DB->get_record_sql(
  3015. "SELECT s.id, s.shortname FROM {role} s " .
  3016. " WHERE s.shortname = :shortname", $params_temp);
  3017. // $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");
  3018. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3019. $students = $DB->get_records_sql(
  3020. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3021. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3022. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3023. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3024. $width = 90/$num_exerc;
  3025. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3026. $sum_iassign_correct[$j] = 0;
  3027. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3028. }
  3029. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3030. $sum_iassign = $j - 1;
  3031. print '</tr>' . "\n";
  3032. $total = 0;
  3033. $sum_student = 0;
  3034. $comment = iassign_icons::insert('comment_read');
  3035. $sum_comment = 0;
  3036. $sum_correct_iassign = array();
  3037. $sum_correct_student = array();
  3038. $USER->matrix_iassign = array();
  3039. if ($students) {
  3040. $w = 0;
  3041. foreach ($students as $tmp) { // count students
  3042. $users_array[$w] = $tmp;
  3043. $w++;
  3044. }
  3045. for ($x=0; $x<$w; $x++) { // for all students
  3046. print '<tr>' . "\n";
  3047. $sum_student++;
  3048. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3049. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3050. $total_student = 0;
  3051. $tentativas = 0;
  3052. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3053. $sum_comment = $sum_verify_message = 0;
  3054. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3055. if ($student_submissions) {
  3056. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3057. $tentativas = $student_submissions->experiment;
  3058. // Get student comments
  3059. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3060. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3061. $student_submissions_comment = $DB->get_record_sql(
  3062. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3063. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3064. if ($student_submissions_comment) // student has comment
  3065. foreach ($student_submissions_comment as $tmp)
  3066. $sum_comment = $tmp;
  3067. // informations to previous activities
  3068. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3069. else $iassign_previous = $num[$j - 1]->iassignid;
  3070. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3071. else $user_previous = $users_array[$x - 1]->userid;
  3072. // next
  3073. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3074. else $iassign_next = "-1";
  3075. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3076. else $user_next = "-1";
  3077. $position = "&row= $x&column=$j";
  3078. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3079. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3080. $url .= $position;
  3081. // receiver=1 - message to teacher
  3082. // receiver=2 - message to student
  3083. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3084. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3085. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3086. $verify_message = $DB->get_record_sql(
  3087. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3088. "WHERE iassign_submissionid = :iassign_submissionid " .
  3089. " AND return_status= :return_status " .
  3090. " AND receiver= :receiver", $params_temp);
  3091. if ($verify_message)
  3092. foreach ($verify_message as $tmp)
  3093. $sum_verify_message = $tmp;
  3094. if ($sum_verify_message > 0)
  3095. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3096. else
  3097. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3098. if ($student_submissions->status == 3) {
  3099. $sum_iassign_correct[$j]++;
  3100. $total_student++;
  3101. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3102. }
  3103. elseif ($student_submissions->status == 2) {
  3104. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3105. }
  3106. elseif ($student_submissions->status == 1) {
  3107. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3108. }
  3109. elseif ($student_submissions->status == 0) {
  3110. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3111. }
  3112. if ($this->action != 'print') {
  3113. if ($tentativas > 0)
  3114. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3115. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3116. . $feedback
  3117. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3118. . $tentativas
  3119. . '</span> </button>'
  3120. . '</a>' . "\n";
  3121. else
  3122. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3123. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3124. . $feedback
  3125. .'</button>'
  3126. . '</a>' . "\n";
  3127. if ($sum_comment > 0 && $sum_verify_message > 0)
  3128. print '<a href="' . $url . '"> '
  3129. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3130. . $comment
  3131. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3132. . $sum_verify_message . '/' . $sum_comment
  3133. . '</span> </button>'
  3134. . '</a>';
  3135. else if ($sum_comment > 0)
  3136. print '<a href="' . $url . '"> '
  3137. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3138. . $comment
  3139. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3140. . $sum_comment
  3141. . '</span> </button>'
  3142. . '</a>';
  3143. print '</td>' . "\n";
  3144. }
  3145. if ($this->action == 'print')
  3146. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3147. } // if ($student_submissions)
  3148. else { // if ($student_submissions)
  3149. // Student does not have any submission
  3150. // informations to browse previous activities
  3151. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3152. else $iassign_previous = $num[$j - 1]->iassignid;
  3153. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3154. else $user_previous = $users_array[$x - 1]->userid;
  3155. // next
  3156. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3157. else $iassign_next = "-1";
  3158. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3159. else $user_next = "-1";
  3160. $position = "&row= $x&column=$j";
  3161. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3162. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3163. $url .= $position;
  3164. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3165. if ($this->action == 'print')
  3166. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3167. else {
  3168. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3169. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3170. . $feedback
  3171. .'</button>'
  3172. . '</a>' . "\n";
  3173. // print '<td> &nbsp;</td>';
  3174. if ($sum_comment > 0)
  3175. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3176. // else print '<td> &nbsp;</td>';
  3177. print '</td>';
  3178. }
  3179. } // else if ($student_submissions)
  3180. $USER->matrix_iassign[$x][$j] = new stdClass();
  3181. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3182. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3183. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3184. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3185. if ($student_submissions)
  3186. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3187. else
  3188. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3189. //print '</td>' . "\n";
  3190. } // for ($j=1; $j<$num_exerc; $j++)
  3191. $total = $total + $total_student;
  3192. $porcentagem = ($total_student / ($j - 1)) * 100;
  3193. if ($tentativas != 0 && $tentativas != null) {
  3194. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3195. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3196. }
  3197. else {
  3198. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3199. }
  3200. print '</tr>' . "\n";
  3201. $sum_correct_student[$sum_student] = new stdClass();
  3202. $sum_correct_student[$sum_student]->name = $name;
  3203. $sum_correct_student[$sum_student]->sum = $total_student;
  3204. } // for ($x = 0; $x < $w; $x ++)
  3205. for ($i = 1; $i < $j; $i++) {
  3206. if (is_null($sum_iassign_correct[$i]))
  3207. $sum_iassign_correct[$i] = 0;
  3208. $sum_correct_iassign[$i] = new stdClass();
  3209. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3210. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3211. }
  3212. // print '</tr></table>' . "\n";
  3213. }
  3214. } // if ($i>1)
  3215. else {
  3216. print_string('no_activity', 'iassign');
  3217. }
  3218. print "</table>\n";
  3219. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3220. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3221. if ($this->action != 'print')
  3222. print $OUTPUT->footer();
  3223. die();
  3224. } // function report()
  3225. /// Display graphics of performance
  3226. function stats () {
  3227. global $USER, $CFG, $DB, $OUTPUT;
  3228. $id = $this->cm->id;
  3229. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3230. if ($this->action != 'printstats')
  3231. $title = get_string('graphic', 'iassign');
  3232. $num = array();
  3233. $sum_correct_iassign = array();
  3234. $sum_correct_student = array();
  3235. $sum_student = 0;
  3236. $i = 1;
  3237. foreach ($iassign_list as $iassign) {
  3238. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3239. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3240. $sum_iassign_correct[$i] = 0;
  3241. $num[$i] = new stdClass();
  3242. $num[$i]->name = $iassign->name;
  3243. $num[$i]->id = $i;
  3244. $num[$i]->iassignid = $iassign->id;
  3245. $i++;
  3246. } // if ($iassign->type_iassign == 3)
  3247. } // foreach ($iassign_list as $iassign)
  3248. $sum_iassign = $i - 1;
  3249. $context = context_course::instance($this->course->id);
  3250. if ($i > 1) {
  3251. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3252. $params_temp = array('shortname' => 'student');
  3253. $role = $DB->get_record_sql(
  3254. "SELECT s.id, s.shortname FROM {role} s " .
  3255. " WHERE s.shortname = :shortname", $params_temp);
  3256. // $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");
  3257. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3258. $students = $DB->get_records_sql(
  3259. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3260. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3261. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3262. $total = 0;
  3263. $sum_student = 0;
  3264. $j = 0;
  3265. $sum_correct_iassign = array();
  3266. $sum_correct_student = array();
  3267. $sum_experiment = array();
  3268. if ($students) {
  3269. foreach ($students as $users) {
  3270. $sum_student++;
  3271. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3272. // rows
  3273. $total_student = 0;
  3274. for ($j = 1; $j < $i; $j++) {
  3275. $total_experiment = 0;
  3276. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3277. if ($student_submissions) {
  3278. if ($student_submissions->status == 3) {
  3279. $sum_iassign_correct[$j]++;
  3280. $total_student++;
  3281. } // if ($student_submissions->status == 3)
  3282. $total_experiment += $student_submissions->experiment;
  3283. }
  3284. $sum_experiment[$j] = $total_experiment;
  3285. } // for ($j=1; $j<$i; $j++)
  3286. $total = $total + $total_student;
  3287. $sum_correct_student[$sum_student] = new stdClass();
  3288. $sum_correct_student[$sum_student]->name = $name;
  3289. $sum_correct_student[$sum_student]->sum = $total_student;
  3290. } // foreach ($students as $users)
  3291. }
  3292. for ($i = 1; $i < $j; $i++) {
  3293. if (is_null($sum_iassign_correct[$i]))
  3294. $sum_iassign_correct[$i] = 0;
  3295. $sum_correct_iassign[$i] = new stdClass();
  3296. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3297. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3298. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3299. } // for ($i = 1; $i < $j; $i++)
  3300. } // if ($i > 1)
  3301. print $OUTPUT->header();
  3302. $this->print_main_menu();
  3303. if ($this->action != 'printstats') {
  3304. $title = get_string('graphic', 'iassign');
  3305. $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>";
  3306. $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>";
  3307. print '<table width=100%><tr>';
  3308. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3309. print '<td width=15% align="right">' . $link_report . '</td>';
  3310. print '</td></tr></table>' . "\n";
  3311. print "<br><br>";
  3312. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3313. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3314. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3315. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3316. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3317. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3318. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3319. print '</tr>' . "\n";
  3320. $sum_correct = 0;
  3321. if ($sum_correct_iassign) {
  3322. foreach ($sum_correct_iassign as $iassign) {
  3323. if (is_null($iassign->experiment))
  3324. $iassign->experiment = 0;
  3325. $bar = "";
  3326. $sum = $iassign->sum;
  3327. $percent = ($sum / $sum_student) * 100;
  3328. $text = number_format($percent, 1) . '%';
  3329. $sum_correct += $sum;
  3330. if ($sum > 0) {
  3331. for ($i = 1; $i < $percent * 2; $i++)
  3332. $bar .= iassign_icons::insert('hbar_blue');
  3333. $bar .= iassign_icons::insert('hbar_blue_r');
  3334. } // if ($sum > 0)
  3335. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3336. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3337. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3338. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3339. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3340. print '</tr>' . "\n";
  3341. } // foreach ($sum_correct_iassign as $iassign)
  3342. }
  3343. print "</table>";
  3344. print "<br><br>";
  3345. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3346. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3347. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3348. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3349. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3350. print '</tr>' . "\n";
  3351. $sum_correct = 0;
  3352. foreach ($sum_correct_student as $student) {
  3353. $bar = "";
  3354. $sum = $student->sum;
  3355. $percent = ($sum / $sum_iassign) * 100;
  3356. $text = number_format($percent, 1) . '%';
  3357. $sum_correct += $sum;
  3358. if ($sum > 0) {
  3359. for ($i = 1; $i < $percent * 2; $i++)
  3360. $bar .= iassign_icons::insert('hbar_blue');
  3361. $bar .= iassign_icons::insert('hbar_blue_r');
  3362. } // if ($sum > 0)
  3363. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3364. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3365. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3366. print '</tr>' . "\n";
  3367. } // foreach ($sum_correct_student as $student)
  3368. print "</table>\n";
  3369. print "<br><br>\n";
  3370. $var = 0;
  3371. $cv = 0;
  3372. $dv = 0;
  3373. $avg = 0;
  3374. if ($sum_correct_student) {
  3375. $avg = $sum_correct / $sum_student;
  3376. if ($avg > 0) {
  3377. foreach ($sum_correct_student as $student)
  3378. $var += pow($student->sum - $avg, 2);
  3379. $var = $var / $sum_student;
  3380. $dv = sqrt($var);
  3381. $cv = ($dv / $avg) * 100;
  3382. }
  3383. }
  3384. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3385. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3386. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3387. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3388. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3389. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3390. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3391. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3392. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3393. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3394. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3395. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3396. print "</table>\n";
  3397. print $OUTPUT->footer();
  3398. } else {
  3399. print "<STYLE TYPE='text/css'>
  3400. <!--
  3401. .boldtable {
  3402. font-family:sans-serif;
  3403. font-size:10pt;
  3404. }
  3405. -->
  3406. </STYLE>\n";
  3407. print '<table border=1 width=100%>' . "\n";
  3408. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3409. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3410. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3411. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3412. print '</tr>' . "\n";
  3413. $sum_correct = 0;
  3414. foreach ($sum_correct_iassign as $iassign) {
  3415. $bar = "";
  3416. $sum = $iassign->sum;
  3417. $percent = ($sum / $sum_student) * 100;
  3418. $text = number_format($percent, 1) . '%';
  3419. $sum_correct += $sum;
  3420. if ($sum > 0) {
  3421. for ($i = 1; $i < $percent * 2; $i++)
  3422. $bar .= iassign_icons::insert('hbar_blue');
  3423. $bar .= iassign_icons::insert('hbar_blue_r');
  3424. } // if ($sum > 0)
  3425. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3426. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3427. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3428. print '</tr>' . "\n";
  3429. } // foreach ($sum_correct_iassign as $iassign)
  3430. print "</table>";
  3431. print "<br><br>";
  3432. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3433. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3434. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3435. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3436. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3437. print '</tr>' . "\n";
  3438. $sum_correct = 0;
  3439. foreach ($sum_correct_student as $student) {
  3440. $bar = "";
  3441. $sum = $student->sum;
  3442. $percent = ($sum / $sum_iassign) * 100;
  3443. $text = number_format($percent, 1) . '%';
  3444. $sum_correct += $sum;
  3445. if ($sum > 0) {
  3446. for ($i = 1; $i < $percent * 2; $i++)
  3447. $bar .= iassign_icons::insert('hbar_blue');
  3448. $bar .= iassign_icons::insert('hbar_blue_r');
  3449. } // if ($sum > 0)
  3450. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3451. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3452. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3453. print '</tr>' . "\n";
  3454. } // foreach ($sum_correct_student as $student)
  3455. print "</table>\n";
  3456. print "<br/><br/>\n";
  3457. $var = 0;
  3458. $cv = 0;
  3459. $dv = 0;
  3460. $avg = 0;
  3461. if ($sum_correct_student) {
  3462. $avg = $sum_correct / $sum_student;
  3463. if ($avg > 0) {
  3464. foreach ($sum_correct_student as $student)
  3465. $var += pow($student->sum - $avg, 2);
  3466. $var = $var / $sum_student;
  3467. $dv = sqrt($var);
  3468. $cv = ($dv / $avg) * 100;
  3469. }
  3470. }
  3471. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3472. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3473. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3474. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3475. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3476. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3477. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3478. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3479. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3480. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3481. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3482. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3483. print "</table>\n";
  3484. } // if ($this->action != 'printstats')
  3485. die();
  3486. }
  3487. /// Display graphics of performance for students
  3488. function stats_students () {
  3489. global $USER, $CFG, $DB, $OUTPUT;
  3490. $id = $this->cm->id;
  3491. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3492. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3493. $title = get_string('results', 'iassign');
  3494. $sum_correct = 0;
  3495. $sum_incorrect = 0;
  3496. $sum_post = 0;
  3497. $sum_nopost = 0;
  3498. $sum_iassign = count($iassign_statement_list);
  3499. $bar_nopost = "";
  3500. $bar_correct = "";
  3501. $bar_incorrect = "";
  3502. $bar_post = "";
  3503. $text_nopost = "";
  3504. $text_correct = "";
  3505. $text_incorrect = "";
  3506. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3507. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3508. if ($iassign_submission) {
  3509. if ($iassign_submission->status == 3)
  3510. $sum_correct++;
  3511. elseif ($iassign_submission->status == 2)
  3512. $sum_incorrect++;
  3513. elseif ($iassign_submission->status == 1)
  3514. $sum_post++;
  3515. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3516. $sum_nopost++;
  3517. } // if ($iassign_submission)
  3518. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3519. if ($sum_iassign > 0) {
  3520. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3521. $text_correct = number_format($percent_correct, 1) . '%';
  3522. }
  3523. if ($sum_correct > 0) {
  3524. for ($i = 1; $i < $percent_correct * 2; $i++)
  3525. $bar_correct .= iassign_icons::insert('hbar_green');
  3526. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3527. } // if ($sum_correct > 0)
  3528. if ($sum_iassign > 0) {
  3529. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3530. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3531. }
  3532. if ($sum_incorrect > 0) {
  3533. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3534. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3535. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3536. } // if ($sum_incorrect > 0)
  3537. if ($sum_iassign > 0) {
  3538. $percent_post = ($sum_post / $sum_iassign) * 100;
  3539. $text_post = number_format($percent_post, 1) . '%';
  3540. }
  3541. if ($sum_post > 0) {
  3542. for ($i = 1; $i < $percent_post * 2; $i++)
  3543. $bar_post .= iassign_icons::insert('hbar_blue');
  3544. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3545. } // if ($sum_post > 0)
  3546. if ($sum_iassign > 0) {
  3547. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3548. $text_nopost = number_format($percent_nopost, 1) . '%';
  3549. }
  3550. if ($sum_nopost > 0) {
  3551. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3552. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3553. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3554. } // if ($sum_nopost > 0)
  3555. print $OUTPUT->header();
  3556. $this->print_main_menu();
  3557. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3558. //2021/12 print '<table width=100%><tr>';
  3559. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3560. //2021/12 print '</td></tr></table>' . "\n";
  3561. print "<br/><br/>\n";
  3562. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3563. print '<tr><th colspan=3 class="header c1">' . "\n";
  3564. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3565. // $imagetext = '');
  3566. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3567. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3568. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3569. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3570. print '</tr>' . "\n";
  3571. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3572. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3573. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3574. print '</tr>' . "\n";
  3575. if ($sum_post) {
  3576. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3577. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3578. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3579. print '</tr>' . "\n";
  3580. } // if ($sum_post)
  3581. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3582. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3583. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3584. print '</tr>' . "\n";
  3585. print "</table>";
  3586. print "<br><br>";
  3587. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3588. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3589. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3590. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3591. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3592. $sum_grade = 0;
  3593. $sum_grade_student = 0;
  3594. $avg = 0;
  3595. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3596. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3597. if (!$iassign_submission) {
  3598. $iassign_submission = new stdClass();
  3599. $iassign_submission->grade = 0;
  3600. }
  3601. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3602. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3603. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3604. print '</tr>' . "\n";
  3605. $sum_grade += $iassign_statement_activity_item->grade;
  3606. $sum_grade_student += $iassign_submission->grade;
  3607. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3608. if ($sum_grade > 0)
  3609. $avg = $sum_grade_student / $sum_grade * 100;
  3610. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3611. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3612. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3613. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3614. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3615. print "</table>";
  3616. print $OUTPUT->footer();
  3617. die();
  3618. } // function stats_students()
  3619. function get_total_notifications () {
  3620. global $DB, $USER, $COURSE;
  3621. $total_messages = 0;
  3622. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3623. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3624. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3625. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3626. }
  3627. else {
  3628. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3629. $total_messages = $DB->get_record_sql("SELECT COUNT(*) AS total FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3630. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3631. }
  3632. return $total_messages->total;
  3633. }
  3634. function get_iassign_statement_messages () {
  3635. global $DB, $USER, $COURSE;
  3636. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3637. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3638. $totais = array();
  3639. $messages = $DB->get_records_sql("SELECT c.id AS commentid, st.id AS stid, s.userid AS user, ias.id AS iasid, s.id AS subid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3640. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3641. foreach($messages as $item) {
  3642. if (isset($totais[$item->subid])) {
  3643. $totais[$item->subid]->total++;
  3644. }
  3645. else {
  3646. $totais[$item->subid] = new stdclass();
  3647. $item->total = 1;
  3648. $totais[$item->subid] = $item;
  3649. }
  3650. }
  3651. return $totais;
  3652. }
  3653. else {
  3654. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3655. $totais = array();
  3656. $messages = $DB->get_records_sql("SELECT c.id as commentid, s.id AS subid, st.id AS stid, ias.id AS iasid, s.userid AS userid, st.name AS stname, ias.name AS iasname FROM {iassign_submission_comment} AS c, {iassign_submission} AS s, {iassign_statement} AS st, {iassign} AS ias "
  3657. . " WHERE c.return_status=0 AND c.receiver=:receiver AND c.iassign_submissionid=s.id AND s.userid=:userid AND s.iassign_statementid=st.id AND st.iassignid=ias.id AND ias.course=:course", $params);
  3658. foreach($messages as $item) {
  3659. if (isset($totais[$item->subid])) {
  3660. $totais[$item->subid]->total++;
  3661. }
  3662. else {
  3663. $totais[$item->subid] = new stdclass();
  3664. $item->total = 1;
  3665. $totais[$item->subid] = $item;
  3666. }
  3667. }
  3668. return $totais;
  3669. }
  3670. }
  3671. function view_notifications_teachers () {
  3672. global $OUTPUT, $USER, $DB;
  3673. $messages = $this->get_iassign_statement_messages();
  3674. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3675. // 1º. listar as mensagens recebidas no bloco atual:
  3676. $actual_block = $this->iassign->id;
  3677. $id = $this->cm->id;
  3678. $total_include = 0;
  3679. $activities_actual_block = array();
  3680. if ($messages)
  3681. foreach ($messages as $item)
  3682. if ($item->iasid == $actual_block)
  3683. if (!in_array($item->stid, $activities_actual_block))
  3684. array_push($activities_actual_block, $item->stid);
  3685. if ($activities_actual_block)
  3686. foreach ($activities_actual_block as $activity_id) {
  3687. $printed = false;
  3688. foreach ($messages as $item) {
  3689. if ($item->stid == $activity_id) {
  3690. if (!$printed) {
  3691. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3692. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3693. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3694. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3695. $printed = true;
  3696. }
  3697. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3698. $user = $DB->get_record('user', array('id' => $item->user));
  3699. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3700. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3701. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3702. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td>'
  3703. .'</tr>';
  3704. $total_include++;
  3705. }
  3706. }
  3707. print '</td></tr></table>';
  3708. }
  3709. print '</table>';
  3710. if (count($activities_actual_block) == 0) {
  3711. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3712. print '<hr class="my-4">';
  3713. }
  3714. if ($messages && $total_include == count($messages)) {
  3715. print $OUTPUT->footer();
  3716. return;
  3717. }
  3718. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3719. $iassign_ids = array();
  3720. if ($messages)
  3721. foreach ($messages as $item)
  3722. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3723. array_push($iassign_ids, $item->iasid);
  3724. foreach ($iassign_ids as $id_iassign) {
  3725. $printed = false;
  3726. $activities_in_block = array();
  3727. foreach ($messages as $subitem)
  3728. if ($subitem->iasid == $id_iassign)
  3729. if (!in_array($item->stid, $activities_in_block))
  3730. array_push($activities_in_block, $item->stid);
  3731. foreach ($messages as $item) {
  3732. if ($item->iasid == $id_iassign) {
  3733. if (!$printed) {
  3734. $printed = true;
  3735. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3736. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3737. }
  3738. foreach ($activities_in_block as $id_activity) {
  3739. $print = false;
  3740. foreach ($messages as $subitem) {
  3741. if ($subitem->stid == $id_activity) {
  3742. if (!$print) {
  3743. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3744. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3745. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3746. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3747. $print = true;
  3748. }
  3749. foreach ($messages as $comment_student) {
  3750. if ($comment_student->stid == $id_activity) {
  3751. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3752. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3753. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3754. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3755. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3756. '<td class="align-middle"> <a href="'.$submission_url.'#comments"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$comment_student->total.'</span> </span></a></td>'
  3757. .'</tr>';
  3758. }
  3759. }
  3760. break;
  3761. }
  3762. }
  3763. }
  3764. print '</table></td></tr></table>';
  3765. break;
  3766. }
  3767. }
  3768. }
  3769. print $OUTPUT->footer();
  3770. }
  3771. function view_notifications () {
  3772. global $OUTPUT, $USER;
  3773. print $OUTPUT->header();
  3774. $this->print_main_menu();
  3775. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3776. if ($this->get_total_notifications() == 0) {
  3777. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3778. print '<hr class="my-4">';
  3779. print $OUTPUT->footer();
  3780. return;
  3781. }
  3782. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3783. $this->view_notifications_teachers();
  3784. return;
  3785. }
  3786. $messages = $this->get_iassign_statement_messages();
  3787. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3788. // 1º. listar as mensagens recebidas no bloco atual:
  3789. $actual_block = $this->iassign->id;
  3790. $id = $this->cm->id;
  3791. $total_include = 0;
  3792. if ($messages)
  3793. foreach ($messages as $item) {
  3794. if ($item->iasid == $actual_block) {
  3795. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3796. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3797. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3798. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a></td></tr>';
  3799. $total_include++;
  3800. }
  3801. }
  3802. print '</table>';
  3803. if ($total_include == 0) {
  3804. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3805. print '<hr class="my-4">';
  3806. }
  3807. if ($messages && $total_include == count($messages)) {
  3808. print $OUTPUT->footer();
  3809. return;
  3810. }
  3811. print '<h4 class="mt-4 mb-3 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages_other_blocks', 'iassign').'</h4>';
  3812. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3813. $iassign_ids = array();
  3814. if ($messages)
  3815. foreach ($messages as $item)
  3816. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3817. array_push($iassign_ids, $item->iasid);
  3818. foreach ($iassign_ids as $id_iassign) {
  3819. $printed = false;
  3820. foreach ($messages as $item) {
  3821. if ($item->iasid == $id_iassign) {
  3822. if (!$printed) {
  3823. $printed = true;
  3824. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3825. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3826. }
  3827. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3828. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3829. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3830. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '</td><td class="align-middle"> <a href="'.$student_url.'"><span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $label . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$item->total.'</span> </span></a> </td></tr>';
  3831. }
  3832. }
  3833. print '</table>';
  3834. }
  3835. print $OUTPUT->footer();
  3836. }
  3837. function print_main_menu () {
  3838. global $USER;
  3839. $id = $this->cm->id;
  3840. $actual_action = optional_param('action', '', PARAM_TEXT);
  3841. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3842. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3843. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3844. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3845. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3846. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3847. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3848. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3849. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3850. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  3851. print '<div class="btn-group" role="group" aria-label="">';
  3852. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  3853. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  3854. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3855. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3856. // Has capability to see "report": teacher or up
  3857. print '<a href="'.$url_help.'" class="btn btn-outline-primary"><i class="fa fa-question-circle" aria-hidden="true"></i> '.get_string('help_ilm', 'iassign').'</a>';
  3858. print '<div class="btn-group"><div class="btn-group">
  3859. <a href="'.$url_report.'" class="btn btn-outline-primary '.($actual_action == 'report' || $actual_action == 'stats' || $actual_action == 'all_submissions' ? 'active' : '').' dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3860. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3861. <div class="dropdown-menu">
  3862. <a href="'.$url_report.'" class=" '.($actual_action == 'report' ? 'active' : ''). ' dropdown-item"><i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('home', 'iassign').'</a>
  3863. <div class="dropdown-divider"></div>
  3864. <a href="'.$url_sub_stats.'" class="dropdown-item '.($actual_action == 'stats' ? 'active' : '').'"><i class="fa fa-pie-chart" aria-hidden="true"></i> '.get_string('graphic', 'iassign') .'</a>
  3865. <div class="dropdown-divider"></div>
  3866. <a href="'.$url_all_submissions.'" class="dropdown-item '.($actual_action == 'all_submissions' ? 'active' : '').'"><i class="fa fa-files-o" aria-hidden="true"></i> '.get_string('all_submissions_manager', 'iassign') .'</a>
  3867. </div>
  3868. </div>
  3869. '; // "
  3870. print '<a href="'.$url_stats.'" class="btn btn-outline-primary '.($actual_action == 'stats_student' ? 'active' : '').'"><i class="fa fa-list" aria-hidden="true"></i> '.get_string('results', 'iassign').'</a>';
  3871. print '<a href="'.$url_auto_evaluate.'" class="btn btn-outline-primary '.($actual_action == 'auto_evaluate' ? 'active' : '').'"><i class="fa fa-check-square-o" aria-hidden="true"></i> '.get_string('auto_evaluate_name_config', 'iassign').'</a>';
  3872. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3873. $notifications = $this->get_total_notifications();
  3874. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  3875. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  3876. if ($notifications > 0)
  3877. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3878. print '</a></div><div class="btn-group">';
  3879. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3880. print '<a href="' . $url_add . '" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> ' . get_string('add_iassign', 'iassign') . "</a>\n";
  3881. print '
  3882. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3883. </button>
  3884. <div class="dropdown-menu">
  3885. <a class="dropdown-item" href="'.$url_import_activity.'">'.get_string('import_activity', 'iassign').'</a>
  3886. </div>'; // "
  3887. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3888. print '</div></div>' . "\n";
  3889. }
  3890. /// Display page of iAssign's block of activities
  3891. function view_iassigns () {
  3892. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3893. $id = $this->cm->id;
  3894. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3895. $notice = optional_param('notice', '', PARAM_TEXT);
  3896. if (strpos($notice, 'error'))
  3897. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3898. else if ($notice != '')
  3899. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3900. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  3901. print $OUTPUT->box_start();
  3902. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3903. print '<div class="border float-right">' . "\n";
  3904. if ($iassign_list) {
  3905. // $USER->iassignEdit == 0 view 'Turn editing off'
  3906. // $USER->iassignEdit == 1 view 'Turn editing on'
  3907. if (!isset($USER->iassignEdit))
  3908. $USER->iassignEdit = 0;
  3909. if ($USER->iassignEdit == 0) {
  3910. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3911. $botton = 1;
  3912. }
  3913. elseif ($USER->iassignEdit == 1) {
  3914. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3915. $botton = 0;
  3916. }
  3917. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3918. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3919. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  3920. print "</form>\n";
  3921. } // if ($iassign_list)
  3922. print "</div>\n";
  3923. }
  3924. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3925. // $this->view_legend_icons();
  3926. print $OUTPUT->box_end();
  3927. $iassign_array_exercise = array();
  3928. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  3929. $iassign_array_test = array();
  3930. $i_test = 0; // count total number of activities of type 'test' inside the block
  3931. $iassign_array_example = array();
  3932. $i_example = 0; // count total number of activities of type 'example' inside the block
  3933. $iassign_array_general = array();
  3934. $i_general = 0;
  3935. if ($iassign_list) {
  3936. if ($this->iassign->activity_group == 0) {
  3937. foreach ($iassign_list as $iassign) {
  3938. $iassign_array_general[$i_general] = $iassign;
  3939. $i_general++;
  3940. }
  3941. } // if ($this->iassign->activity_group == 0)
  3942. else {
  3943. foreach ($iassign_list as $iassign) {
  3944. if ($iassign->type_iassign == 3) {
  3945. $iassign_array_exercise[$i_exercise] = $iassign;
  3946. $i_exercise++;
  3947. } // if ($iassign->type_iassign == 3)
  3948. if ($iassign->type_iassign == 2) {
  3949. $iassign_array_test[$i_test] = $iassign;
  3950. $i_test++;
  3951. } // if ($iassign->type_iassign == 2)
  3952. if ($iassign->type_iassign == 1) {
  3953. $iassign_array_example[$i_example] = $iassign;
  3954. $i_example++;
  3955. } // if ($iassign->type_iassign == 1)
  3956. }
  3957. }
  3958. if ($iassign_array_exercise) {
  3959. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3960. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3961. }
  3962. if ($iassign_array_test) {
  3963. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3964. $this->show_iassign($title, $iassign_array_test, $i_test);
  3965. }
  3966. if ($iassign_array_example) {
  3967. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3968. $this->show_iassign($title, $iassign_array_example, $i_example);
  3969. }
  3970. if ($iassign_array_general) {
  3971. $title = "";
  3972. $this->show_iassign($title, $iassign_array_general, $i_general);
  3973. }
  3974. } else { // if ($iassign_list)
  3975. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3976. }
  3977. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3978. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3979. print $OUTPUT->box_start();
  3980. print '<table width=100% border=0><tr>' . "\n";
  3981. print '<td width=10% align="left">' . "\n";
  3982. print $link_report;
  3983. print '</td>' . "\n";
  3984. print '</tr></table>' . "\n";
  3985. print $OUTPUT->box_end();
  3986. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3987. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3988. print $OUTPUT->box_start();
  3989. print '<table width=100% border=0><tr>' . "\n";
  3990. print '<td align="left">' . "\n";
  3991. print $link_add;
  3992. print '</td>' . "\n";
  3993. print '</tr></table>' . "\n";
  3994. print $OUTPUT->box_end();
  3995. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3996. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3997. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3998. // $this->view_legend_icons();
  3999. } // function view_iassigns()
  4000. /// Display all iAssigns: the list of activities inside the iAssign block
  4001. // HTTP: ./mod/iassign/view.php?id= <$id>
  4002. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4003. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4004. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4005. print $OUTPUT->box_start();
  4006. print " <script type='text/javascript'>
  4007. //<![CDATA[
  4008. function validate_move () {
  4009. var radios = document.getElementsByName('iassign_destiny');
  4010. var formValid = false;
  4011. //alert('aqui validate_move()');
  4012. var i = 0;
  4013. while (!formValid && i < radios.length) {
  4014. if (radios[i].checked) formValid = true;
  4015. i++;
  4016. }
  4017. if (!formValid) {
  4018. document.getElementById('move_dest').classList.add('alert-danger');
  4019. }
  4020. return formValid;
  4021. }
  4022. var modal;
  4023. function load_move(id_ias) {
  4024. document.form_move_activity.iassign_current.value = id_ias;
  4025. modal.style.display = 'block';
  4026. var radios = document.getElementsByName('iassign_destiny');
  4027. var i = 0;
  4028. while (i < radios.length) {
  4029. radios[i].checked = false;
  4030. i++;
  4031. }
  4032. document.getElementById('move_dest').classList.remove('alert-danger');
  4033. }
  4034. function closeModal () {
  4035. modal.style.display = 'none';
  4036. }
  4037. function load_modal_elements () {
  4038. modal = document.getElementById('myModal');
  4039. var span = document.getElementById('close_modal');
  4040. span.onclick = function() {
  4041. modal.style.display = 'none';
  4042. }
  4043. window.onclick = function(event) {
  4044. if (event.target == modal) {
  4045. modal.style.display = 'none';
  4046. }
  4047. }
  4048. }
  4049. window.onload = load_modal_elements;
  4050. //]]>
  4051. </script>\n";
  4052. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4053. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4054. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4055. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4056. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4057. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4058. <input type='hidden' name='iassign_current' value='' />";
  4059. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4060. $section = $course_sections[0];
  4061. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4062. for ($k = 0; $k < count($ids_sections); $k++) {
  4063. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4064. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4065. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4066. if ($c_cm) {
  4067. if ($ccm->instance == $c_cm->instance) {
  4068. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4069. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4070. }
  4071. else {
  4072. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4073. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4074. }
  4075. }
  4076. }
  4077. $radio_buttons .= "</ul>";
  4078. }
  4079. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4080. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4081. </form>
  4082. </div></div> </div></div>\n";
  4083. print " <style>.modal {
  4084. display: none;
  4085. position: fixed;
  4086. z-index: 1;
  4087. left: 0;
  4088. top: 0;
  4089. width: 100%;
  4090. height: 100%;
  4091. overflow: scroll;
  4092. background-color: rgb(0,0,0);
  4093. background-color: rgba(0,0,0,0.4);
  4094. }
  4095. .modal-content {
  4096. background-color: #fefefe;
  4097. margin: 15% auto;
  4098. padding: 10px 10px;
  4099. border: 1px solid #888;
  4100. width: 50%;
  4101. }
  4102. #close_modal {
  4103. color: #aaa;
  4104. float: right;
  4105. font-size: 28px;
  4106. font-weight: bold;
  4107. margin-top: -15px;
  4108. margin-right: -3px;
  4109. }
  4110. #close_modal:hover,
  4111. #close_modal:focus {
  4112. color: black;
  4113. text-decoration: none;
  4114. cursor: pointer;
  4115. }
  4116. #modal_title {
  4117. min-height: 3rem;
  4118. color: initial;
  4119. background: initial;
  4120. font-size: 1.5rem;
  4121. line-height: 1.5;
  4122. padding: 15px;
  4123. border-bottom: 1px solid #e5e5e5;
  4124. }
  4125. .input_move {
  4126. width: 90%;
  4127. padding: 2px;
  4128. }
  4129. .input_move:hover {
  4130. background: #eff0ef;
  4131. }
  4132. </style>";
  4133. $action_links = "";
  4134. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4135. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4136. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4137. for ($j=0; $j<$total_of_activities; $j++) {
  4138. $iassign_current = $iassign_array[$j]->id;
  4139. // receiver=1 - message to teacher
  4140. // receiver=2 - message to student
  4141. $sum_comment = 0;
  4142. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4143. foreach ($iassign_submissions as $iassign_submission) {
  4144. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4145. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4146. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4147. if ($verify_message)
  4148. foreach ($verify_message as $tmp)
  4149. $sum_comment += $tmp;
  4150. } // foreach ($iassign_submissions as $iassign_submission)
  4151. if ($sum_comment == 0)
  4152. $comment_unread = "";
  4153. else {
  4154. $comment_unread_message = get_string('comment_unread', 'iassign');
  4155. if ($sum_comment == 1)
  4156. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4157. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4158. ' <span class="badge bg-danger ml-2" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message .
  4159. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4160. }
  4161. if ($j == $total_of_activities - 1)
  4162. $iassign_down = $iassign_array[$j]->id;
  4163. else
  4164. $iassign_down = $iassign_array[$j + 1]->id;
  4165. if ($j > 0)
  4166. $iassign_up = $iassign_array[$j - 1]->id;
  4167. else
  4168. $iassign_up = $iassign_array[$j]->id;
  4169. if ($iassign_array[$j]->visible == 0)
  4170. $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>\n";
  4171. else
  4172. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4173. $links .= $comment_unread;
  4174. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4175. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4176. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4177. $link_up = "<li class='page-item'><a href='view.php?action=up" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-up' aria-hidden='true'></i></a></li>\n";
  4178. if ($j==0) // first activity
  4179. $link_down = "<li class='page-item'><a href='view.php?action=firstdown" . $str_aux . "' class='page-link' title='" . get_string('move_down_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
  4180. else
  4181. $link_down = "<li class='page-item'><a href='view.php?action=down" . $str_aux . "' class='page-link' title='" . get_string('move_up_iassign', 'iassign') . "'><i class='fa fa-arrow-down' aria-hidden='true'></i></a></li>\n";
  4182. $link_delete = "<li class='page-item'><a href='view.php?action=delete" . $str_aux . "' class='page-link' title='" . get_string('delete_iassign', 'iassign') . "'><i class='fa fa-trash-o' aria-hidden='true'></i></a></li>\n";
  4183. $link_visible_hide = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('hide_iassign', 'iassign') . "'><i class='fa fa-eye' aria-hidden='true'></i></a></li>\n";
  4184. $link_visible_show = "<li class='page-item'><a href='view.php?action=visible" . $str_aux . "' class='page-link' title='" . get_string('show_iassign', 'iassign') . "'><i class='fa fa-eye-slash' aria-hidden='true'></i></a></li>\n";
  4185. $link_edit = "<li class='page-item'><a href='view.php?action=edit" . $str_aux . "' class='page-link' title='" . get_string('edit_iassign', 'iassign') . "'><i class='fa fa-pencil-square-o' aria-hidden='true'></i></a></li>\n";
  4186. $link_duplicate_activity = "<li class='page-item'><a href='view.php?action=duplicate_activity" . $str_aux . "' class='page-link' title='" . get_string('duplicate_iassign', 'iassign') . "'><i class='fa fa-clone' aria-hidden='true'></i></a></li>\n";
  4187. $link_move_activity = "<li class='page-item'><a href='#' onclick='load_move(" . $iassign_current . "); return false;' class='page-link' title='" . get_string('move_activity', 'iassign') . "'><i class='fa fa-sign-out' aria-hidden='true'></i></a></li>\n";
  4188. if (count($iassign_array) > 1) {
  4189. if ($j == 0)
  4190. $action_links .= $link_down;
  4191. elseif ($j == $total_of_activities - 1)
  4192. $action_links .= $link_up;
  4193. else
  4194. $action_links .= $link_up . $link_down;
  4195. } // if (count($iassign_array) > 1)
  4196. $action_links .= $link_edit . $link_delete;
  4197. if ($iassign_array[$j]->visible == 0)
  4198. $action_links .= $link_visible_show;
  4199. else
  4200. $action_links .= $link_visible_hide;
  4201. $action_links .= $link_duplicate_activity . $link_move_activity;
  4202. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4203. $action_links .= "</ul></nav>\n";
  4204. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $links . '</td><td class="align-middle">' . $action_links . "</td></tr>\n";
  4205. } // for ($j=0; $j<$total_of_activities; $j++)
  4206. print "</tbody></table>\n";
  4207. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4208. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4209. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4210. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4211. $corect_position = 1; //EXTRA: to detect (and fix it) 'iassign_statement.position' errors
  4212. for ($j=0; $j<$total_of_activities; $j++) {
  4213. if ($iassign_array[$j]->position!=$corect_position) { // ops, the current 'position' is wrong, fix it!
  4214. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $corect_position, $corect_position);
  4215. }
  4216. $corect_position++;
  4217. }
  4218. for ($j=0; $j<$total_of_activities; $j++) {
  4219. $icon_status = "";
  4220. $icon_comment = "";
  4221. if ($iassign_array[$j]->visible == 1) {
  4222. $iassign_current = $iassign_array[$j]->id;
  4223. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4224. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4225. $icon_status = "";
  4226. $icon_comment = "";
  4227. if ($iassign_submission) {
  4228. // receiver=1 - message to teacher
  4229. // receiver=2 - message to student
  4230. // $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");
  4231. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4232. $verify_message = $DB->get_record_sql(
  4233. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4234. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4235. if ($verify_message)
  4236. foreach ($verify_message as $tmp)
  4237. $sum_comment = $tmp;
  4238. if ($sum_comment > 0) {
  4239. $comment_unread_message = get_string('comment_unread', 'iassign');
  4240. if ($sum_comment == 1)
  4241. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4242. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4243. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4244. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4245. }
  4246. // $icon_comment = iassign_icons::insert('comment_unread');
  4247. if ($iassign_array[$j]->type_iassign == 3) {
  4248. if ($iassign_array[$j]->show_answer == 1) {
  4249. if ($iassign_submission->status == 3)
  4250. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign').'"></i>' . "\n";
  4251. elseif ($iassign_submission->status == 2)
  4252. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign').'"></i>' . "\n";
  4253. elseif ($iassign_submission->status == 1)
  4254. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4255. //2021/12 $icon_status = iassign_icons::insert('post');
  4256. elseif ($iassign_submission->status == 0)
  4257. $icon_status = '<i class="fa fa-question" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4258. } // if ($iassign_array[$j]->show_answer==1)
  4259. else {
  4260. if ($iassign_submission->status == 0)
  4261. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4262. $icon_status = iassign_icons::insert('not_post');
  4263. else
  4264. //TODO: $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4265. $icon_status = iassign_icons::insert('post');
  4266. }
  4267. } // if ($iassign_array[$j]->type_iassign == 3)
  4268. } // if ($iassign_submission)
  4269. elseif ($iassign_array[$j]->type_iassign == 3) {
  4270. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('not_post', 'iassign') . '"></i>' . "\n";
  4271. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4272. } // if ($iassign_array[$j]->type_iassign == 3)
  4273. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 0; text-align: center;">'. $icon_status .'</td><td style="white-space: nowrap; width: 1%; padding-right: 2rem; padding-left: 0.2rem;">'
  4274. . $links . '</td><td>'. $icon_comment.'</td></tr>' . "\n";
  4275. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4276. } // if ($iassign_array[$j]->visible == 1)
  4277. } // for ($j=0; $j<$total_of_activities; $j++)
  4278. print "</table>\n";
  4279. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4280. else if (isguestuser()) {
  4281. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4282. print '<table width=100% ><tr>' . "\n";
  4283. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4284. print '</tr></table>' . "\n";
  4285. for ($j=0; $j<$total_of_activities; $j++) {
  4286. $icon_status = "";
  4287. $icon_comment = "";
  4288. if ($iassign_array[$j]->visible == 1) {
  4289. $iassign_current = $iassign_array[$j]->id;
  4290. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4291. print '<p>' . $links . '</p>' . "\n";
  4292. } // if ($iassign_array[$j]->visible == 1)
  4293. }
  4294. }
  4295. print $OUTPUT->box_end();
  4296. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4297. /// Show message of return
  4298. function return_home_course ($message) {
  4299. //D global $DB, $OUTPUT;
  4300. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4301. //D echo $OUTPUT->box_start();
  4302. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4303. //D echo '<tr><td align="left"><strong>' . "\n";
  4304. //D print_string($message, 'iassign');
  4305. //D echo '</strong></td>' . "\n";
  4306. //D echo '<td width=20% align="right">' . "\n";
  4307. //D echo $link_return;
  4308. //D echo '</td></tr></table>' . "\n";
  4309. //D echo $OUTPUT->box_end();
  4310. //D // echo $OUTPUT->footer();
  4311. redirect(new moodle_url($this->return . '&notice=' . $message));
  4312. exit;
  4313. }
  4314. /// Search comment of activity
  4315. function search_comment_submission ($iassign_submissionid) {
  4316. global $USER, $DB, $OUTPUT, $COURSE;
  4317. // $context = context_course::instance($COURSE->id);
  4318. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4319. $colorEdit2 = "#d2e5fc";
  4320. $has_capability = 0;
  4321. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4322. $text = "";
  4323. if ($comments) {
  4324. $even = 1;
  4325. foreach ($comments as $tmp) {
  4326. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4327. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4328. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4329. // $text .= $tmp->comment . "</td></tr>";
  4330. //} else {
  4331. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4332. $avatar = new user_picture($user_data);
  4333. $avatar->courseid = $COURSE->id;
  4334. $avatar->link = true;
  4335. $user_picture = $OUTPUT->render($avatar);
  4336. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4337. if ($even) {
  4338. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  4339. $even = 0;
  4340. } else {
  4341. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  4342. $even = 1;
  4343. }
  4344. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4345. } // foreach ($comments as $tmp)
  4346. }
  4347. return $text;
  4348. }
  4349. /// Update comment of activity
  4350. function update_comment ($iassign_submissionid) {
  4351. global $USER, $DB, $OUTPUT;
  4352. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4353. $receiver = 1; // student message to teacher
  4354. else
  4355. $receiver = 2; // teacher message to student
  4356. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4357. if ($verify_message) {
  4358. foreach ($verify_message as $message) {
  4359. if ($message->receiver == $receiver) {
  4360. $newentry = new stdClass();
  4361. $newentry->id = $message->id;
  4362. $newentry->return_status = 1;
  4363. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4364. print_error('error_update', 'iassign');
  4365. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4366. } // if ($message->receiver == $receiver)
  4367. // Trigger module viewed event.
  4368. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4369. 'objectid' => $this->iassign->id,
  4370. 'context' => $this->context
  4371. ));
  4372. $event->add_record_snapshot('course', $this->course);
  4373. $event->trigger();
  4374. } // foreach ($verify_message as $message)
  4375. }
  4376. }
  4377. /// Record comment of activity
  4378. function write_comment_submission () {
  4379. global $USER, $CFG, $DB;
  4380. $id = $this->cm->id;
  4381. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4382. $row = optional_param('row', 0, PARAM_INT);
  4383. $column = optional_param('column', 0, PARAM_INT);
  4384. $sum_comment = 0;
  4385. $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);
  4386. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4387. $str1 = trim($submission_comment);
  4388. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4389. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4390. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4391. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4392. $receiver = 1; // student message to teacher
  4393. $this->action = 'view';
  4394. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4395. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4396. } else {
  4397. $receiver = 2; // teacher message to student
  4398. $this->action = 'viewsubmission';
  4399. //D $tousers = array(); //MOOC 2016
  4400. //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
  4401. }
  4402. //MOOC 2016: foi p/ 15 linhas acima:
  4403. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4404. // verificar se existe uma submissão para o exercício e aluno informados
  4405. if (!$iassign_submission) {
  4406. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4407. }
  4408. if (!$iassign_submission) {
  4409. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4410. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4411. $this->iassign_submission_current = $id_submission;
  4412. }
  4413. else {
  4414. $id_submission = $iassign_submission->id;
  4415. } // if (!$iassign_submission)
  4416. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4417. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4418. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4419. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4420. $comments = $DB->get_record_sql(
  4421. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4422. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4423. if ($comments)
  4424. foreach ($comments as $tmp)
  4425. $sum_comment = $tmp;
  4426. if ($sum_comment == 0) {
  4427. $newentry = new stdClass();
  4428. $newentry->iassign_submissionid = $id_submission;
  4429. $newentry->comment_authorid = $USER->id;
  4430. $newentry->timecreated = time();
  4431. $newentry->comment = $submission_comment;
  4432. $newentry->receiver = $receiver;
  4433. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4434. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4435. // Trigger module viewed event.
  4436. $event = \mod_iassign\event\submission_comment_created::create(array(
  4437. 'objectid' => $this->iassign->id,
  4438. 'context' => $this->context
  4439. ));
  4440. $event->add_record_snapshot('course', $this->course);
  4441. $event->trigger();
  4442. }
  4443. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4444. // if ($this->action=='viewsubmission') {
  4445. // echo $OUTPUT->header();
  4446. // $this->return_last('confirm_add_comment', $link_return);
  4447. // die;
  4448. // }
  4449. return true;
  4450. } // function write_comment_submission()
  4451. /// Writes a new submission
  4452. // The first student answer is under 'function get_answer()'
  4453. function new_submission ($iassignid, $id_user, $receiver) {
  4454. global $USER, $DB, $OUTPUT;
  4455. $newentry = new stdClass();
  4456. $newentry->iassign_statementid = $iassignid;
  4457. $newentry->userid = $id_user;
  4458. $newentry->timecreated = time();
  4459. $newentry->timemodified = time();
  4460. $newentry->answer = 0; // student only submit message
  4461. if ($receiver == 2) // teacher message to student (write id teacher)
  4462. $newentry->teacher = $USER->id;
  4463. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4464. return_home_course('error_insert_submissions');
  4465. else {
  4466. // Trigger module view event
  4467. $event = \mod_iassign\event\submission_created::create(array(
  4468. 'objectid' => $this->iassign->id,
  4469. 'context' => $this->context
  4470. ));
  4471. $event->add_record_snapshot('course', $this->course);
  4472. $event->trigger();
  4473. }
  4474. return $newentry->id;
  4475. }
  4476. /// Return to a specific address of page
  4477. function return_last ($message, $link_return) {
  4478. global $DB, $OUTPUT;
  4479. print $OUTPUT->box_start();
  4480. print '<table width=100% border=0 valign="top">' . "\n";
  4481. print '<tr><td align="left"><strong>' . "\n";
  4482. print_string($message, 'iassign');
  4483. print '</strong></td>' . "\n";
  4484. print '<td width=20% align="right">' . "\n";
  4485. print $link_return;
  4486. print '</td></tr></table>' . "\n";
  4487. print $OUTPUT->box_end();
  4488. print $OUTPUT->footer();
  4489. die();
  4490. } // function return_last($message, $link_return)
  4491. } // class iassign
  4492. /// Class for manage activities
  4493. class activity {
  4494. var $activity;
  4495. /// Constructor of class.
  4496. // @param int $id Id of activity
  4497. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4498. //D public function activity($id) { self::__construct($id); }
  4499. function __construct ($id) {
  4500. global $DB;
  4501. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4502. if (empty($this->activity))
  4503. $this->activity = null;
  4504. }
  4505. /// Get an activity
  4506. // @return NULL
  4507. function get_activity () {
  4508. if ($this->activity != null)
  4509. return $this->activity;
  4510. else
  4511. return null;
  4512. }
  4513. /// Delete interactive activities
  4514. function delete ($return) {
  4515. global $USER, $CFG, $DB, $OUTPUT;
  4516. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4517. print $OUTPUT->header();
  4518. $output .= $OUTPUT->box_start();
  4519. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4520. if ($iassign_submission_currents) {
  4521. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4522. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4523. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4524. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4525. $output .= $OUTPUT->box_end();
  4526. $output .= $OUTPUT->footer();
  4527. print $output;
  4528. die();
  4529. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4530. } // if ($iassign_submission_currents)
  4531. else
  4532. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  4533. $output .= '<table width=50% border=0>';
  4534. $output .= '<tr valign="top"><td>';
  4535. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  4536. $output .= '</td><td>';
  4537. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4538. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4539. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4540. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4541. $output .= "</form>\n";
  4542. $output .= '</td><td>';
  4543. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4544. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4545. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4546. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4547. $output .= "</form>\n";
  4548. $output .= '</td></tr></table>' . "\n";
  4549. $output .= $OUTPUT->box_end();
  4550. $output .= $OUTPUT->footer();
  4551. print $output;
  4552. } // function delete($return)
  4553. /// Function for confirm the delete of activity
  4554. // @param String $return Url of return
  4555. // @param Object $iassign Object content an activity
  4556. function deleteyes ($return, $iassign) {
  4557. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4558. $msg = '';
  4559. if (!empty($this->activity->id)) {
  4560. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4561. if ($iassign_submission_currents) {
  4562. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4563. foreach ($iassign_submission_currents as $iassign_submission)
  4564. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4565. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4566. } // if ($iassign_submission_currents)
  4567. }
  4568. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4569. // Remove all files associated to this activity:
  4570. $fs = get_file_storage();
  4571. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4572. $this->delete_calendar($this->activity->id);
  4573. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4574. iassign::update_grade_iassign($this->activity->iassignid);
  4575. if ($delete_iassign_current) {
  4576. $iassign->return_home_course('confirm_delete_iassign');
  4577. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4578. } else {
  4579. $iassign->return_home_course('error_confirm_delete_iassign');
  4580. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4581. }
  4582. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4583. }
  4584. } // function deleteyes($return, $iassign)
  4585. // Change fields 'iassign_statement.position' between 2 activities
  4586. // @calledby : class this->move_iassign($move_action, $target, $return)
  4587. // @calledby : class iassign show_iassign($title, $iassign_array, $total_of_activities) - this is used only to fix 'position' erros (e.g. {1,2,2,3} to {1,2,3,4})
  4588. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4589. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4590. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4591. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4592. //D echo "mover: id=" . $idFrom . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4593. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4594. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4595. print_error('error_update_move_iassign', 'iassign');
  4596. }
  4597. else if ($idFrom != $idTo) { // first update performed successfully - change second only if they are different
  4598. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4599. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4600. if (!$DB->update_record('iassign_statement', $newentry))
  4601. print_error('error_update_move_iassign', 'iassign');
  4602. }
  4603. }
  4604. /// Changes position of activities (between those inside a group of interactive activities)
  4605. // @param $move_action = must be "up" or "down"
  4606. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4607. function move_iassign ($move_action, $target, $return) {
  4608. global $DB, $OUTPUT;
  4609. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4610. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4611. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4612. if ($move_action=="firstdown") {
  4613. $final_position_source = 2;
  4614. $final_position_target = 1;
  4615. }
  4616. else
  4617. if ($move_action=="down") {
  4618. $final_position_target = $this->activity->position;
  4619. $final_position_source = $final_position_target + 1;
  4620. }
  4621. else
  4622. if ($move_action=="up") {
  4623. $final_position_target = $this->activity->position;
  4624. $final_position_source = $final_position_target - 1;
  4625. }
  4626. else { // error:
  4627. print_error('error_update_move_iassign', 'iassign');
  4628. exit;
  4629. }
  4630. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4631. redirect($return);
  4632. } // function move_iassign($move_action, $target, $return)
  4633. /// Enable or disable the display of interactive activities
  4634. function visible_iassign ($return) {
  4635. global $DB;
  4636. $newentry = new stdClass();
  4637. $newentry->id = $this->activity->id;
  4638. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4639. if (!$DB->update_record('iassign_statement', $newentry))
  4640. print_error('error_update_visible_iassign', 'iassign');
  4641. redirect($return);
  4642. }
  4643. /// Add news interactive activities (register in table 'iassign_statement')
  4644. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4645. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4646. function new_iassign ($param) {
  4647. global $DB;
  4648. $newentry = new stdClass();
  4649. $newentry->iassignid = $param->iassignid;
  4650. $newentry->name = $param->name;
  4651. $newentry->type_iassign = $param->type_iassign;
  4652. $newentry->store_all_submissions = $param->store_all_submissions;
  4653. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4654. $proposition = $param->proposition;
  4655. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4656. else $proposition_text = $proposition;
  4657. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4658. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4659. //TODO Then get it directly from the form data $_POST!
  4660. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4661. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4662. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4663. $newentry->author_name = $param->author_name;
  4664. $newentry->author_modified_name = $param->author_modified_name;
  4665. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4666. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4667. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4668. $newentry->grade = $param->grade;
  4669. $newentry->timemodified = time();
  4670. $newentry->timecreated = time();
  4671. if ($param->type_iassign == 1) {
  4672. $newentry->timedue = 0;
  4673. $newentry->timeavailable = 0;
  4674. } // if ($param->type_iassign == 1)
  4675. else {
  4676. $newentry->timedue = $param->timedue;
  4677. $newentry->timeavailable = $param->timeavailable;
  4678. }
  4679. $newentry->preventlate = $param->preventlate;
  4680. $newentry->test = $param->test;
  4681. $newentry->special_param1 = $param->special_param1;
  4682. $newentry->visible = $param->visible;
  4683. $newentry->position = $param->position;
  4684. $newentry->max_experiment = $param->max_experiment;
  4685. $newentry->dependency = $param->dependency;
  4686. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4687. $newentry->show_answer = $param->show_answer;
  4688. $id = $DB->insert_record("iassign_statement", $newentry);
  4689. if ($id) {
  4690. $component = 'mod_iassign';
  4691. $filearea = 'exercise';
  4692. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4693. $file = $fs->get_file_by_id($param->file);
  4694. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4695. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4696. //$itemid = $id;
  4697. // File already inserted in other context!
  4698. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4699. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4700. $updateentry = new stdClass();
  4701. $updateentry->id = $id;
  4702. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4703. $updateentry->filesid = $newfile->get_itemid();
  4704. if (!$DB->update_record("iassign_statement", $updateentry))
  4705. print_error('error_add', 'iassign');
  4706. if ($param->type_iassign == 3)
  4707. iassign::update_grade_iassign($param->iassignid);
  4708. //TODO iLM_HTML5 :: //MOOC2014
  4709. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4710. //D if ($iassign_ilm_configs) {
  4711. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4712. //D if ($iassign_ilm_config->param_type != 'static') {
  4713. //D $newentry = new stdClass();
  4714. //D $newentry->iassign_statementid = $id;
  4715. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4716. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4717. //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});
  4718. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4719. //D print_error('error_add_param', 'iassign');
  4720. //D }
  4721. //D }
  4722. //D }
  4723. // log event --------------------------------------------------------------------------------------
  4724. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4725. // log event --------------------------------------------------------------------------------------
  4726. return $id;
  4727. }
  4728. else
  4729. print_error('error_add', 'iassign');
  4730. } // function new_iassign($param)
  4731. /// Add the calendar entries for this iassign
  4732. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4733. // @return bool
  4734. static function add_calendar ($iassignid) {
  4735. global $DB, $CFG;
  4736. require_once($CFG->dirroot . '/calendar/lib.php');
  4737. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4738. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4739. $event = new stdClass();
  4740. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4741. $event->description = $iassign_statement_activity_item->name;
  4742. $event->courseid = $iassign->course;
  4743. $event->groupid = 0;
  4744. $event->userid = 0;
  4745. $event->modulename = 'iassign';
  4746. $event->instance = $iassign->id;
  4747. $event->eventtype = 'due';
  4748. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4749. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4750. calendar_event::create($event);
  4751. }
  4752. /// Update the calendar entries for this iassign
  4753. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4754. // @return bool
  4755. function update_calendar ($iassignid, $olddescription) {
  4756. global $DB, $CFG;
  4757. require_once($CFG->dirroot . '/calendar/lib.php');
  4758. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4759. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4760. $event = new stdClass();
  4761. $event->id = 0;
  4762. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4763. if ($events) {
  4764. foreach ($events as $value) {
  4765. if ($value->description == $olddescription) {
  4766. $event->id = $value->id;
  4767. }
  4768. }
  4769. }
  4770. if ($event->id != 0) {
  4771. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4772. $event->description = $iassign_statement_activity_item->name;
  4773. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4774. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4775. $calendarevent = calendar_event::load($event->id);
  4776. $calendarevent->update($event);
  4777. } else
  4778. $this->add_calendar($iassignid);
  4779. }
  4780. /// Update the calendar entries for this iassign
  4781. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4782. // @return bool
  4783. function delete_calendar ($iassignid) {
  4784. global $DB, $CFG;
  4785. require_once($CFG->dirroot . '/calendar/lib.php');
  4786. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4787. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4788. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4789. if ($events) {
  4790. foreach ($events as $value) {
  4791. if ($value->description == $iassign_statement_activity_item->name) {
  4792. $DB->delete_records('event', array('id' => $value->id));
  4793. }
  4794. }
  4795. }
  4796. }
  4797. /// Update interactive activities
  4798. function update_iassign ($param) {
  4799. global $DB;
  4800. $component = 'mod_iassign';
  4801. $filearea = 'exercise';
  4802. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4803. $file = $fs->get_file_by_id($param->file);
  4804. $fileold = $fs->get_file_by_id($param->fileold);
  4805. if ($param->file != $param->fileold) {
  4806. if ($fileold) {
  4807. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4808. foreach ($fileoldarea as $value) {
  4809. $value->delete();
  4810. }
  4811. }
  4812. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4813. $itemid = $file->get_itemid() + $param->iassign_id;
  4814. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4815. $param->file = $newfile->get_itemid();
  4816. }
  4817. else
  4818. $param->file = $file->get_itemid();
  4819. }
  4820. else {
  4821. $param->file = $file->get_itemid();
  4822. }
  4823. $newentry = new stdClass();
  4824. $newentry->id = $param->iassign_id;
  4825. $newentry->name = $param->name;
  4826. $newentry->type_iassign = $param->type_iassign;
  4827. $newentry->store_all_submissions = $param->store_all_submissions;
  4828. //2019 $newentry->proposition = $param->proposition;
  4829. $proposition = $param->proposition;
  4830. if (is_array($proposition))
  4831. $proposition_text = $proposition['text'];
  4832. else
  4833. $proposition_text = $proposition;
  4834. $newentry->proposition = $proposition_text;
  4835. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4836. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4837. $newentry->grade = $param->grade;
  4838. $newentry->author_modified_name = $param->author_modified_name;
  4839. $newentry->timemodified = time();
  4840. if ($param->type_iassign == 1) {
  4841. $newentry->timedue = 0;
  4842. $newentry->timeavailable = 0;
  4843. } // if ($param->type_iassign == 1)
  4844. else {
  4845. $newentry->timedue = $param->timedue;
  4846. $newentry->timeavailable = $param->timeavailable;
  4847. }
  4848. $newentry->preventlate = $param->preventlate;
  4849. $newentry->test = $param->test;
  4850. if (isset($param->special_param1))
  4851. $newentry->special_param1 = $param->special_param1;
  4852. else
  4853. $newentry->special_param1 = NULL;
  4854. $newentry->visible = $param->visible;
  4855. $newentry->max_experiment = $param->max_experiment;
  4856. $newentry->dependency = $param->dependency;
  4857. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4858. $newentry->show_answer = $param->show_answer;
  4859. if (!$DB->update_record("iassign_statement", $newentry))
  4860. print_error('error_update', 'iassign');
  4861. if ($param->type_iassign == 3) {
  4862. iassign::update_grade_iassign($param->iassignid);
  4863. }
  4864. //$id = $newentry->id; // MOOC 2016 --- inicio
  4865. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4866. //if ($iassign_activity_item_configs) {
  4867. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4868. // $newentry = new stdClass();
  4869. // $newentry->id = $iassign_activity_item_config->id;
  4870. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4871. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4872. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4873. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4874. // print_error('error_edit_param', 'iassign');
  4875. // }
  4876. // } // MOOC 2016 --- final
  4877. // log event --------------------------------------------------------------------------------------
  4878. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4879. // log event --------------------------------------------------------------------------------------
  4880. return $newentry->id;
  4881. // if ($param->type_iassign==3)
  4882. // $this->update_grade_iassign($param->iassignid);
  4883. } // function update_iassign($param)
  4884. /// Show information of activity
  4885. function show_info_iassign () {
  4886. global $DB, $OUTPUT;
  4887. $output = '';
  4888. if ($this->activity->type_iassign == 3) {
  4889. if ($this->activity->dependency == 0) {
  4890. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4891. } else {
  4892. $dependencys = explode(';', $this->activity->dependency);
  4893. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4894. foreach ($dependencys as $dependency) {
  4895. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4896. if ($dependencyiassign)
  4897. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4898. } // foreach ($dependencys as $dependency)
  4899. } // if ($iassign_statement_activity_item->dependency == 0)
  4900. if ($this->activity->max_experiment == 0)
  4901. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4902. else
  4903. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4904. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4905. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4906. $output .= $this->toggle_columns_script();
  4907. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4908. print $OUTPUT->box($output);
  4909. } // function show_info_iassign()
  4910. /// Provide script to toggle columns
  4911. static function toggle_columns_script () {
  4912. $output = "";
  4913. $output .= '<script>
  4914. function toLeft () {
  4915. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4916. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4917. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4918. document.getElementById("columnsbutton").style.color = "#1da075";
  4919. }
  4920. function toDefault () {
  4921. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4922. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4923. document.getElementById("fullscreen").style.marginTop = "0";
  4924. document.getElementById("columnsbutton").style.color = "#343a40";
  4925. }
  4926. var activate = false;
  4927. function toggleColumns () {
  4928. if (activate) {
  4929. activate = false;
  4930. toDefault();
  4931. } else {
  4932. activate = true;
  4933. toLeft();
  4934. }
  4935. }
  4936. </script>'; // '
  4937. $output .= '<span tabindex="0" data-toggle="tooltip" title="'.get_string('enable_disable_columns', 'iassign').'" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4938. return $output;
  4939. }
  4940. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the gratest grade?
  4941. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  4942. $item = NULL;
  4943. foreach ($iassign_statement as $item) ; // get the last item!
  4944. if ($item) return $item; // return the last one
  4945. return NULL;
  4946. }
  4947. /// Shows date of opening and closing activities
  4948. function view_dates () {
  4949. global $USER, $CFG, $DB, $OUTPUT;
  4950. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4951. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4952. $status_iassign = "";
  4953. $status_iassign1 = "";
  4954. $status_iassign2 = "";
  4955. if ($this->activity->type_iassign == 1) // activity of type example
  4956. $type_iassign = get_string('example_iassign', 'iassign');
  4957. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4958. $type_iassign = get_string('test_iassign', 'iassign');
  4959. if ($this->activity->timeavailable > time()) {
  4960. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4961. } elseif ($this->activity->timedue < time()) {
  4962. $status_iassign = get_string('last_timedue', 'iassign');
  4963. }
  4964. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4965. $type_iassign = get_string('exercise_iassign', 'iassign');
  4966. if ($this->activity->timeavailable > time()) {
  4967. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4968. } elseif ($this->activity->timedue < time()) { // after delivery
  4969. $status_iassign = get_string('last_timedue', 'iassign');
  4970. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4971. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4972. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4973. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4974. if ($this->activity->test == 1) // allowed to test after of deadline
  4975. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4976. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4977. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4978. } // elseif ($iassign_statement_activity_item->test == 0)
  4979. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4980. } // elseif ($iassign_statement_activity_item->timedue < time())
  4981. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4982. $output = '<table width=100% >' . "\n";
  4983. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4984. $output .= '<tr>' . "\n";
  4985. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4986. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4987. //leo $output .= '<td width=80%>' . $type_iassign;
  4988. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4989. // $output .= '</td>' . "\n";
  4990. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4991. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  4992. $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>";
  4993. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4994. }
  4995. else {
  4996. // Get all previous/next solution sent by this student (present link to his last answer)
  4997. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4998. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  4999. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  5000. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  5001. $link_next = "";
  5002. $link_previous = "";
  5003. if ($iassign_previous) { // previous_activity
  5004. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5005. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5006. }
  5007. if ($iassign_next) { // next_activity
  5008. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5009. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5010. }
  5011. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5012. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5013. $output .= '</tr></table>' . "\n";
  5014. $output .= '<table width=100% >' . "\n";
  5015. if ($this->activity->type_iassign > 1) {
  5016. if ($this->activity->timeavailable)
  5017. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5018. if ($this->activity->timedue)
  5019. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5020. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5021. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5022. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5023. $output .= '</table>' . "\n";
  5024. print $OUTPUT->box($output);
  5025. } // function view_dates()
  5026. } // class activity
  5027. /// Class to manage Interactive Learning Module (iLM)
  5028. class ilm {
  5029. var $ilm;
  5030. /// Constructor of class
  5031. // @param int $id Id of iLM
  5032. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5033. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5034. function __construct ($id) {
  5035. global $DB;
  5036. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5037. if (empty($this->ilm))
  5038. $this->ilm = null;
  5039. }
  5040. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5041. // @calledby view_iassign_current()
  5042. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5043. global $USER, $CFG, $DB;
  5044. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5045. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5046. $typec = strtolower($iassign_ilm->type);
  5047. require_once 'ilm_handlers/' . $typec . '.php';
  5048. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5049. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5050. return $retorno;
  5051. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5052. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5053. // @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);
  5054. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5055. // @param Object $file File in use in activity
  5056. // @return int Return the id of log
  5057. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5058. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5059. $newentry = new stdClass();
  5060. $newentry->iassign_statementid = $iassign_activity_itemid;
  5061. $newentry->userid = $USER->id;
  5062. $newentry->filesid = $content_or_id_from_ilm_security;
  5063. $newentry->timecreated = time();
  5064. $newentry->view = 1;
  5065. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5066. if (!$id_iLM_security) {
  5067. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5068. } // from (!$DB->insert_record("iassign_security", $newentry))
  5069. return $id_iLM_security;
  5070. }
  5071. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5072. // @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);
  5073. // @param int $userid
  5074. // @param int $iassign_activity_itemid Id of iassign statement
  5075. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5076. global $DB;
  5077. // 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")
  5078. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5079. }
  5080. } // class ilm
  5081. /// Class to manage settings of iLM.
  5082. class ilm_settings {
  5083. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5084. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5085. // @param int $ilm_id Id of iLM
  5086. // @param array $options An array with options for create dynamic tag html APPLET
  5087. // @return string Return with a tag html APPLET created
  5088. static function build_ilm_tags ($ilm_id, $options = array()) {
  5089. global $DB;
  5090. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5091. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5092. $typec = strtolower($iassign_ilm->type);
  5093. require_once 'ilm_handlers/' . $typec . '.php';
  5094. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5095. return $retorno;
  5096. } // static function build_ilm_tags($ilm_id, $options = array())
  5097. /// Function for get modified date of iLM file
  5098. // @param string $file_jar String with Ids of iLM files
  5099. // @return string Return with the filenames and modified date
  5100. static function applet_filetime ($file_jar) {
  5101. $filetime = "";
  5102. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5103. $files_jar = explode(",", $file_jar);
  5104. foreach ($files_jar as $one_file) {
  5105. $file = $fs->get_file_by_id($one_file);
  5106. if ($file)
  5107. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5108. }
  5109. return $filetime;
  5110. }
  5111. /// Function for verify an default applet
  5112. // @param String $file_jar String containing an list de ids of applet files
  5113. // @return boolean Return true or fale if applet is default
  5114. static function applet_default ($file_jar) {
  5115. $is_default = true;
  5116. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5117. $files_jar = explode(",", $file_jar);
  5118. foreach ($files_jar as $one_file) {
  5119. $file = $fs->get_file_by_id($one_file);
  5120. if ($file)
  5121. $is_default &= ($file->get_itemid() == 0);
  5122. }
  5123. return $is_default;
  5124. }
  5125. /// Function for get form variables for add, edit, or copy iLM
  5126. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  5127. // @see settings_form.php
  5128. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5129. // @param int $ilm_id Id of iLM
  5130. // @param string $action String with the action
  5131. // @return object Return an object with forms variables
  5132. static function add_edit_copy_ilm ($ilm_id, $action) {
  5133. global $USER, $DB, $CFG;
  5134. require_once('settings_form.php'); // put the form
  5135. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5136. $param = new stdClass();
  5137. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  5138. $param->action = $action;
  5139. $param->ilm_id = $ilm_id;
  5140. $CFG->action_ilm = $action;
  5141. $CFG->ilm_id = $ilm_id;
  5142. if ($action == 'add') {
  5143. $param->title = get_string('add_ilm', 'iassign');
  5144. $param->name = "";
  5145. $param->version = "";
  5146. $param->url = "";
  5147. $param->description = "";
  5148. $param->extension = "";
  5149. $param->author = $USER->id;
  5150. $param->file_jar = "";
  5151. $param->file_jar_static = "";
  5152. $param->file_class = "";
  5153. $param->width = 800;
  5154. $param->height = 600;
  5155. $param->enable = 0; // 0 - hide / 1 - show
  5156. $param->timecreated = time();
  5157. $param->timemodified = time();
  5158. $param->evaluate = 0;
  5159. $param->parent = 0;
  5160. }
  5161. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5162. if ($iassign_ilm) {
  5163. $description = json_decode($iassign_ilm->description);
  5164. $param->title = get_string('edit_ilm', 'iassign');
  5165. $param->id = $iassign_ilm->id;
  5166. $param->name_ilm = $iassign_ilm->name;
  5167. $param->name = $iassign_ilm->name;
  5168. $param->version = $iassign_ilm->version;
  5169. $param->ilm_type = $iassign_ilm->type;
  5170. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5171. $param->url = $iassign_ilm->url; // iLM official URL
  5172. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5173. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5174. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5175. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5176. if (!isset($description->{current_language()})) {
  5177. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5178. else
  5179. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5180. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5181. }
  5182. else
  5183. $param->description = $description->{current_language()};
  5184. $param->description_lang = $iassign_ilm->description;
  5185. $param->extension = $iassign_ilm->extension;
  5186. $param->author = $iassign_ilm->author;
  5187. $param->file_jar = $iassign_ilm->file_jar;
  5188. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5189. $param->file_class = $iassign_ilm->file_class;
  5190. $param->width = $iassign_ilm->width;
  5191. $param->height = $iassign_ilm->height;
  5192. $param->enable = $iassign_ilm->enable;
  5193. $param->timecreated = $iassign_ilm->timecreated;
  5194. $param->timemodified = time();
  5195. $param->evaluate = $iassign_ilm->evaluate;
  5196. $param->parent = $iassign_ilm->parent;
  5197. }
  5198. }
  5199. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5200. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5201. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5202. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5203. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5204. // echo "Sem dados<br/>"; exit;
  5205. return;
  5206. }
  5207. $description = json_decode($iassign_ilm->description);
  5208. if ($iassign_ilm) {
  5209. if ($iassign_ilm->parent == 0)
  5210. $iassign_ilm->parent = $ilm_id;
  5211. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5212. $param->title = get_string('new_version_ilm', 'iassign');
  5213. $param->name_ilm = $iassign_ilm->name;
  5214. $param->name = $iassign_ilm->name;
  5215. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5216. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5217. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5218. $param->ilm_type = $iassign_ilm->type;
  5219. $param->url = $iassign_ilm->url;
  5220. $param->description = $description->{current_language()};
  5221. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5222. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5223. $param->extension = $iassign_ilm->extension;
  5224. $param->author = $USER->id;
  5225. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5226. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5227. $param->file_jar_static = '';
  5228. $param->file_class = $iassign_ilm->file_class;
  5229. $param->width = $iassign_ilm->width;
  5230. $param->height = $iassign_ilm->height;
  5231. $param->enable = 0;
  5232. $param->timecreated = time();
  5233. $param->timemodified = time();
  5234. $param->evaluate = $iassign_ilm->evaluate;
  5235. $param->parent = $iassign_ilm->parent;
  5236. }
  5237. }
  5238. elseif ($action == 'copy') {
  5239. $description = json_decode($iassign_ilm->description);
  5240. if ($iassign_ilm) {
  5241. if ($iassign_ilm->parent == 0)
  5242. $iassign_ilm->parent = $ilm_id;
  5243. $param->title = get_string('copy_ilm', 'iassign');
  5244. $param->id = $iassign_ilm->id;
  5245. $param->name_ilm = $iassign_ilm->name;
  5246. $param->name = $iassign_ilm->name;
  5247. $param->version = "";
  5248. $param->ilm_type = $iassign_ilm->type;
  5249. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5250. $param->url = $iassign_ilm->url;
  5251. $param->description = $description->{current_language()};
  5252. $param->description_lang = $iassign_ilm->description;
  5253. $param->extension = $iassign_ilm->extension;
  5254. $param->author = $USER->id;
  5255. $param->file_jar = '';
  5256. $param->file_jar_static = '';
  5257. $param->file_class = $iassign_ilm->file_class;
  5258. $param->width = $iassign_ilm->width;
  5259. $param->height = $iassign_ilm->height;
  5260. $param->enable = 0;
  5261. $param->timecreated = time();
  5262. $param->timemodified = time();
  5263. $param->evaluate = $iassign_ilm->evaluate;
  5264. $param->parent = $iassign_ilm->parent;
  5265. }
  5266. }
  5267. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5268. //D var_dump(debug_backtrace());
  5269. //D print_r(debug_backtrace());
  5270. return $param;
  5271. } // static function add_edit_copy_ilm($ilm_id, $action)
  5272. /// Function for save iLM file in moodledata
  5273. // @param int $itemid Itemid of file save in draft (upload file)
  5274. // @param int $ilm_id Id of iLM
  5275. // @return string Return an string with ids of iLM files
  5276. static function new_file_ilm ($itemid, $iassign_ilm) {
  5277. global $CFG, $USER, $DB;
  5278. $return = null;
  5279. $file_jar = array();
  5280. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5281. $contextuser = context_user::instance($USER->id);
  5282. $contextsystem = context_system::instance();
  5283. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5284. if ($files_ilm) {
  5285. foreach ($files_ilm as $value) {
  5286. // CHECK IF file is HTML type
  5287. if ($iassign_ilm->type == 1) {
  5288. // Check if the file extension is ZIP
  5289. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5290. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5291. if ((strtolower($ext) == 'zip')) {
  5292. // Coping...:
  5293. $destination = 'ilm_debug/' . $value->get_filename();
  5294. $value->copy_content_to($destination);
  5295. // Extracting content...:
  5296. $zip = new ZipArchive();
  5297. $extracted = './ilm';
  5298. $dir = "";
  5299. if ($zip->open($destination) === TRUE) {
  5300. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5301. if (is_dir($dir)) {
  5302. $i = 1;
  5303. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5304. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5305. $i++;
  5306. }
  5307. $name = $previous . "_" . $i;
  5308. $dir = './ilm/' . $name . "/";
  5309. $j = 0;
  5310. while ($item_name = $zip->getNameIndex($j)) {
  5311. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5312. $j++;
  5313. }
  5314. $zip->close();
  5315. }
  5316. $zip->open($destination);
  5317. $zip->extractTo($extracted);
  5318. $zip->close();
  5319. // After the extraction, remove it from DEBUG
  5320. unlink($destination);
  5321. } else { // Error trying to open destination...
  5322. // After the extraction error, also remove it from DEBUG
  5323. unlink($destination);
  5324. print_error('error_add_ilm_zip', 'iassign');
  5325. }
  5326. return $dir;
  5327. }
  5328. } // if ($iassign_ilm->type == 1)
  5329. if ($value->get_filename() != '.') {
  5330. $file_ilm = array(
  5331. 'userid' => $USER->id,
  5332. 'contextid' => $contextsystem->id,
  5333. 'component' => 'mod_iassign',
  5334. 'filearea' => 'ilm',
  5335. 'itemid' => rand(1, 999999999),
  5336. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5337. 'filename' => $value->get_filename());
  5338. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5339. array_push($file_jar, $file_ilm->get_id());
  5340. }
  5341. }
  5342. if (!empty($file_jar)) {
  5343. $return = implode(",", $file_jar);
  5344. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5345. foreach ($old_file_jar as $value) {
  5346. $file = $fs->get_file_by_id($value);
  5347. if ($file)
  5348. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5349. }
  5350. }
  5351. }
  5352. else // if ($files_ilm)
  5353. $return = $iassign_ilm->file_jar;
  5354. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5355. return $return;
  5356. } // static function new_file_ilm($itemid, $iassign_ilm)
  5357. /// Function for save in database an new iLM
  5358. // @param object $param An object with iLM params
  5359. static function new_ilm ($itemid) {
  5360. global $CFG, $USER, $OUTPUT;
  5361. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5362. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5363. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5364. }
  5365. $pathtemp = $CFG->dataroot . '/temp/';
  5366. $contextuser = context_user::instance($USER->id);
  5367. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5368. $zip = new zip_packer();
  5369. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5370. foreach ($files as $file) {
  5371. if (!$file->is_directory())
  5372. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5373. }
  5374. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5375. // Verifica se o pacote possui o XML
  5376. if (!$application_xml) {
  5377. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5378. return;
  5379. } else {
  5380. $missing = "";
  5381. if (!isset($application_xml->name)) {
  5382. $missing .= "name";
  5383. }
  5384. if (!isset($application_xml->version)) {
  5385. $missing .= ", version";
  5386. }
  5387. if (!isset($application_xml->type)) {
  5388. $missing .= ", type";
  5389. }
  5390. if (!isset($application_xml->extension)) {
  5391. $missing .= ", extension";
  5392. }
  5393. if (!isset($application_xml->file_jar)) {
  5394. $missing .= ", file_jar";
  5395. }
  5396. if (!isset($application_xml->file_class)) {
  5397. $missing .= ", file_class";
  5398. }
  5399. if (!isset($application_xml->width)) {
  5400. $missing .= ", width";
  5401. }
  5402. if (!isset($application_xml->height)) {
  5403. $missing .= ", height";
  5404. }
  5405. if (!isset($application_xml->evaluate)) {
  5406. $missing .= ", evaluate";
  5407. }
  5408. if (strlen($missing) > 2) {
  5409. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5410. return;
  5411. }
  5412. }
  5413. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5414. $typec = strtolower($application_xml->type);
  5415. require_once 'ilm_handlers/' . $typec . '.php';
  5416. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5417. return $retorno;
  5418. } // static function new_ilm($itemid)
  5419. /// Function for save in database an iLM edit
  5420. // @param object $param An object with iLM params
  5421. static function edit_ilm ($param, $itemid) {
  5422. // Descobrir o tipo de iLM:
  5423. global $DB, $USER, $CFG;
  5424. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5425. $pathtemp = $CFG->dataroot . '/temp/';
  5426. $contextuser = context_user::instance($USER->id);
  5427. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5428. $zip = new zip_packer();
  5429. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5430. $files_extract = null;
  5431. foreach ($files as $file) {
  5432. if (!$file->is_directory())
  5433. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5434. }
  5435. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5436. $typec = strtolower($iassign_t->type);
  5437. require_once 'ilm_handlers/' . $typec . '.php';
  5438. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5439. }
  5440. /// Function for register the new iLM (in database and in the directory)
  5441. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5442. // @param object $param An object with iLM params
  5443. static function copy_new_version_ilm ($param) {
  5444. global $DB, $CFG, $USER;
  5445. $itemid = $param->file;
  5446. $pathtemp = $CFG->dataroot . '/temp/';
  5447. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5448. //D echo "pathtemp=$pathtemp<br/>";
  5449. $contextuser = context_user::instance($USER->id);
  5450. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5451. $zip = new zip_packer();
  5452. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5453. $files_extract = null;
  5454. foreach ($files as $file) {
  5455. if (!$file->is_directory())
  5456. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5457. }
  5458. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5459. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5460. $typec = strtolower($iassign_t->type);
  5461. require_once 'ilm_handlers/' . $typec . '.php';
  5462. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5463. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5464. } // static function copy_new_version_ilm($param)
  5465. //VER::
  5466. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5467. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5468. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5469. /// Function for change visibility of iLM
  5470. // @param int $ilm_id Id of iLM
  5471. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5472. static function visible_ilm ($ilm_id, $status) {
  5473. global $DB;
  5474. if ($status == 0)
  5475. $visible = 1;
  5476. else
  5477. $visible = 0;
  5478. $newentry = new stdClass();
  5479. $newentry->id = $ilm_id;
  5480. $newentry->enable = $visible;
  5481. if (!$DB->update_record("iassign_ilm", $newentry))
  5482. error(get_string('error_edit_ilm', 'iassign'));
  5483. }
  5484. /// Function for confirm change default iLM
  5485. // @param int $ilm_id Id of iLM
  5486. // @param int $ilm_parent Id of parent iLM
  5487. // @return string Return with an string for create default page confirmation
  5488. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5489. global $OUTPUT, $DB;
  5490. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5491. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5492. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5493. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5494. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5495. return $return;
  5496. }
  5497. /// Function for change the default iLM
  5498. // @see settings_ilm.php
  5499. // @param int $ilm_id Id of iLM
  5500. // @return int Return Id of default iLM
  5501. static function default_ilm ($ilm_id) {
  5502. global $DB;
  5503. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5504. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5505. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5506. $iassign_ilm_default->id = $iassign_ilm->id;
  5507. $iassign_ilm_default->parent = 0;
  5508. $iassign_ilm->parent = $iassign_ilm_default->id;
  5509. $iassign_ilm->id = 0;
  5510. $iassign_ilm_default->enable = 1;
  5511. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5512. print_error('error_edit_ilm', 'iassign');
  5513. }
  5514. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5515. if (!$inserted) {
  5516. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5517. print_error($msg_error);
  5518. //xx print_error('error_add_ilm', 'iassign');
  5519. }
  5520. return $iassign_ilm_default->id;
  5521. } // static function default_ilm ($ilm_id)
  5522. /// Function for confirm delete iLM
  5523. // @param int $ilm_id Id of iLM
  5524. // @param int $ilm_parent Id of parent iLM
  5525. // @return string Return with an string for create delete page confirmation
  5526. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5527. global $OUTPUT, $DB;
  5528. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5529. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5530. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5531. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5532. }
  5533. /// Function for delete directory where the iLM is allocated.
  5534. // @param string $dirPath
  5535. // @throws InvalidArgumentException
  5536. public static function delete_dir ($dirPath) {
  5537. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5538. $dirPath .= '/';
  5539. }
  5540. $files = glob($dirPath . '*', GLOB_MARK);
  5541. foreach ($files as $file) {
  5542. if (is_dir($file)) {
  5543. ilm_settings::delete_dir($file);
  5544. } else {
  5545. unlink($file);
  5546. }
  5547. }
  5548. rmdir($dirPath);
  5549. }
  5550. /// Function for delete iLM
  5551. // @param int $ilm_id Id of iLM
  5552. // @return int Return Id of parent iLM
  5553. static function delete_ilm ($ilm_id) {
  5554. global $DB;
  5555. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5556. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5557. $typec = strtolower($iassign_ilm->type);
  5558. require_once 'ilm_handlers/' . $typec . '.php';
  5559. $retorno = $typec::delete_ilm($ilm_id);
  5560. return $retorno;
  5561. }
  5562. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5563. // @param int $ilm_id Id of iLM
  5564. static function export_ilm ($ilm_id) {
  5565. global $DB;
  5566. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5567. if (!$iassign_ilm) return; // security debug...
  5568. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5569. $typec = strtolower($iassign_ilm->type);
  5570. if (!$typec) $typec = "html5"; // security debug...
  5571. require_once 'ilm_handlers/' . $typec . '.php';
  5572. $typec::export_ilm($ilm_id);
  5573. } // static function export_ilm($ilm_id)
  5574. //TODO iLM_HTML5 :: //MOOC 2016
  5575. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5576. // @param int $ilm_id Id of iLM
  5577. static function export_update_ilm ($ilm_id) {
  5578. global $DB, $CFG;
  5579. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5580. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5581. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5582. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5583. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5584. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5585. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5586. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5587. $upgrade_descriptor .= '</upgrade>' . "\n";
  5588. file_put_contents($xml_filename, $upgrade_descriptor);
  5589. header("Pragma: public");
  5590. header("Expires: 0");
  5591. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5592. header("Cache-Control: private", false);
  5593. header('Content-Type: application/xml; charset=utf-8');
  5594. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5595. header("Content-Length: " . @filesize($xml_filename));
  5596. set_time_limit(0);
  5597. @readfile("$xml_filename") || die("File not found.");
  5598. unlink($xml_filename);
  5599. exit;
  5600. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5601. /// Function for save iLM from XML descriptor
  5602. // @param array $application_xml Data of XML descriptor
  5603. // @param array $files_extract Filenames of extract files
  5604. // @return array Return an array content id of JAR files
  5605. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5606. global $CFG, $USER;
  5607. // Tratamento diferenciado se for do tipo HTML5:
  5608. $source = "";
  5609. $diretorio = "";
  5610. if (strtolower($application_xml->type) == 'html5') {
  5611. $i = 0;
  5612. foreach ($files_extract as $key => $value) {
  5613. $file = $CFG->dataroot . '/temp/' . $key;
  5614. // Verifica se já existe a pasta no diretório dos iLM:
  5615. if ($i == 0) {
  5616. $source = $file;
  5617. if (file_exists("ilm/" . basename($file))) {
  5618. $j = 1;
  5619. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5620. $j++;
  5621. }
  5622. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5623. // mkdir($diretorio, 0777, true);
  5624. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5625. }
  5626. else {
  5627. $diretorio = 'ilm/' . basename($file);
  5628. // mkdir($diretorio, 0777, true);
  5629. mkdir($diretorio, 0755, true);
  5630. }
  5631. break;
  5632. }
  5633. $i++;
  5634. }
  5635. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5636. if ($item->isDir()) {
  5637. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5638. }
  5639. else {
  5640. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5641. }
  5642. }
  5643. ilm_settings::delete_dir($source);
  5644. return "./" . $diretorio;
  5645. }
  5646. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5647. $file_jar = array();
  5648. $files_ilm = explode(",", $application_xml->file_jar);
  5649. $contextsystem = context_system::instance();
  5650. foreach ($files_ilm as $value) {
  5651. $file_ilm = array(
  5652. 'userid' => $USER->id,
  5653. 'contextid' => $contextsystem->id,
  5654. 'component' => 'mod_iassign',
  5655. 'filearea' => 'ilm',
  5656. 'itemid' => rand(1, 999999999),
  5657. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5658. 'filename' => $value);
  5659. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5660. array_push($file_jar, $file_ilm->get_id());
  5661. }
  5662. foreach ($files_extract as $key => $value) {
  5663. $file = $CFG->dataroot . '/temp/' . $key;
  5664. if (file_exists($file))
  5665. unlink($file);
  5666. }
  5667. return $file_jar;
  5668. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5669. /// Function for import the iLM from an package
  5670. // @param int $itemid Itemid of zip file
  5671. static function import_ilm ($itemid) {
  5672. global $CFG, $USER, $OUTPUT;
  5673. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5674. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5675. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5676. }
  5677. $pathtemp = $CFG->dataroot . '/temp/';
  5678. $contextuser = context_user::instance($USER->id);
  5679. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5680. $zip = new zip_packer();
  5681. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5682. foreach ($files as $file) {
  5683. if (!$file->is_directory())
  5684. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5685. }
  5686. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5687. // Verifica se o pacote possui o XML
  5688. if (!$application_xml) {
  5689. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5690. return;
  5691. } else {
  5692. $missing = "";
  5693. if (!isset($application_xml->name)) {
  5694. $missing .= "name";
  5695. }
  5696. if (!isset($application_xml->version)) {
  5697. $missing .= ", version";
  5698. }
  5699. if (!isset($application_xml->type)) {
  5700. $missing .= ", type";
  5701. }
  5702. if (!isset($application_xml->extension)) {
  5703. $missing .= ", extension";
  5704. }
  5705. if (!isset($application_xml->file_jar)) {
  5706. $missing .= ", file_jar";
  5707. }
  5708. if (!isset($application_xml->file_class)) {
  5709. $missing .= ", file_class";
  5710. }
  5711. if (!isset($application_xml->width)) {
  5712. $missing .= ", width";
  5713. }
  5714. if (!isset($application_xml->height)) {
  5715. $missing .= ", height";
  5716. }
  5717. if (!isset($application_xml->evaluate)) {
  5718. $missing .= ", evaluate";
  5719. }
  5720. if (strlen($missing) > 2) {
  5721. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5722. return;
  5723. }
  5724. }
  5725. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5726. $typec = strtolower($application_xml->type);
  5727. require_once 'ilm_handlers/' . $typec . '.php';
  5728. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5729. } // static function import_ilm($itemid)
  5730. /// Function for list iLM defaults
  5731. // @return string Return an string with a table of iLM
  5732. static function list_ilm () {
  5733. global $DB, $OUTPUT;
  5734. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5735. $str = '';
  5736. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5737. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5738. if ($iassign_ilm) {
  5739. foreach ($iassign_ilm as $ilm) {
  5740. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5741. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5742. $str .= '<tr><td>';
  5743. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5744. $str .= '<tr>';
  5745. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5746. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5747. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5748. $str .= '</tr>';
  5749. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5750. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5751. $str .= '</table>';
  5752. $str .= '</td></tr>';
  5753. }
  5754. }
  5755. $str .= '</table>';
  5756. return $str;
  5757. }
  5758. /// Function for download and install an upgrade of an iLM
  5759. // @param int $ilm_id Id of iLM
  5760. static function upgrade_ilm ($ilm_id) {
  5761. global $DB, $CFG, $USER;
  5762. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5763. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5764. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5765. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5766. if (!$result)
  5767. print_error('error_upgrade_ilm', 'iassign');
  5768. else {
  5769. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5770. $extension = explode(".", $zip_filename);
  5771. if ($extension[count($extension) - 1] != 'ipz') {
  5772. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5773. die;
  5774. }
  5775. $zip = new zip_packer();
  5776. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5777. $contextuser = context_user::instance($USER->id);
  5778. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5779. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5780. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5781. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5782. if (file_exists($zip_filename))
  5783. unlink($zip_filename);
  5784. if (empty($file_jar)) {
  5785. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5786. print_error($msg_error);
  5787. //xx print_error('error_add_ilm', 'iassign');
  5788. }
  5789. else {
  5790. $newentry = new stdClass();
  5791. $newentry->name = (String) $application_xml->name;
  5792. $newentry->version = (String) $application_xml->version;
  5793. $newentry->url = (String) $application_xml->url;
  5794. $newentry->description = $description_str;
  5795. $newentry->extension = strtolower((String) $application_xml->extension);
  5796. $newentry->file_jar = implode(",", $file_jar);
  5797. $newentry->file_class = (String) $application_xml->file_class;
  5798. $newentry->width = (String) $application_xml->width;
  5799. $newentry->height = (String) $application_xml->height;
  5800. $newentry->enable = 0;
  5801. $newentry->timemodified = time();
  5802. $newentry->author = $USER->id;
  5803. $newentry->timecreated = time();
  5804. $newentry->evaluate = (String) $application_xml->evaluate;
  5805. $newentry->parent = $ilm_id;
  5806. }
  5807. }
  5808. return $iassign_ilm->id;
  5809. } // static function upgrade_ilm($ilm_id)
  5810. //MOOC2014 -- inicio
  5811. //TODO: REVIEW
  5812. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5813. // static function move_iassign($ilm_id)
  5814. //MOOC2014 -- final
  5815. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  5816. // @return string Return an string with a table of iLM
  5817. static function view_ilm ($ilmid, $from) {
  5818. global $DB;
  5819. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5820. // Get the iLM type and calls its correpondent handler ('Java' or 'HTML5')
  5821. $typec = strtolower($iassign_ilm->type);
  5822. require_once 'ilm_handlers/' . $typec . '.php';
  5823. $retorno = $typec::view_ilm($ilmid, $from);
  5824. return $retorno;
  5825. }
  5826. /// Function for get form variables for add, edit, or copy iLM params
  5827. // @param int $ilm_param_id Id of iLM param
  5828. // @param string $action String with the action
  5829. // @return object Return an object with forms variables
  5830. static function add_edit_copy_param ($ilm_param_id, $action) {
  5831. global $DB;
  5832. require_once('params_form.php');
  5833. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5834. $param = new stdClass();
  5835. $param->action = $action;
  5836. $param->ilm_param_id = $ilm_param_id;
  5837. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5838. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5839. $type = $iassign_ilm_config->param_type;
  5840. if ($action == 'add') {
  5841. $param->title = get_string('add_ilm', 'iassign');
  5842. $param->iassign_ilmid = $ilm_param_id;
  5843. $param->param_name = "";
  5844. $param->param_value = "";
  5845. $param->description = "";
  5846. $param->visible = 1;
  5847. }
  5848. elseif ($action == 'edit') {
  5849. if ($iassign_ilm_config) {
  5850. $param->title = get_string('edit_ilm', 'iassign');
  5851. $param->id = $iassign_ilm_config->id;
  5852. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5853. $param->param_type = $type; //MOOC2014
  5854. $param->param_name = $iassign_ilm_config->param_name;
  5855. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5856. $param->param_value = $iassign_ilm_config->param_value;
  5857. else //MOOC2014
  5858. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5859. $param->param_value = $iassign_ilm_config->param_value;
  5860. $param->description = $iassign_ilm_config->description;
  5861. $param->visible = $iassign_ilm_config->visible;
  5862. }
  5863. }
  5864. elseif ($action == 'copy') {
  5865. if ($iassign_ilm_config) {
  5866. $param->title = get_string('copy_ilm', 'iassign');
  5867. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5868. $param->param_type = $type; //MOOC2014
  5869. $param->param_name = $iassign_ilm_config->param_name;
  5870. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5871. $param->param_value = $iassign_ilm_config->param_value;
  5872. else //MOOC2014
  5873. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5874. $param->description = $iassign_ilm_config->description;
  5875. $param->visible = $iassign_ilm_config->visible;
  5876. }
  5877. }
  5878. return $param;
  5879. } // static function add_edit_copy_param($ilm_param_id, $action)
  5880. /// Function for change visibility of iLM param
  5881. // @param int $ilm_param_id Id of iLM param
  5882. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5883. static function visible_param ($ilm_param_id, $status) {
  5884. global $DB, $CFG;
  5885. if ($status == 0)
  5886. $visible = 1;
  5887. else
  5888. $visible = 0;
  5889. $newentry = new stdClass();
  5890. $newentry->id = $ilm_param_id;
  5891. $newentry->visible = $visible;
  5892. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5893. error(get_string('error_edit_param', 'iassign'));
  5894. }
  5895. /// Function for save in database an new iLM param
  5896. // @param object $param An object with iLM params
  5897. static function add_param ($param) {
  5898. global $DB;
  5899. $newentry = new stdClass();
  5900. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5901. //MOOC2014 $newentry->param_name = $param->param_name;
  5902. $newentry->param_type = $param->param_type; //MOOC2014
  5903. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5904. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5905. $newentry->param_value = $param->param_value;
  5906. else //MOOC2014
  5907. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5908. $newentry->description = $param->description;
  5909. $newentry->visible = $param->visible;
  5910. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5911. if (!$newentry->id) {
  5912. print_error('error_add_param', 'iassign');
  5913. }
  5914. }
  5915. /// Function for save in database a iLM param edit
  5916. // @param object $param An object with iLM params
  5917. static function edit_param ($param) {
  5918. global $DB;
  5919. $updentry = new stdClass();
  5920. $updentry->id = $param->id;
  5921. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5922. $updentry->param_type = $param->param_type; //MOOC2014
  5923. // $updentry->param_name = $param->param_name;
  5924. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5925. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5926. $updentry->param_value = $param->param_value;
  5927. else //MOOC2014
  5928. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5929. $updentry->description = $param->description;
  5930. $updentry->visible = $param->visible;
  5931. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5932. error(get_string('error_edit_param', 'iassign'));
  5933. }
  5934. }
  5935. /// Function for save in database a iLM param copy
  5936. // @param object $param An object with iLM params
  5937. static function copy_param ($param) {
  5938. global $DB;
  5939. $newentry = new stdClass();
  5940. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5941. //$newentry->param_name = $param->param_name;
  5942. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5943. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5944. $newentry->param_value = $param->param_value;
  5945. else //MOOC2014
  5946. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5947. $newentry->description = $param->description;
  5948. $newentry->visible = $param->visible;
  5949. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5950. if (!$newentry->id) {
  5951. print_error('error_add_param', 'iassign');
  5952. }
  5953. }
  5954. /// Function for delete iLM param of database
  5955. // @param int $param_id Id of iLM param
  5956. static function delete_param ($param_id) {
  5957. global $DB;
  5958. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5959. print_error('error_delete_param', 'iassign');
  5960. }
  5961. }
  5962. } // class ilm_settings
  5963. /// Class for manage iLM files (editor).
  5964. class ilm_manager {
  5965. var $id; // course id
  5966. var $url;
  5967. var $from;
  5968. /// Constructor for the base ilm_manager class
  5969. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5970. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5971. function __construct ($id, $url, $from) {
  5972. $this->id = $id; // course id
  5973. $this->url = $url;
  5974. $this->from = $from;
  5975. }
  5976. /// Function to get iAssign content file in Moodle data (exercise)
  5977. // @calledby x function preview_ilm($iassign_ilm) :
  5978. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5979. function get_file_ilm () {
  5980. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5981. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5982. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5983. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5984. $md_file = $fs->get_file_by_id($fileid);
  5985. $ilm_content_file = $md_file->get_content();
  5986. return $ilm_content_file;
  5987. }
  5988. /// Function for creating a new file from the iLM online editor
  5989. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5990. function ilm_editor_new () {
  5991. global $CFG, $DB, $OUTPUT, $PAGE;
  5992. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5993. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5994. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5995. $context = context_course::instance($this->id);
  5996. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5997. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5998. if (!$iassign) {
  5999. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  6000. die();
  6001. }
  6002. $temp = explode(",", $iassign->extension);
  6003. $extension = $temp[0]; // default extension for this iLM
  6004. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6005. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6006. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6007. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6008. if ($stringArchiveContent != NULL) {
  6009. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6010. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6011. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6012. $filename = optional_param('filename', NULL, PARAM_RAW);
  6013. //Leo $filename = iassign_utils::format_filename($filename); //
  6014. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6015. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6016. //2019/02 $arrayfilename = explode(".", $filename);
  6017. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6018. //2019/02 $count_dots = count($arrayfilename);
  6019. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6020. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6021. //2019/02 if ($last_name != $extension)
  6022. //2019/02 $filename = $filename . '.' . $extension;
  6023. //2019/02 }
  6024. //2019/02 else { // no extension...
  6025. //2019/02 $filename = $filename . '.' . $extension;
  6026. //2019/02 }
  6027. // Store the name of recent created file
  6028. $_SESSION['file_name'] = $filename;
  6029. //$this->write_file_iassign($string, $filename);
  6030. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6031. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6032. die();
  6033. }
  6034. else { // if ($stringArchiveContent != NULL)
  6035. // iLM On-line editor
  6036. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6037. $str_get_iLM = "window.frames.iLM";
  6038. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6039. }
  6040. else { // otherwise it is JAR named 'iLM'
  6041. $str_get_iLM = "document.iLM";
  6042. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6043. }
  6044. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6045. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6046. $files_array = '';
  6047. foreach ($files as $value) {
  6048. if ($value->get_filename() != ".")
  6049. $files_array .= "'" . $value->get_filename() . "',";
  6050. }
  6051. $files_array .= "''";
  6052. $file = null;
  6053. $ia_content = "";
  6054. $filename = "";
  6055. $error_files_exists = get_string('error_file_exists', 'iassign');
  6056. $output = "<script type='text/javascript'>
  6057. //<![CDATA[
  6058. //D alert('locallib.php: ilm_editor_new');
  6059. function submit_iLM_Answer () {
  6060. var docFormOnLineEditor = document.formEnvio;
  6061. var resposta_exerc = new Array(3);
  6062. var valor_resposta = new Array(3);
  6063. var sessao = new Array(3);
  6064. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6065. resposta_exerc[0] = doc_iLM.getAnswer();
  6066. valor_resposta[0] = doc_iLM.getEvaluation();
  6067. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6068. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6069. var files = new Array(" . $files_array . ");
  6070. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6071. if (docFormOnLineEditor.filename.value=='') {
  6072. // ERROR: the file name is empty
  6073. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6074. return false;
  6075. }
  6076. // }
  6077. for (i=0; i<files.length; i++) {
  6078. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6079. alert('" . $error_files_exists . "');
  6080. return false;
  6081. }
  6082. }
  6083. docFormOnLineEditor.submit();
  6084. return true;
  6085. }
  6086. //]]>
  6087. </script>\n";
  6088. $output .= "
  6089. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6090. $output .= $OUTPUT->box_start();
  6091. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6092. $output .= "
  6093. <table width='100%' cellpadding='20'>
  6094. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6095. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6096. </tr>
  6097. </table>\n";
  6098. $output .= $OUTPUT->box_end();
  6099. $output .= "<center>\n";
  6100. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6101. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6102. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6103. $output .= $output_ilm;
  6104. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6105. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6106. </center>
  6107. </form>\n";
  6108. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6109. $PAGE->navbar->add($title);
  6110. $PAGE->set_title($title);
  6111. $PAGE->set_heading($title); // insert title above the navigation bar
  6112. print $OUTPUT->header();
  6113. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6114. print $output;
  6115. print $OUTPUT->footer();
  6116. }
  6117. die();
  6118. } // function ilm_editor_new()
  6119. /// Function for editing an file in online editor
  6120. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6121. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6122. global $CFG, $DB, $OUTPUT, $PAGE;
  6123. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6124. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6125. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6126. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6127. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6128. // If iLM is not registered, error!
  6129. if (!$iassign) {
  6130. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6131. die;
  6132. }
  6133. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6134. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6135. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6136. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6137. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6138. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6139. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6140. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6141. if ($stringArchiveContent != NULL) {
  6142. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6143. die();
  6144. } else { // if ($stringArchiveContent != NULL)
  6145. $end_file = '';
  6146. if ($content_file) {
  6147. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6148. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6149. }
  6150. $temp = explode(",", $iassign->extension);
  6151. $extension = $temp[0]; // default extension for this iLM
  6152. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6153. $str_get_iLM = "window.frames.iLM";
  6154. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6155. } else { // otherwise it is JAR named 'iLM'
  6156. $str_get_iLM = "document.iLM";
  6157. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6158. }
  6159. $output = "<script type='text/javascript'>
  6160. //<![CDATA[
  6161. function submit_iLM_Answer () {
  6162. var docFormEditor = document.formEnvio;
  6163. var activityAnswer; // to get activity answer (text)
  6164. var activityValue; // to get activity answer value (float)
  6165. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6166. //activityAnswer = doc_iLM.getAnswer();
  6167. //activityValue = doc_iLM.getEvaluation();
  6168. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6169. activityValue = " . $str_get_iLM . ".getEvaluation();
  6170. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6171. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6172. docFormEditor.submit();
  6173. return true;
  6174. }
  6175. //]]>
  6176. </script>\n";
  6177. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6178. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6179. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6180. // return true;
  6181. // }
  6182. $output .= "
  6183. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6184. $output .= $OUTPUT->box_start();
  6185. $output .= "
  6186. <table width='100%' cellpadding='20'>
  6187. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6188. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6189. <input type='hidden' name='filename' value='$filename'/></td>
  6190. <td>
  6191. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6192. </tr>
  6193. </table>\n";
  6194. $output .= $OUTPUT->box_end();
  6195. $output .= " <center>\n";
  6196. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6197. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6198. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6199. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6200. </center>
  6201. </form>\n";
  6202. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6203. $PAGE->navbar->add($title);
  6204. $PAGE->set_title($title);
  6205. $PAGE->set_heading($title); // insert title above the navigation bar
  6206. print $OUTPUT->header();
  6207. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6208. print $output;
  6209. print $OUTPUT->footer();
  6210. } // else if ($stringArchiveContent != NULL)
  6211. die();
  6212. } // function ilm_editor_update()
  6213. /// Function for write iAssign file in Moodle data (exercise)
  6214. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6215. // @param string $stringArchiveContent Content of iassign file
  6216. // @param string $filename Filename of iassign file
  6217. function write_file_iassign ($stringArchiveContent, $filename) {
  6218. global $USER;
  6219. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6220. $context = context_course::instance($this->id);
  6221. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6222. $dirid = $this->get_dir_ilm('dirid');
  6223. $dir = $fs->get_file_by_id($dirid);
  6224. $fileinfo = array('contextid' => $context->id, // ID of course
  6225. 'component' => 'mod_iassign', // usually = table name
  6226. 'filearea' => 'activity', // usually = table name
  6227. 'itemid' => 0, // usually = ID of row in table
  6228. 'filepath' => '/', // any path beginning and ending whith '/'
  6229. 'userid' => $USER->id,
  6230. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6231. 'filename' => $filename); // any filename
  6232. // Create file containing text. '$stringArchiveContent'
  6233. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6234. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6235. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6236. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6237. // 'Activité interactive enregistrée avec succès sous le nom:';
  6238. // 'Atividade interativa gravada com sucesso sob o nome:'
  6239. $output = "
  6240. <script type='text/javascript'>
  6241. //<![CDATA[
  6242. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6243. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6244. //]]>
  6245. </script>";
  6246. print $output;
  6247. die();
  6248. }
  6249. /// Function for write iAssign file in Moodle data (exercise)
  6250. // @param string $stringArchiveContent Content of iassign file
  6251. // @param string $filename Filename of iassign file
  6252. // @param int $itemid Itemid of iassign file
  6253. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6254. global $OUTPUT, $USER;
  6255. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6256. $context = context_course::instance($this->id);
  6257. $dirid = $this->get_dir_ilm('dirid');
  6258. if ($stringArchiveContent != (-1)) {
  6259. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6260. $file = $fs->get_file_by_id($fileid);
  6261. if (!$file) {
  6262. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6263. die;
  6264. }
  6265. $fileinfo = array('contextid' => $context->id, // ID of context
  6266. 'component' => 'mod_iassign', // usually = table name
  6267. 'filearea' => 'activity', // usually = table name
  6268. 'itemid' => 0, // usually = ID of row in table
  6269. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6270. 'userid' => $USER->id,
  6271. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6272. 'license' => 'allrightsreserved', // allrightsreserved
  6273. 'timecreated' => $file->get_timecreated(),
  6274. 'filename' => $file->get_filename()); // any filename
  6275. $file->delete();
  6276. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6277. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6278. }
  6279. $output = "<script type='text/javascript'>
  6280. //<![CDATA[
  6281. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6282. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6283. //]]>
  6284. </script>";
  6285. print $output;
  6286. die();
  6287. }
  6288. /// Function for create an tag for iAssign filter
  6289. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6290. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6291. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6292. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6293. // @param int $fileid Id of file
  6294. // @return string Return an string with an tag of iassign filter
  6295. function tag_ilm ($fileid) {
  6296. global $DB;
  6297. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6298. $width = '600';
  6299. $height = '400';
  6300. $file = $fs->get_file_by_id($fileid);
  6301. $filetype = explode(".", $file->get_filename());
  6302. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6303. foreach ($iassign_ilm as $value) {
  6304. $extensions = explode(",", $value->extension);
  6305. if (in_array($filetype[1], $extensions)) {
  6306. $width = $value->width;
  6307. $height = $value->height;
  6308. }
  6309. }
  6310. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6311. }
  6312. /// Function for delete iAssign file in Moodle data (exercise)
  6313. function delete_file_ilm () {
  6314. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6315. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6316. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6317. $file = $fs->get_file_by_id($fileid);
  6318. if ($file)
  6319. $file->delete();
  6320. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6321. die();
  6322. }
  6323. /// Function for delete selected iAssign file in Moodle data (exercise)
  6324. function delete_selected_ilm () {
  6325. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6326. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6327. $context = context_course::instance($this->id);
  6328. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6329. $dirid = $this->get_dir_ilm('dirid');
  6330. foreach ($files_id as $file_id) {
  6331. $file = $fs->get_file_by_id($file_id);
  6332. if ($file) {
  6333. if (!$file->is_directory())
  6334. $file->delete();
  6335. else {
  6336. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6337. foreach ($files_delete as $value)
  6338. $value->delete();
  6339. $file->delete();
  6340. }
  6341. }
  6342. }
  6343. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6344. die();
  6345. }
  6346. /// Function for duplicate iAssign file from "online" edition
  6347. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6348. function duplicate_file_ilm () {
  6349. global $USER, $COURSE;
  6350. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6351. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6352. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6353. $filename = optional_param('filename', NULL, PARAM_RAW);
  6354. $file = $fs->get_file_by_id($fileid);
  6355. $context = context_course::instance($this->id);
  6356. $fileinfo = array(
  6357. 'contextid' => $context->id, // ID of context
  6358. 'component' => 'mod_iassign', // usually = table name
  6359. 'filearea' => 'activity', // usually = table name
  6360. 'itemid' => 0, // usually = ID of row in table
  6361. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6362. 'userid' => $USER->id,
  6363. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6364. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6365. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6366. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6367. die();
  6368. }
  6369. /// Function for rename iAssign file
  6370. function rename_file_ilm () {
  6371. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6372. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6373. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6374. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6375. $file = $fs->get_file_by_id($fileid);
  6376. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6377. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6378. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6379. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6380. die();
  6381. }
  6382. /// Function for get iassign file for iassign form
  6383. function add_ilm () {
  6384. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6385. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6386. $output = "
  6387. <script type='text/javascript'>
  6388. //<![CDATA[
  6389. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6390. iassign_file_link.innerHTML = '$filename';
  6391. window.opener.document.forms['mform1'].file.value='$fileid';
  6392. window.opener.document.forms['mform1'].filename.value='$filename';
  6393. window.close();
  6394. //]]>
  6395. </script>";
  6396. print $output;
  6397. die();
  6398. }
  6399. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6400. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6401. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6402. function preview_ilm ($courseid, $iassign_ilm) {
  6403. global $OUTPUT, $CFG, $USER;
  6404. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6405. $title = get_string('modulename', 'iassign'); // iAssign
  6406. print $OUTPUT->header();
  6407. print $OUTPUT->box_start();
  6408. $javascript = "
  6409. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6410. <script type='text/javascript'>
  6411. //<![CDATA[
  6412. function submit_close () {
  6413. window.opener.location.reload();
  6414. window.close();
  6415. }
  6416. //]]>
  6417. </script>\n";
  6418. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6419. // to the complete "applet" tag
  6420. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6421. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6422. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6423. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6424. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6425. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6426. if ($ilm_name != "ivprog") {
  6427. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6428. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6429. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6430. } else {
  6431. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6432. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6433. $timecreated = time();
  6434. $token = md5($timecreated);
  6435. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6436. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6437. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6438. $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)
  6439. }
  6440. $html = "
  6441. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6442. <table border='1'>
  6443. <tr><td>
  6444. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6445. <!-- iLM calls : end -->
  6446. </td></tr>
  6447. </table>
  6448. <table>
  6449. <tr>
  6450. <td align='center'>
  6451. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6452. </td></tr>
  6453. </table>
  6454. </form>\n";
  6455. print $javascript . $html;
  6456. print $OUTPUT->box_end();
  6457. //NAO echo format_string($html); // Moodle 3.X
  6458. die();
  6459. } // function preview_ilm($courseid, $iassign_ilm)
  6460. //r_ function preview_ilm ($iassign_ilm)
  6461. //r_ /// Function for preview iassign file from iassign filter.
  6462. //r_ function preview_ilm() {
  6463. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6464. //r_ $tag_filter = $this->tag_ilm($fileid);
  6465. //r_ $javascript = "<script type='text/javascript'>
  6466. //r_ //<![CDATA[
  6467. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6468. //r_ //]]>
  6469. //r_ </script>";
  6470. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6471. //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>
  6472. //r_ </table></form></body></html>";
  6473. //r_ echo $javascript . format_text($html);
  6474. //r_ die;
  6475. //r_ }
  6476. /// Function for export an package (zip) of iassign files
  6477. function export_files_ilm () {
  6478. global $CFG;
  6479. $context = context_course::instance($this->id);
  6480. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6481. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6482. $zip = new zip_archive();
  6483. $zip->open($zip_filename);
  6484. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6485. foreach ($files_id as $file_id) {
  6486. $file = $fs->get_file_by_id($file_id);
  6487. if (!$file->is_directory())
  6488. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6489. else {
  6490. $zip->add_directory($file->get_filepath());
  6491. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6492. foreach ($files_zip as $value) {
  6493. if (!$value->is_directory())
  6494. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6495. else
  6496. $zip->add_directory($value->get_filepath());
  6497. }
  6498. }
  6499. }
  6500. $zip->close();
  6501. header("Pragma: public");
  6502. header("Expires: 0");
  6503. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6504. header("Cache-Control: private", false);
  6505. header("Content-Type: application/zip");
  6506. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6507. header("Content-Transfer-Encoding: binary");
  6508. header("Content-Length: " . @filesize($zip_filename));
  6509. set_time_limit(0);
  6510. @readfile("$zip_filename") || die("File not found.");
  6511. unlink($zip_filename);
  6512. exit;
  6513. }
  6514. /// Function of execute a command in button editor tinymce
  6515. // @param int $fileid Id of file
  6516. function tinymce_ilm ($fileid) {
  6517. $tag_filter = $this->tag_ilm($fileid);
  6518. $output = "<script type='text/javascript'>
  6519. //<![CDATA[
  6520. var tag_filter = '$tag_filter';
  6521. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6522. // all right, insert it
  6523. } else {
  6524. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6525. }
  6526. // window.close();
  6527. //]]>
  6528. </script>\n";
  6529. print $output;
  6530. die();
  6531. }
  6532. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6533. /// Function to add content to the Editor Window
  6534. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6535. // @param int $fileid Id of file
  6536. function editor_ilm ($fileid, $editor) {
  6537. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6538. $output1 = "<script type='text/javascript'>
  6539. //<![CDATA[
  6540. var tag_filter = '$tag_filter';\n";
  6541. if ($editor == 'atto') {
  6542. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6543. } elseif ($editor == 'tinyMCE') {
  6544. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6545. } else
  6546. $output2 = "";
  6547. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6548. window.close();
  6549. //]]>
  6550. </script>\n";
  6551. //D var_dump($output);
  6552. print $output1 . $output2 . $output3;
  6553. die();
  6554. }
  6555. /// Function to add content to the Atto Editor Window
  6556. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6557. // @param int $fileid Id of file
  6558. function atto_ilm ($fileid) {
  6559. global $CFG, $DB;
  6560. $tag_filter = $this->tag_ilm($fileid);
  6561. $output = "<script type='text/javascript'>
  6562. //<![CDATA[
  6563. var tag_filter = '$tag_filter';
  6564. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6565. // all right, insert iLM tag to this editor
  6566. } else {
  6567. // error trying to insert
  6568. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6569. }
  6570. //window.close();
  6571. //]]>
  6572. </script>\n";
  6573. print $output;
  6574. die();
  6575. }
  6576. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6577. // @param string $key Key for return information
  6578. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6579. function get_dir_ilm ($key) {
  6580. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6581. $context = context_course::instance($this->id);
  6582. $dirid = optional_param('dirid', 0, PARAM_INT);
  6583. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6584. if ($dirid == 0) {
  6585. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6586. $dirid = $dir->get_id();
  6587. }
  6588. else {
  6589. $dir = $fs->get_file_by_id($dirid);
  6590. $dir_base = $dir->get_filepath();
  6591. }
  6592. $dir_parent = $dir->get_parent_directory();
  6593. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6594. return $data[$key];
  6595. }
  6596. /// Function for create an new dir
  6597. function new_dir_ilm () {
  6598. global $USER;
  6599. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6600. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6601. $dir_base = $this->get_dir_ilm('dir_base');
  6602. $context = context_course::instance($this->id);
  6603. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6604. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6605. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6606. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6607. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6608. }
  6609. /// Function for delete an dir
  6610. function delete_dir_ilm () { //
  6611. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6612. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6613. $context = context_course::instance($this->id);
  6614. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6615. $dir_parent = $this->get_dir_ilm('dir_parent');
  6616. if ($dir) {
  6617. if ($dir->is_directory()) {
  6618. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6619. foreach ($files_delete as $value)
  6620. $value->delete();
  6621. $dir->delete();
  6622. }
  6623. }
  6624. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6625. die();
  6626. }
  6627. /// Function for rename an dir
  6628. function rename_dir_ilm () {
  6629. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6630. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6631. $context = context_course::instance($this->id);
  6632. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6633. $dir_parent = $this->get_dir_ilm('dir_parent');
  6634. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6635. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6636. if ($dir->is_directory()) {
  6637. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6638. foreach ($files_rename_path as $value)
  6639. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6640. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6641. }
  6642. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6643. die();
  6644. }
  6645. /// Function for move an dir and your content for other dir
  6646. function selected_move_ilm () {
  6647. global $PAGE, $OUTPUT, $CFG;
  6648. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6649. $context = context_course::instance($this->id);
  6650. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6651. $dirid = $this->get_dir_ilm('dirid');
  6652. $dir_base = $this->get_dir_ilm('dir_base');
  6653. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6654. $code_javascript_ilm = "
  6655. <script type='text/javascript'>
  6656. //<![CDATA[
  6657. function getRadiobutton () {
  6658. var radioButtons = document.getElementsByTagName('input');
  6659. var param = '';
  6660. for (var counter=0; counter < radioButtons.length; counter++) {
  6661. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6662. param = radioButtons[counter].value;
  6663. }
  6664. return param;
  6665. }
  6666. function move_selected_ilm () {
  6667. var msgAnswer;
  6668. if (getRadiobutton() != '') {
  6669. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6670. if (msgAnswer)
  6671. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6672. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6673. }
  6674. else
  6675. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6676. }
  6677. function cancel_selected_ilm () {
  6678. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6679. }
  6680. //]]>
  6681. </script>\n";
  6682. $title = get_string('move_files', 'iassign');
  6683. $PAGE->set_title($title);
  6684. $PAGE->set_pagelayout('base');
  6685. print $OUTPUT->header();
  6686. print $OUTPUT->heading($title);
  6687. $dir_paths = array();
  6688. print $OUTPUT->box_start();
  6689. print "<center>";
  6690. foreach ($files_id as $file_id) {
  6691. $file = $fs->get_file_by_id($file_id);
  6692. if ($file) {
  6693. if (!$file->is_directory())
  6694. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6695. else {
  6696. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6697. array_push($dir_paths, $file->get_filepath());
  6698. }
  6699. }
  6700. }
  6701. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6702. if ($dir_base != '/') {
  6703. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6704. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6705. }
  6706. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6707. foreach ($files_tree as $file) {
  6708. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6709. $is_parent = false;
  6710. foreach ($dir_paths as $dir) {
  6711. $path = explode("/", $dir);
  6712. array_pop($path);
  6713. $path[count($path) - 1] = '';
  6714. $path = implode("/", $path);
  6715. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6716. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6717. }
  6718. if ($is_parent == false) {
  6719. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6720. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6721. }
  6722. }
  6723. }
  6724. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6725. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6726. print "</center>";
  6727. print $OUTPUT->box_end();
  6728. print $OUTPUT->footer();
  6729. print $code_javascript_ilm;
  6730. die;
  6731. }
  6732. /// Function for move files for an dir
  6733. function move_files_ilm () {
  6734. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6735. $context = context_course::instance($this->id);
  6736. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6737. $dirid = $this->get_dir_ilm('dirid');
  6738. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6739. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6740. foreach ($files_id as $file_id) {
  6741. $file = $fs->get_file_by_id($file_id);
  6742. if ($file) {
  6743. if ($file->is_directory()) {
  6744. $pathname = explode("/", $file->get_filepath());
  6745. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6746. foreach ($files_move_path as $value) {
  6747. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6748. $value->rename($path_move, $value->get_filename());
  6749. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6750. }
  6751. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6752. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6753. $file->rename($path_move, $file->get_filename());
  6754. } else {
  6755. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6756. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6757. }
  6758. }
  6759. }
  6760. //die;
  6761. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6762. die();
  6763. } // function move_files_ilm()
  6764. /// Function for recover files in use on all activities of a course
  6765. function recover_files_ilm () {
  6766. global $DB, $USER;
  6767. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6768. $courseid = optional_param('id', NULL, PARAM_INT);
  6769. $dirid = $this->get_dir_ilm('dirid');
  6770. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6771. $contextfile = context_course::instance($this->id);
  6772. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6773. foreach ($iassigns as $iassign) {
  6774. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6775. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6776. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6777. $context = context_module::instance($cm->id);
  6778. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6779. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6780. if ($files) {
  6781. foreach ($files as $value) {
  6782. $extension = explode(".", $value->get_filename());
  6783. if (!$value->is_directory()) {
  6784. $fileinfo = array('contextid' => $contextfile->id,
  6785. 'component' => 'mod_iassign',
  6786. 'filearea' => 'activity',
  6787. 'itemid' => 0,
  6788. 'filepath' => $this->get_dir_ilm('dir_base'),
  6789. 'userid' => $USER->id,
  6790. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6791. 'license' => 'allrightsreserved',
  6792. 'timecreated' => time(),
  6793. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6794. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6795. }
  6796. }
  6797. } // if ($files)
  6798. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6799. } // foreach ($iassigns as $iassign)
  6800. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6801. die();
  6802. } // function recover_files_ilm()
  6803. /// Auxiliary function the get all files in a given context
  6804. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6805. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6806. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6807. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6808. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6809. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6810. // (NAO s_iassign_statement.file = s_files.id)
  6811. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6812. $dir_base = $this->get_dir_ilm('dir_base');
  6813. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6814. $countf = 0;
  6815. $array_files_id = array(); // all files from this context
  6816. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6817. //$filename = $item_fc->get_filename();
  6818. //$filepath = $item_fc->get_filepath();
  6819. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6820. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6821. // $array_files_aux[] = $item_fc;
  6822. $itemid = $item_fc->get_id();
  6823. if (!in_array($itemid, $array_files_id)) {
  6824. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6825. if ($fileuserid == $userid)
  6826. $filesfrommine[] = $item_fc;
  6827. else
  6828. $filesfromothers[] = $item_fc;
  6829. $array_files_id[] = $itemid;
  6830. $countf++;
  6831. }
  6832. }
  6833. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6834. return $countf;
  6835. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6836. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6837. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6838. function get_all_ilm_files_by_fileid ($fileid) {
  6839. global $DB, $USER;
  6840. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6841. //TODO Criar coluna 'authorid'
  6842. $str_query = "SELECT * FROM {iassign_statement} " .
  6843. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6844. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6845. return $array_iassign_ilm;
  6846. }
  6847. //NN
  6848. // Build string with JavaScript code with function to edit/remove/double iLM files
  6849. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6850. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6851. global $CFG;
  6852. $error_files_exists = get_string('error_file_exists', 'iassign');
  6853. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6854. $code_javascript_ilm = "
  6855. <script type='text/javascript'>
  6856. //<![CDATA[
  6857. function preview_ilm (fileid, ilmid) { //JavaScript function
  6858. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6859. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6860. }
  6861. function update_ilm (ilmid, fileid) { //JavaScript function
  6862. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6863. }
  6864. function delete_ilm (ilmid, fileid) { //JavaScript function
  6865. var msgAnswer;
  6866. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6867. if (msgAnswer) {
  6868. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6869. }
  6870. }
  6871. function delete_selected_ilm () { //JavaScript function
  6872. var msgAnswer;
  6873. var param = getCheckbox();
  6874. if (param.join() != '') {
  6875. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6876. if (msgAnswer)
  6877. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6878. }
  6879. else
  6880. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6881. }
  6882. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6883. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6884. }
  6885. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6886. var filenamecopy;
  6887. var i;
  6888. var files = new Array(" . $files_array . ");
  6889. do {
  6890. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6891. } while (filenamecopy == '');
  6892. if (filenamecopy == null)
  6893. return false;\n
  6894. else {
  6895. for (i=0;i<files.length;i++) {
  6896. if (files[i]==filenamecopy) {
  6897. alert('" . $error_files_exists . "');
  6898. return false;\n
  6899. }
  6900. }\n" .
  6901. // @see: function 'duplicate_file_ilm()' above
  6902. "
  6903. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6904. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6905. } // else
  6906. }
  6907. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6908. var filenamecopy;
  6909. var i;
  6910. var files = new Array($files_array);
  6911. do {
  6912. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6913. } while (filenamecopy == '');
  6914. if (filenamecopy == null)
  6915. return false;
  6916. else {
  6917. for (i=0;i<files.length;i++) {
  6918. if (files[i]==filenamecopy) {
  6919. alert('" . $error_files_exists . "');
  6920. return false;
  6921. }
  6922. }
  6923. 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;
  6924. }
  6925. }
  6926. function export_files_ilm () { //JavaScript function
  6927. var param = getCheckbox();
  6928. if (param.join() != '')
  6929. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6930. else
  6931. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6932. }
  6933. function select_all_ilm () { //JavaScript function
  6934. var checkBoxes = document.getElementsByTagName('input');
  6935. var selectAll = document.getElementById('select_all');
  6936. for (var counter=0; counter < checkBoxes.length; counter++) {
  6937. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6938. checkBoxes[counter].checked = selectAll.checked;
  6939. }
  6940. }
  6941. function getCheckbox () { //JavaScript function
  6942. var checkBoxes = document.getElementsByTagName('input');
  6943. var param = new Array();
  6944. for (var counter=0; counter < checkBoxes.length; counter++) {
  6945. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6946. param.push(checkBoxes[counter].value);
  6947. }
  6948. return param;
  6949. }
  6950. function new_dir_ilm () { //JavaScript function
  6951. var dirname = '';
  6952. var i;
  6953. var dirs = new Array(" . $dirs_array . ");
  6954. do {
  6955. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6956. } while (dirname == '');
  6957. if (dirname == null)
  6958. return false;\n
  6959. else {
  6960. for (i=0;i<dirs.length;i++) {
  6961. if (dirs[i]==dirname) {
  6962. alert('" . $error_dir_exists . "');
  6963. return false;\n
  6964. }
  6965. }
  6966. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6967. }
  6968. }
  6969. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6970. var msgAnswer;
  6971. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6972. if (msgAnswer) {
  6973. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6974. }
  6975. }
  6976. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6977. var dirnamecopy;
  6978. var i;
  6979. var dirs = new Array($dirs_array);
  6980. do {
  6981. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6982. } while (dirnamecopy == '');
  6983. if (dirnamecopy == null)
  6984. return false;\n
  6985. else {
  6986. for (i=0;i<dirs.length;i++) {
  6987. if (dirs[i]==dirnamecopy) {
  6988. alert('" . $error_dir_exists . "');
  6989. return false;\n
  6990. }
  6991. }
  6992. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6993. }
  6994. }
  6995. function move_selected_ilm (ilmid) { //JavaScript function
  6996. var param = getCheckbox();
  6997. if (param.join() != '')
  6998. 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();
  6999. else
  7000. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7001. }
  7002. function recover_files_ilm () { //JavaScript function
  7003. var msgAnswer;
  7004. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7005. if (msgAnswer) {
  7006. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7007. }
  7008. }
  7009. window.onload = function() { //JavaScript function
  7010. var xPosition = 0;
  7011. var yPosition = 0;
  7012. element=document.getElementById('new_file');
  7013. while(element) {
  7014. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7015. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7016. element = element.offsetParent;
  7017. }
  7018. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7019. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7020. location.hash = '#new_file';
  7021. };
  7022. //]]>
  7023. </script>\n"; // end of $code_javascript_ilm
  7024. return $code_javascript_ilm;
  7025. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7026. /// List iassign files from course directory
  7027. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7028. function view_files_ilm ($iassign_ilm_class, $extension) {
  7029. global $CFG, $DB, $USER, $OUTPUT;
  7030. $fs = get_file_storage();
  7031. $context = context_course::instance($this->id);
  7032. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7033. $dirid = $this->get_dir_ilm('dirid');
  7034. $dir_base = $this->get_dir_ilm('dir_base');
  7035. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7036. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7037. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7038. $files_array = '';
  7039. foreach ($files_course as $value) {
  7040. if (!$value->is_directory())
  7041. $files_array .= "'" . $value->get_filename() . "',";
  7042. }
  7043. $files_array .= "''";
  7044. $error_files_exists = get_string('error_file_exists', 'iassign');
  7045. $dirs_array = '';
  7046. foreach ($files_course as $value) {
  7047. if ($value->is_directory()) {
  7048. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7049. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7050. }
  7051. }
  7052. $dirs_array .= "''";
  7053. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7054. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7055. $code_javascript_ilm = "
  7056. <script type='text/javascript'>
  7057. //<![CDATA[
  7058. function preview_ilm (fileid, ilmid) {
  7059. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7060. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7061. }
  7062. function update_ilm (ilmid, fileid) {
  7063. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7064. }
  7065. function delete_ilm (ilmid, fileid) {
  7066. var msgAnswer;
  7067. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7068. if (msgAnswer) {
  7069. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7070. }
  7071. }
  7072. function delete_selected_ilm () {
  7073. var msgAnswer;
  7074. var param = getCheckbox();
  7075. if (param.join() != '') {
  7076. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7077. if (msgAnswer)
  7078. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7079. }
  7080. else
  7081. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7082. }
  7083. function add_ilm_iassign (ilmid, filename, fileid) {
  7084. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7085. }
  7086. function duplicate_ilm (ilmid, filename, fileid) {
  7087. var filenamecopy;
  7088. var i;
  7089. var files = new Array($files_array);
  7090. do {
  7091. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7092. } while (filenamecopy == '');
  7093. if (filenamecopy == null)
  7094. return false;\n
  7095. else {
  7096. for (i=0;i<files.length;i++) {
  7097. if (files[i]==filenamecopy) {
  7098. alert('$error_files_exists');
  7099. return false;\n
  7100. }
  7101. }\n" .
  7102. // @see: function 'duplicate_file_ilm()' above
  7103. "
  7104. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7105. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7106. } // else
  7107. }
  7108. function rename_ilm (ilmid, filename, fileid) {
  7109. var filenamecopy;
  7110. var i;
  7111. var files = new Array($files_array);
  7112. do {
  7113. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7114. } while (filenamecopy == '');
  7115. if (filenamecopy == null)
  7116. return false;
  7117. else {
  7118. for (i=0;i<files.length;i++) {
  7119. if (files[i]==filenamecopy) {
  7120. alert('$error_files_exists');
  7121. return false;
  7122. }
  7123. }
  7124. 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;
  7125. }
  7126. }
  7127. function export_files_ilm () {
  7128. var param = getCheckbox();
  7129. if (param.join() != '')
  7130. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7131. else
  7132. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7133. }
  7134. function select_all_ilm () {
  7135. var checkBoxes = document.getElementsByTagName('input');
  7136. var selectAll = document.getElementById('select_all');
  7137. for (var counter=0; counter < checkBoxes.length; counter++) {
  7138. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7139. checkBoxes[counter].checked = selectAll.checked;
  7140. }
  7141. }
  7142. function getCheckbox () {
  7143. var checkBoxes = document.getElementsByTagName('input');
  7144. var param = new Array();
  7145. for (var counter=0; counter < checkBoxes.length; counter++) {
  7146. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7147. param.push(checkBoxes[counter].value);
  7148. }
  7149. return param;
  7150. }
  7151. function new_dir_ilm () {
  7152. var dirname = '';
  7153. var i;
  7154. var dirs = new Array($dirs_array);
  7155. do {
  7156. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7157. } while (dirname == '');
  7158. if (dirname == null)
  7159. return false;\n
  7160. else {
  7161. for (i=0;i<dirs.length;i++) {
  7162. if (dirs[i]==dirname) {
  7163. alert('$error_dir_exists');
  7164. return false;\n
  7165. }
  7166. }
  7167. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7168. }
  7169. }
  7170. function delete_dir_ilm (ilmid, dirid) {
  7171. var msgAnswer;
  7172. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7173. if (msgAnswer) {
  7174. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7175. }
  7176. }
  7177. function rename_dir_ilm (ilmid, dirname, dirid) {
  7178. var dirnamecopy;
  7179. var i;
  7180. var dirs = new Array($dirs_array);
  7181. do {
  7182. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7183. } while (dirnamecopy == '');
  7184. if (dirnamecopy == null)
  7185. return false;\n
  7186. else {
  7187. for (i=0;i<dirs.length;i++) {
  7188. if (dirs[i]==dirnamecopy) {
  7189. alert('$error_dir_exists');
  7190. return false;\n
  7191. }
  7192. }
  7193. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7194. }
  7195. }
  7196. function move_selected_ilm (ilmid) {
  7197. var param = getCheckbox();
  7198. if (param.join() != '')
  7199. 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();
  7200. else
  7201. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7202. }
  7203. function recover_files_ilm () {
  7204. var msgAnswer;
  7205. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7206. if (msgAnswer) {
  7207. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7208. }
  7209. }
  7210. window.onload = function() {
  7211. var xPosition = 0;
  7212. var yPosition = 0;
  7213. element=document.getElementById('new_file');
  7214. while(element) {
  7215. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7216. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7217. element = element.offsetParent;
  7218. }
  7219. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7220. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7221. location.hash = '#new_file';
  7222. };
  7223. //]]>
  7224. </script>\n";
  7225. $output = "";
  7226. $select_all = "";
  7227. $count_files = 0;
  7228. $extensions_allow = array();
  7229. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7230. foreach ($iassign_ilm as $item_iassign_ilm)
  7231. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7232. foreach ($files_course as $value) {
  7233. $filename = $value->get_filename();
  7234. $filepath = $value->get_filepath();
  7235. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7236. $pathname = $pathname[count($pathname) - 1];
  7237. $fileid = $value->get_id();
  7238. $tmp = explode(".", $filename);
  7239. if (count($tmp)>1) // avoid error if the file has no extension
  7240. $filetype = $tmp[1];
  7241. else // probably error...
  7242. $filetype = '';
  7243. $author = $value->get_author();
  7244. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7245. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7246. $extensions = explode(",", $extension);
  7247. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7248. $count_files++;
  7249. // buscar fileid nas tabelas do iassign
  7250. $list_filein_use = "";
  7251. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7252. if ($iassign_statement_activity_list) {
  7253. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7254. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7255. }
  7256. }
  7257. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7258. if (!$iassign_ilm) {
  7259. $iassign_ilm = new stdClass();
  7260. $iassign_ilm->id = $ilmid;
  7261. }
  7262. // Do not use $var inside "..." - problem with some "unusual" operational system
  7263. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7264. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7265. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7266. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7267. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7268. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7269. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7270. $check_select = "";
  7271. $link_rename = "";
  7272. $link_delete = "";
  7273. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7274. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7275. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7276. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7277. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7278. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7279. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7280. if ($value->get_userid() == $USER->id) {
  7281. if ($iassign_statement_activity_list) {
  7282. $check_select = "";
  7283. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7284. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7285. $link_rename = "";
  7286. } else {
  7287. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7288. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7289. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7290. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7291. }
  7292. }
  7293. if (!in_array($filetype, $extensions_allow)) {
  7294. $link_edit = "";
  7295. $link_add_ilm_iassign = "";
  7296. $link_add_ilm_tinymce = "";
  7297. $link_add_ilm_atto = "";
  7298. $link_filter = "";
  7299. }
  7300. if ($value->is_directory()) {
  7301. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7302. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7303. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7304. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7305. <td><center>$author</center></td>
  7306. <td><center>$timecreated</center></td>
  7307. <td><center>$timemodified</center></td></tr>\n";
  7308. }
  7309. else if ($this->from == 'iassign') {
  7310. $new_id = "";
  7311. $new_class = "";
  7312. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7313. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7314. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7315. }
  7316. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7317. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7318. <td><center>$author</center></td>
  7319. <td><center>$timecreated</center></td>
  7320. <td><center>$timemodified</center></td></tr>\n";
  7321. }
  7322. else if ($this->from == 'block') {
  7323. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7324. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7325. <td><center>$author</center></td>
  7326. <td><center>$timecreated</center></td>
  7327. <td><center>$timemodified</center></td></tr>\n";
  7328. }
  7329. else if ($this->from == 'tinymce') {
  7330. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7331. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7332. <td><center>$author</center></td>
  7333. <td><center>$timecreated</center></td>
  7334. <td><center>$timemodified</center></td></tr>\n";
  7335. }
  7336. else if ($this->from == 'atto') {
  7337. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7338. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7339. <td><center>$author</center></td>
  7340. <td><center>$timecreated</center></td>
  7341. <td><center>$timemodified</center></td></tr>\n";
  7342. }
  7343. }
  7344. }
  7345. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7346. $dir_base = "";
  7347. $header = "";
  7348. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7349. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7350. foreach ($basename as $value) {
  7351. $dir_base .= $value . "/";
  7352. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7353. if ($dir_id) {
  7354. if ($value == "") {
  7355. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7356. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7357. } else {
  7358. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7359. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7360. }
  7361. }
  7362. } // foreach ($basename as $value)
  7363. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7364. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7365. $html .= "
  7366. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7367. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7368. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7369. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7370. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7371. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7372. </table>\n";
  7373. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7374. $html .= "<table width='100%'><tr>\n";
  7375. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7376. if ($count_files != 0) {
  7377. $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";
  7378. $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";
  7379. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7380. }
  7381. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7382. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7383. $html .= "</form>\n";
  7384. print $code_javascript_ilm;
  7385. print $html;
  7386. } // function view_files_ilm($extension)
  7387. } // class ilm_manager
  7388. /// Class to insert of icons
  7389. class iassign_icons {
  7390. static function insert ($icon) {
  7391. global $CFG;
  7392. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7393. return $string;
  7394. }
  7395. }
  7396. /// Class with util functions for plugin manage
  7397. class iassign_utils {
  7398. /// Function to return the filename extension
  7399. // @param string The $filename as an string
  7400. // @return string Return an string (last group after '.')
  7401. static function filename_extension ($filename) {
  7402. if ($filename == null || $filename == '') {
  7403. return null;
  7404. }
  7405. $itens = explode('.', $filename);
  7406. $num = count($itens);
  7407. if ($num < 2) {
  7408. return null;
  7409. }
  7410. return $itens[$num - 1];
  7411. }
  7412. /// Use the PHP class/package ZipArchive to create a Zip file
  7413. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7414. // 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
  7415. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7416. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7417. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7418. $zip = new zip_archive(); //2
  7419. $res = $zip->open($full_path_zip_filename);
  7420. $total_vet = count($vet_student_filename);
  7421. for ($ii=0; $ii<$total_vet; $ii++) {
  7422. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7423. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7424. }
  7425. $ret = $zip->close();
  7426. iassign_utils::download_file($full_path_zip_filename);
  7427. $filenameZip = $zip->filename;
  7428. return array($ret, $zip);
  7429. }
  7430. static function download_file ($zip_filename) {
  7431. header("Pragma: public");
  7432. header("Expires: 0");
  7433. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7434. header("Cache-Control: private", false);
  7435. header("Content-Type: application/zip");
  7436. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7437. header("Content-Transfer-Encoding: binary");
  7438. header("Content-Length: " . @filesize($zip_filename));
  7439. set_time_limit(0);
  7440. @readfile("$zip_filename") || die("File not found.");
  7441. unlink($zip_filename);
  7442. }
  7443. /// Function for format filename remove special caracters
  7444. // @param string $text String for clean
  7445. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7446. // @return string Return an string in clean format
  7447. static function format_filename ($text) {
  7448. if ($text != '.') {
  7449. //D $text = htmlspecialchars(urldecode($text));
  7450. //D echo "locallib.php: format_filename: $text<br/>";
  7451. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7452. $text = json_decode($text)->{current_language()};
  7453. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7454. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7455. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7456. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7457. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7458. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7459. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7460. // E.g. text = "exerc_midpoint.course.geo"
  7461. // 0123456789012345678901234
  7462. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7463. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7464. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7465. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7466. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7467. //$ext = strrpos($text, ".");
  7468. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7469. //$text = str_replace($array1, $array2, $text);
  7470. }
  7471. return $text;
  7472. }
  7473. /// Function to filter characters to the file name to iLM content
  7474. // @param string $text String for clean
  7475. // @param string $ext String ot the extension of the iLM
  7476. // @return string Return an string in clean format
  7477. static function filter_filename_extension ($filename, $ext) {
  7478. if ($filename != '.') {
  7479. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7480. $arrTo = array("_","","","","","","","","","","","","");
  7481. $filename = str_replace($arrFrom, $arrTo, $filename);
  7482. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7483. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7484. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7485. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7486. $index_lastposition = strlen($filenameF);
  7487. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7488. $text = str_replace(".", "_", $text); // erase all other "."
  7489. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7490. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7491. }
  7492. else
  7493. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7494. return $filenameF;
  7495. }
  7496. /// Function for format pathname remove special caracters
  7497. // @param string $text String for clean
  7498. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7499. // @return string Return an string in clean format
  7500. static function format_pathname ($text, $is_lowercase = true) {
  7501. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7502. $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", "-", "_", "", "", "");
  7503. $text = str_replace($array1, $array2, $text);
  7504. if ($is_lowercase)
  7505. $text = strtolower($text);
  7506. return $text;
  7507. }
  7508. /// Function for format file name from iLM original name
  7509. // @param string $text String to build the file neam
  7510. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7511. // @return string Return an string in clean format
  7512. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7513. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7514. $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", "-", "_", "", "", "");
  7515. $index_firstposition_blank = strpos($ilm_name, " ");
  7516. if ($index_firstposition_blank) { // truncate the name!
  7517. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7518. }
  7519. $index_firstposition_dots = strpos($ilm_name, ":");
  7520. if ($index_firstposition_dots) { // truncate the name!
  7521. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7522. }
  7523. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7524. if ($is_lowercase)
  7525. $namefiltered = strtolower($namefiltered);
  7526. return $namefiltered;
  7527. }
  7528. /// Function for insert version in the filename
  7529. // @param string $filename Name of file
  7530. // @return string Return the filename with version
  7531. static function version_filename ($filename) {
  7532. $array_filename = explode('.', $filename);
  7533. if (count($array_filename) > 1)
  7534. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7535. else
  7536. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7537. return $filename;
  7538. }
  7539. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7540. static function remove_code_message ($string) {
  7541. $array = explode("&lt;ia_uc&gt;", $string);
  7542. return $array[0];
  7543. }
  7544. }
  7545. // class iassign_utils
  7546. /// Class with language functions for plugin manage
  7547. class iassign_language {
  7548. /// Function for return text in language or get default language (en)
  7549. // @param string $lang Code of language
  7550. // @param string $description JSON text content all languages
  7551. // @return string Return an string in the language selected
  7552. static function get_description_lang ($lang, $descriptions) {
  7553. $description_lang = "";
  7554. $description = json_decode($descriptions);
  7555. if ($description == null) {
  7556. $description_lang = $descriptions;
  7557. }
  7558. else {
  7559. if (isset($description->{$lang}))
  7560. $description_lang = $description->{$lang};
  7561. else
  7562. if (isset($description->en)) //MOOC2014
  7563. $description_lang = $description->en;
  7564. else //MOOC2014
  7565. $description_lang = "en"; //MOOC2014
  7566. }
  7567. return $description_lang;
  7568. }
  7569. /// Function for return all language supported by iLM
  7570. // @param string $descriptions JSON text content all languages
  7571. // @return string Return as string with all languages
  7572. static function get_all_lang ($descriptions) {
  7573. $langs = "";
  7574. $description = json_decode($descriptions);
  7575. if ($description) {
  7576. foreach ($description as $key => $value) {
  7577. $langs .= $key . " ; ";
  7578. }
  7579. $langs = substr($langs, 0, strlen($langs) - 3);
  7580. }
  7581. return $langs;
  7582. }
  7583. /// Function for convert json in xml //MOOC2014
  7584. // @param string $json JSON text
  7585. // @return string Return as string with xml tags
  7586. static function json_to_xml ($json) {
  7587. $xml = "";
  7588. $json = json_decode($json);
  7589. foreach ($json as $key => $value) {
  7590. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7591. }
  7592. return $xml;
  7593. }
  7594. }
  7595. // class iassign_language
  7596. /// Class with log functions for plugin manage.
  7597. class iassign_log {
  7598. /// Function for insert log event
  7599. // @param string $action Code action of event
  7600. // @param string $information Text for describe action of event
  7601. // @param int $cmid Id of context module
  7602. // @param int $ilmid Id of iLM
  7603. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7604. global $COURSE, $CFG, $USER, $DB;
  7605. $newentry = new stdClass();
  7606. $newentry->time = time();
  7607. $newentry->userid = $USER->id;
  7608. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7609. $newentry->course = $COURSE->id;
  7610. $newentry->cmid = $cmid;
  7611. $newentry->ilmid = $ilmid;
  7612. $newentry->action = $action;
  7613. $newentry->info = $information;
  7614. $newentry->language = current_language();
  7615. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7616. if (ini_get("browscap") && function_exists('get_browse')) {
  7617. $browser = get_browse(null, true);
  7618. $newentry->javascript = $browser['javascript'];
  7619. $newentry->java = $browser['javaapplets'];
  7620. }
  7621. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7622. print_error('error_add_log', 'iassign');
  7623. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7624. } // class iassign_log