locallib.php 427 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.7 2022/02/11
  7. * + Try to fix teacher edit of activity changing 'statement.id' to 'statement.file' in 'add_edit_iassign()'
  8. *
  9. * - v 4.9.6 2022/01/21
  10. * + Try to fix view activity not sent through report ("view_iassign_current()": else if (!$student_answer) $loadTeacherActivity=true;)
  11. *
  12. * - v 4.9.5 2021/12/28
  13. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  14. *
  15. * - v 4.9.4 2020/05/28
  16. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  17. *
  18. * - v 4.9.3 2020/01/16
  19. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  20. *
  21. * - v 4.9.2 2019/03/13
  22. * + Several fixes to allow iLM under HTML stack
  23. *
  24. * - v 4.9.1 2017/11/02
  25. * + 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")
  26. * + 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)'
  27. *
  28. * - v 4.9 2017/03/13
  29. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  30. *
  31. * - v 4.8 2016/05/12
  32. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  33. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  34. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  35. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  36. * replaced by
  37. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  38. * - v 4.7 2016/02/17
  39. * + 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(...)')
  40. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  41. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  42. * + 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)
  43. * + 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'
  44. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  45. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  46. *
  47. * --------------- (code bellow was used at our MOOC 2014)
  48. * - v 4.6 2014/02/25
  49. * + Fix bugs in filter function for open applets.
  50. * - v 4.5 2014/02/24
  51. * + Fix bugs in params.
  52. * + Insert new param type.
  53. * - v 4.4 2014/01/24
  54. * + Allow select type of params.
  55. * + Insert the use of applet params specific for activities.
  56. * - v 4.3 2014/01/23
  57. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  58. * - v 4.2 2016/02/13
  59. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  60. * --------------- (above code used at our MOOC 2014)
  61. *
  62. * - v 4.1 2013/12/13
  63. * + Insert log in iAssign actions.
  64. * + 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).
  65. * + Insert class for Log actions in system.
  66. * - v 4.0 2013/10/31
  67. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  68. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  69. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  70. * - v 3.9 2013/10/25
  71. * + Insert support of upgrade iLM.
  72. * + Insert support for more than one extension in iLM.
  73. * + Fix bugs in verion control.
  74. * - v 3.8 2013/09/19
  75. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  76. * - v 3.7 2013/09/12
  77. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  78. * + 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).
  79. * - v 3.6 2013/09/05
  80. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  81. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  82. * + Change tag APPLET in function ilm_settings::view_ilm.
  83. * - v 3.5 2013/08/26
  84. * + Fix bug in download package iassign without answers (iassign::report).
  85. * - v 3.4 2013/08/23
  86. * + Fix bug in export package iassign.
  87. * - v 3.3 2013/08/22
  88. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  89. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  90. * - v 3.2 2013/08/21
  91. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  92. * + Change functions for import files for ilm_manager.php.
  93. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  94. * - v 3.1 2013/08/15
  95. * + Change return file selected (ilm_manager::add_ilm).
  96. * + 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).
  97. * - v 3.0 2013/08/02
  98. * + 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).
  99. * - v 2.9 2013/08/01
  100. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  101. * - v 2.8 2013/07/25
  102. * + Insert the activity name in header of view (activity::view_dates).
  103. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  104. * - v 2.7 2013/07/24
  105. * + Create link previous and next for student view in one activity (activity::view_dates).
  106. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  107. * - v 2.6 2013/07/23
  108. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  109. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  110. * - v 2.5 2013/07/12
  111. * + 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).
  112. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  113. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  114. *
  115. * @author Patricia Alves Rodrigues
  116. * @author Leônidas O. Brandão
  117. * @contributor Igor Moreira Félix (2018-)
  118. * @contributor Márcio de Lima Passos (2014)
  119. * @version v 4.9.2 2019/03/13
  120. * @version v 4.8 2016/05/12
  121. * @package mod_iassign_lib
  122. * @since 2010/09/27
  123. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  124. *
  125. * <b>License</b>
  126. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  127. */
  128. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  129. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  130. //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"'
  131. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  132. /**
  133. * Standard base class for all iAssign
  134. */
  135. class iassign {
  136. var $cm;
  137. var $course;
  138. var $iassign;
  139. var $striassign;
  140. var $striassigns;
  141. var $context;
  142. var $activity;
  143. var $iassign_up;
  144. var $iassign_down;
  145. var $action;
  146. var $iassign_submission_current;
  147. var $userid_iassign;
  148. var $bottonPost;
  149. var $write_solution;
  150. var $view_iassign;
  151. // 3.1 update PHP 7.0 compatibility for all moodle versions
  152. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  153. /// Constructor for the base iassign class
  154. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  155. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  156. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  157. function __construct ($iassign, $cm, $course) {
  158. global $COURSE, $CFG, $USER, $DB;
  159. $botton = optional_param('botton', NULL, PARAM_TEXT);
  160. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  161. if (!is_null($botton))
  162. $USER->iassignEdit = $botton;
  163. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  164. // 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'
  165. $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"
  166. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  167. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  168. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  169. $this->action = optional_param('action', NULL, PARAM_TEXT);
  170. $this->cm = $cm;
  171. $this->context = context_module::instance($this->cm->id);
  172. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  173. $this->userid_iassign = $USER->id;
  174. if ($course) {
  175. $this->course = $course;
  176. }
  177. else if ($this->cm->course == $COURSE->id) {
  178. $this->course = $COURSE;
  179. }
  180. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  181. print_error('invalidid', 'iassign');
  182. }
  183. $this->coursecontext = context_course::instance($this->course->id);
  184. if ($iassign) {
  185. $this->iassign = $iassign;
  186. }
  187. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  188. print_error('invalidid', 'iassign');
  189. }
  190. $USER->context = context_module::instance($this->cm->id);
  191. $USER->cm = $this->cm->id;
  192. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  193. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  194. $this->context = context_module::instance($this->cm->id);
  195. $this->striassign = get_string('modulename', 'iassign');
  196. $this->striassigns = get_string('modulenameplural', 'iassign');
  197. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  198. $this->bottonPost = 0;
  199. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  200. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT)); // this is the activity inside iAssign block
  201. } // function __construct($iassign, $cm, $course)
  202. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  203. // This method provides the page to view each iLM with any interactive activity
  204. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  205. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  206. global $USER, $DB, $OUTPUT;
  207. // $iassign_statementid = $this->iassign->iassign_statementid;
  208. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  209. $iassign_statementid = $this->activity->get_activity()->id;
  210. else
  211. $iassign_statementid = "";
  212. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  213. // If this user has no capability to View 'iassign': stop here
  214. require_capability('mod/iassign:view', $this->context);
  215. // Trigger module view event
  216. $event = \mod_iassign\event\course_module_viewed::create(array(
  217. 'objectid' => $this->iassign->id,
  218. 'context' => $this->context
  219. ));
  220. $event->add_record_snapshot('course', $this->course);
  221. $event->trigger();
  222. if ($this->action) { // when student do/redo activity or teacher see student solution
  223. $this->action(); // calls '$this->view_iLM();'
  224. }
  225. else {
  226. print $OUTPUT->header();
  227. $this->view_iassigns(); // show the iLM with the content
  228. print $OUTPUT->footer();
  229. }
  230. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  231. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  232. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  233. //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" }
  234. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  235. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  236. //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" }
  237. //D else echo "Apagou!<br/>";
  238. die();
  239. } // function view()
  240. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  241. function action () {
  242. global $USER;
  243. // action:
  244. // up - move up activity (mover atividade para cima)
  245. // down - move down activity (mover atividade para baixo)
  246. // visible - view/hide activity (exibir/ocultar atividade)
  247. // delete - delete activity (excluir atividade)
  248. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  249. // deleteno - does not erase activity (não apaga atividade)
  250. // add - add activity (adicionar atividade)
  251. // edit - edit activity (modificar atividade)
  252. $action_iassign = array(
  253. 'newcomment' => '$this->add_comment();',
  254. 'view' => '$this->view_iassign_current();',
  255. 'get_answer' => '$this->get_answer();',
  256. 'repeat' => '$this->view_iassign_current();',
  257. 'overwrite' => '$this->get_answer();',
  258. 'stats_student' => '$this->stats_students();',
  259. 'download_answer' => '$this->export_file_answer();',
  260. 'download_all_answer' => '$this->export_package_answer();',
  261. 'notifications' => '$this->view_notifications();');
  262. $action_iassign_limit = array(
  263. 'view' => '$this->view_iassign_current();',
  264. //'newcomment' => '$this->get_answer();',
  265. 'viewsubmission' => '$this->view_iassign_current();',
  266. 'edit_status' => '$this->edit_status();',
  267. 'edit_grade' => '$this->edit_grade();',
  268. 'export_csv' => '$this->export_csv();',
  269. 'report' => '$this->report();',
  270. 'print' => '$this->report();',
  271. 'stats' => '$this->stats();',
  272. 'printstats' => '$this->stats();');
  273. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  274. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  275. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  276. 'visible' => '$this->activity->visible_iassign($this->return);',
  277. 'delete' => '$this->activity->delete($this->return);',
  278. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  279. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  280. 'add' => '$this->add_edit_iassign();',
  281. 'edit' => '$this->add_edit_iassign();',
  282. 'get_answer' => '$this->get_answer();',
  283. 'duplicate_activity' => '$this->duplicate_activity();',
  284. 'move_activity' => '$this->move_activity();',
  285. 'auto_evaluate' => '$this->auto_evaluate();',
  286. 'all_submissions' => '$this->all_submissions();',
  287. 'delete_submissions' => '$this->delete_submissions();',
  288. 'download_submissions' => '$this->download_submissions();',
  289. 'open_individual_submission' => '$this->open_individual_submission();',
  290. 'get_individual_submission' => '$this->get_individual_submission();',
  291. 'get_student_submission' => '$this->get_student_submission();',
  292. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  293. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  294. 'import_activity' => '$this->import_activity();',
  295. 'import_activity_confirm' => '$this->import_activity_confirm();'
  296. );
  297. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  298. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  299. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  300. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  301. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  302. }
  303. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  304. eval($action_iassign_limit[$this->action]);
  305. }
  306. else { // Student reaches this point
  307. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  308. // Arrive here with: "get_answer"; "view"
  309. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  310. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  311. }
  312. } // function action()
  313. /// This method prints the student submission to a specific exercise
  314. function get_student_submission () {
  315. global $DB;
  316. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  317. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  318. if (!$student || !$exercise) exit;
  319. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  320. if ($iassign_submission)
  321. print($iassign_submission->answer);
  322. die();
  323. }
  324. /// This method prints the teacher exercise
  325. function get_teacher_exercise () {
  326. global $DB, $COURSE;
  327. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  328. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  329. $fs = get_file_storage(); // Get reference to all files in Moodle data
  330. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  331. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  332. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  333. foreach ($files as $file) {
  334. if ($file->get_filename() != ".") {
  335. print($file->get_content());
  336. }
  337. }
  338. die();
  339. }
  340. /// This method receives the data from auto_eval event
  341. /// @see auto_evaluate()
  342. function post_auto_eval_result () {
  343. global $COURSE, $CFG, $USER, $DB;
  344. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  345. exit;
  346. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  347. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  348. $student = optional_param('student', -1, PARAM_INT);
  349. $grade = optional_param('grade', 0, PARAM_FLOAT);
  350. // 1: Recuperar a nota atual:
  351. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  352. // 2: Atualizar a tabela:
  353. $update_entry = new stdClass();
  354. $update_entry->id = $actual->id;
  355. $update_entry->previous_grade = $actual->grade;
  356. $update_entry->grade = $grade;
  357. // Update the iassign_submission
  358. $DB->update_record("iassign_submission", $update_entry);
  359. }
  360. /// Function to help download all_submissions files
  361. function download_submissions_help ($list) {
  362. global $DB, $CFG, $OUTPUT;
  363. // Get list of iLMs
  364. $ilm_list = $DB->get_records("iassign_ilm");
  365. // Get list of enrolled students:
  366. $params_temp = array('shortname' => 'student');
  367. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  368. $context = context_course::instance($this->course->id);
  369. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  370. $students_list = $DB->get_records_sql(
  371. "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);
  372. $json_obj = new stdclass();
  373. $json_obj->submissions = [];
  374. $csvfields = [];
  375. $csvfields[] = 'submissionid';
  376. $csvfields[] = 'file';
  377. $csvfields[] = 'filesize';
  378. $csvfields[] = 'timestamp';
  379. $csvfields[] = 'humandate';
  380. $csvfields[] = 'grade';
  381. $csvfields[] = 'userid';
  382. $csvfields[] = 'exerciseid';
  383. $json_obj->submissions[] = $csvfields;
  384. $exercise_dir = [];
  385. $exercises_list = [];
  386. foreach ($list as $item) {
  387. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  388. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  389. $exercises_list[] = $temp;
  390. $exercise_dir[] = $temp->id;
  391. }
  392. }
  393. $student_dir = [];
  394. $students_list = [];
  395. foreach ($list as $item) {
  396. if (!in_array($item->userid, $student_dir)) {
  397. $temp = $DB->get_record("user", array("id" => $item->userid));
  398. $students_list[] = $temp;
  399. $student_dir[] = $temp->id;
  400. }
  401. }
  402. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  403. //TODO: tem que criar moodledata/temp/iassign_files
  404. // Create $CFG->dataroot/temp/iassign_files
  405. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  406. if (!file_exists($tempfilespath)) {
  407. mkdir($tempfilespath, 0777, true);
  408. }
  409. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  410. if (!file_exists($iassignfilespath)) {
  411. mkdir($iassignfilespath, 0777, true);
  412. }
  413. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  414. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  415. if (!file_exists($diretorio)) {
  416. 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.';
  417. exit;
  418. }
  419. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  420. $zip = new zip_archive(); // create ZIP
  421. if (!$zip->open($zip_filename)) {
  422. 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;
  423. exit;
  424. }
  425. ;
  426. foreach ($exercises_list as $exercise) {
  427. $dir_ex = iassign_utils::format_filename($exercise->name);
  428. $zip->add_directory($dir_ex);
  429. $extension_ilm = '';
  430. foreach ($ilm_list as $ilm) {
  431. if ($exercise->iassign_ilmid == $ilm->id) {
  432. $extension_ilm = $ilm->extension;
  433. break;
  434. }
  435. }
  436. foreach ($students_list as $student) {
  437. $individual_dir =
  438. $dir_ex . DIRECTORY_SEPARATOR .
  439. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  440. $zip->add_directory($individual_dir);
  441. $i = 1;
  442. foreach($list as $item) {
  443. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  444. $date = new DateTime();
  445. $date->setTimestamp($item->timecreated);
  446. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  447. $zip->add_file_from_string($new_file, $item->answer);
  448. $temp_json = [];
  449. $temp_json[] = intval($item->id);
  450. $temp_json[] = $new_file;
  451. $temp_json[] = strlen($new_file);
  452. $temp_json[] = intval($item->timecreated);
  453. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  454. $temp_json[] = doubleval($item->grade);
  455. $temp_json[] = intval($item->userid);
  456. $temp_json[] = intval($exercise->id);
  457. $json_obj->submissions[] = $temp_json;
  458. }
  459. }
  460. }
  461. }
  462. $csv_str = "";
  463. foreach($json_obj->submissions as $sub) {
  464. $csv_str .= $this->csvstr($sub) . "\n";
  465. }
  466. $zip->add_file_from_string('index.csv', $csv_str);
  467. $zip->close();
  468. iassign_utils::download_file($zip_filename);
  469. exit;
  470. }
  471. function csvstr(array $fields) : string {
  472. $f = fopen('php://memory', 'r+');
  473. if (fputcsv($f, $fields) === false) {
  474. return false;
  475. }
  476. rewind($f);
  477. $csv_line = stream_get_contents($f);
  478. return rtrim($csv_line);
  479. }
  480. /// Download submissions from table iassign_allsubmissions
  481. function download_submissions () {
  482. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  483. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  484. exit;
  485. $type = optional_param('type', NULL, PARAM_TEXT);
  486. $item = optional_param('item', NULL, PARAM_TEXT);
  487. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  488. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  489. $sub_list = [];
  490. if ($type == 'individual') {
  491. $sub_list[] = $DB->get_record(
  492. 'iassign_allsubmissions', array('id' => $item));
  493. } elseif ($type == 'student') {
  494. $sub_list = $DB->get_records(
  495. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  496. } elseif ($type == 'exercise') {
  497. $sub_list = $DB->get_records(
  498. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  499. } elseif ($type == 'block') {
  500. $exercises_in_block = $DB->get_records(
  501. 'iassign_statement', array('iassignid' => $iassign_id));
  502. foreach ($exercises_in_block as $exercise) {
  503. $temp = $DB->get_records(
  504. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  505. $sub_list = array_merge($sub_list, $temp);
  506. }
  507. }
  508. $this->download_submissions_help($sub_list);
  509. }
  510. /// Delete submissions in table iassign_allsubmissions
  511. function delete_submissions () {
  512. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  513. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  514. exit;
  515. $type = optional_param('type', NULL, PARAM_TEXT);
  516. $item = optional_param('item', NULL, PARAM_TEXT);
  517. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  518. if ($type == 'individual') {
  519. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  520. } elseif ($type == 'student') {
  521. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  522. } elseif ($type == 'exercise') {
  523. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  524. }
  525. }
  526. function get_individual_submission () {
  527. global $DB, $USER;
  528. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  529. exit;
  530. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  531. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  532. print $submission->answer;
  533. }
  534. /// Open individual submission
  535. function open_individual_submission () {
  536. global $DB, $USER, $CFG;
  537. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  538. exit;
  539. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  540. $id = $this->cm->id;
  541. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  542. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  543. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  544. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  545. $all_submissions = $DB->get_records('iassign_allsubmissions',
  546. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  547. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  548. $previous = null;
  549. $next = null;
  550. $i = 0;
  551. $found = false;
  552. foreach($all_submissions as $individual) {
  553. if (!$found && $individual->id != $submissionid) {
  554. $previous = $individual;
  555. }
  556. if ($found) {
  557. $next = $individual;
  558. break;
  559. }
  560. if ($individual->id === $submissionid) {
  561. $found = true;
  562. }
  563. $i++;
  564. }
  565. print '<center>' . "\n";
  566. 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>' . "\n";
  567. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>' . "\n";
  568. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>' . "\n";
  569. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>' . "\n";
  570. print '</table>' . "\n";
  571. if ($previous) {
  572. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  573. print '<a href="' . $url_prev . '" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  574. } else {
  575. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  576. }
  577. print ' (' . $i . '/' . count($all_submissions) . ')';
  578. if ($next) {
  579. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  580. print '<a href="' . $url_next . '" style="color: blue; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  581. } else {
  582. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  583. }
  584. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  585. //array("type" => "editor_new", "notSEND" => "true")
  586. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  587. print '</center>' . "\n";
  588. } // function open_individual_submission()
  589. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  590. function import_activity_confirm () {
  591. global $USER, $DB;
  592. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  593. exit;
  594. if (!isset($_REQUEST['statements'])) exit;
  595. $iassign_destiny = $this->iassign->id;
  596. $activities_list = $_REQUEST['statements'];
  597. foreach ($activities_list as $activity) {
  598. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  599. $activity_source->id = 0;
  600. $iassign_id_from = $activity_source->iassignid;
  601. $filesid_from = $activity_source->filesid;
  602. $activity_source->iassignid = $iassign_destiny;
  603. $author = $DB->get_record("user", array('id' => $USER->id));
  604. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  605. $activity_source->author_modified = $activity_source->author_modified_name;
  606. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  607. $fs = get_file_storage();
  608. // Duplicate activity file
  609. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  610. print 'Arquivos a serem copiados: ';
  611. print_r($files_ids);
  612. foreach ($files_ids as $fileid) {
  613. $source_file = $fs->get_file_by_id($fileid->id);
  614. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  615. $updateentry = new stdClass();
  616. $updateentry->id = $id_;
  617. $updateentry->filesid = $id_;
  618. // Update the duplicated iLM iAssign with new file id
  619. $DB->update_record("iassign_statement", $updateentry);
  620. }
  621. }
  622. } // foreach ($activities_list as $activity)
  623. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  624. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  625. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  626. exit;
  627. }
  628. function import_activity () {
  629. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  630. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  631. exit;
  632. print '<script>
  633. function verify_selection () {
  634. document.getElementById("msg-error").classList.add("d-none");
  635. var checkboxes = document.getElementsByName("statements[]");
  636. for (var i = 0; i < checkboxes.length; i++)
  637. if (checkboxes[i].checked) return true;
  638. document.getElementById("msg-error").classList.remove("d-none");
  639. return false;
  640. }
  641. </script>'; // "
  642. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  643. print $OUTPUT->header();
  644. $this->print_main_menu();
  645. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>' . "\n";
  646. print '<form action="' . $destiny_url . '" method="post" onsubmit="return verify_selection()">' . "\n";
  647. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  648. foreach ($courses_as_teacher as $course) {
  649. 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>' . "\n";
  650. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '">' . "\n";
  651. $iassigns = $this->get_iassign_items_by_course($course->id);
  652. if ($iassigns) {
  653. foreach ($iassigns as $iassign) {
  654. 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>' . "\n";
  655. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '-' . $iassign->id . '">' . "\n";
  656. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  657. print '<table class="table table-hover">' . "\n";
  658. if ($statements) {
  659. foreach ($statements as $statement) {
  660. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="' . $statement->id . '" id="statement-' . $statement->id . '">' . "\n";
  661. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  662. print '</label></div></td></tr>' . "\n";
  663. }
  664. }
  665. else {
  666. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>' . "\n";
  667. }
  668. print '</table></div>' . "\n";
  669. }
  670. }
  671. else {
  672. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign') . '</div>' . "\n";
  673. }
  674. print '</div>' . "\n";
  675. }
  676. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>' . "\n";
  677. print '<div class="text-center text-danger d-none" id="msg-error">' . get_string('import_statement_no_exercise', 'iassign') . '</div>' . "\n";
  678. print "</form>\n";
  679. print $OUTPUT->footer();
  680. } // function post_auto_eval_result()
  681. function get_iassign_items_by_course ($courseid) {
  682. global $DB;
  683. return $DB->get_records("iassign", array("course" => $courseid));
  684. }
  685. function get_iassign_statement_by_iassign ($iassignid) {
  686. global $DB;
  687. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  688. }
  689. function get_courses_enroled_as_teacher($userid) {
  690. $all_enroled = enrol_get_users_courses($userid);
  691. $return = array();
  692. foreach ($all_enroled as $enroled) {
  693. $context_course = context_course::instance($enroled->id);
  694. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  695. array_push($return, $enroled);
  696. }
  697. }
  698. return $return;
  699. }
  700. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  701. /// Manage all submissions in exercises to table iassign_allsubmissions
  702. function all_submissions () {
  703. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  704. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  705. exit;
  706. print $OUTPUT->header();
  707. $this->print_main_menu();
  708. $id = $this->cm->id;
  709. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  710. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  711. print '
  712. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  713. <div class="modal-dialog modal-dialog-centered" role="document">
  714. <div class="modal-content">
  715. <div class="modal-header">
  716. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('delete', 'iassign') . '</h5>
  717. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  718. <span aria-hidden="true">&times;</span>
  719. </button>
  720. </div>
  721. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  722. <div class="modal-footer">
  723. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  724. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  725. </div>
  726. </div>
  727. </div>
  728. </div>'; // "
  729. print '
  730. <script>
  731. var sub_type;
  732. var sub_item;
  733. var sub_el;
  734. var sub_exercise;
  735. function delete_submission (type, item, el, exercise = 0) {
  736. sub_type = type;
  737. sub_item = item;
  738. sub_exercise = exercise;
  739. sub_el = el.closest("tr");
  740. if (!sub_el) sub_el = el.closest("a");
  741. $("#modalConfirm").modal();
  742. }
  743. function confirm_delete () {
  744. var url = "'.$enderecoPOST.'&action=delete_submissions";
  745. var xhttp = new XMLHttpRequest();
  746. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  747. xhttp.send();
  748. $("#modalConfirm").modal("hide");
  749. if ($(sub_el).attr("href"))
  750. $($(sub_el).attr("href")).remove();
  751. if (sub_el) sub_el.remove();
  752. }
  753. function download_submission(type, item, exercise = 0, iassign = 0) {
  754. var url = "'.$enderecoPOST.'&action=download_submissions";
  755. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  756. document.location = url;
  757. }
  758. function open_submission(item) {
  759. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  760. var poupup = window.open(url, "popup", "width=900,height=900");
  761. }
  762. </script>' . chr(13); // '
  763. // Get list of exercises in the instance:
  764. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  765. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  766. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  767. 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>';
  768. // Get list of enrolled students:
  769. $params_temp = array('shortname' => 'student');
  770. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  771. $context = context_course::instance($this->course->id);
  772. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  773. $students_list = $DB->get_records_sql(
  774. "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);
  775. print '<div>';
  776. foreach ($exercises_list as $exercise) {
  777. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  778. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  779. print '
  780. <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> '
  781. . $exercise->name
  782. . ' - ' . $iassign_ilm->name
  783. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  784. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  785. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  786. . $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> '
  787. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  788. . '</a>';
  789. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  790. foreach ($students_list as $student) {
  791. $total = 0;
  792. $student_submissions = [];
  793. foreach ($submissions_list as $submission) {
  794. if ($submission->userid == $student->userid) {
  795. $student_submissions[] = $submission;
  796. $total++;
  797. }
  798. }
  799. 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");\'>
  800. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  801. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  802. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  803. . '<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> '
  804. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  805. . ' </a>';
  806. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  807. print '<table class="table table-striped table-hover"><thead>
  808. <tr>
  809. <th scope="col">#</th>
  810. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  811. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  812. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  813. </tr>
  814. </thead><tbody>'; // "
  815. $i = 1;
  816. foreach ($student_submissions as $individual) {
  817. $date = new DateTime();
  818. $date->setTimestamp($individual->timecreated);
  819. print '<tr>';
  820. print '<td>' . ($i++) . '</td>';
  821. print '<td>' . date_format($date, 'd/m/Y H:i:s') . '</td>';
  822. print '<td>' . $individual->grade . '</td>';
  823. print '<td>
  824. <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>
  825. <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>
  826. <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>';
  827. print " </tr>\n";
  828. }
  829. print '</tbody></table>';
  830. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  831. print '</div>';
  832. }
  833. print '</div>';
  834. }
  835. print '</div>';
  836. print $OUTPUT->footer();
  837. } // function all_submissions()
  838. /// This method runs activities auto evaluation in teacher area
  839. function auto_evaluate () {
  840. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  841. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  842. exit;
  843. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  844. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  845. // Get list of exercises in the instance:
  846. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  847. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  848. // Get list of enrolled students:
  849. $params_temp = array('shortname' => 'student');
  850. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  851. $context = context_course::instance($this->course->id);
  852. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  853. $students_list = $DB->get_records_sql(
  854. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  855. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  856. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  857. print $OUTPUT->header();
  858. $this->print_main_menu();
  859. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  860. print '<ul style="list-style-type: none; margin: 1em;">';
  861. foreach ($exercises_list as $exercise) {
  862. $matches = [];
  863. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  864. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  865. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  866. if ($matches[0][0]) {
  867. 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>';
  868. } else {
  869. 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>';
  870. }
  871. } else {
  872. if ($matches[0][0]) {
  873. 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>';
  874. } else {
  875. 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>';
  876. }
  877. }
  878. }
  879. print '</ul>
  880. <center>
  881. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  882. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  883. <div id="evaluate_message" style="color: red"></div>
  884. <div id="evaluate_alerts"></div>
  885. <div>
  886. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  887. <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>
  888. </div>
  889. </center>'; // close "
  890. print ' </div>' . "\n";
  891. print ' <script>' . "\n";
  892. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  893. print ' var submissions = [';
  894. // Get list of student id have submit for each exercise:
  895. foreach ($exercises_list as $exercise) {
  896. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  897. print '
  898. {
  899. "exerciseid": "' . $exercise->id . '",
  900. "grade": ' . $exercise->grade . ',
  901. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  902. "submited": ['; // "
  903. $params_temp = array('iassign_statementid' => $exercise->id);
  904. $submited = $DB->get_records_sql( // Get userid and his grade
  905. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  906. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  907. foreach ($submited as $ss) {
  908. print($ss->userid . ',');
  909. }
  910. print '],';
  911. print '"allgrades": [';
  912. foreach ($submited as $ss) {
  913. print( $ss->grade . ',');
  914. }
  915. print ']
  916. },'; // close "
  917. } // foreach ($exercises_list as $exercise)
  918. print " ];\n";
  919. print '
  920. var total_submissions = 0;
  921. var selected_exercises;
  922. var count_steps;
  923. var value_by_step;
  924. var stoped = false;
  925. var time_interval = 5000;
  926. var var_interval;
  927. function add_hover_th (id_th, id_li) { //AJAX
  928. $("#" + id_th).hover(function() {
  929. $("#" + id_li).css("background-color", "#d9d8d8");
  930. $(this).css("background-color", "#d9d8d8");
  931. }, function() {
  932. $("#" + id_li).css("background-color", "");
  933. $(this).css("background-color", "");
  934. });
  935. }
  936. function start_evaluation () {
  937. stoped = false;
  938. //AJAX
  939. $("#progress_bar").css("display", "none");
  940. $("#evaluate_message").text("");
  941. $("#evaluate_alerts").text("");
  942. $(".added-col").remove();
  943. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  944. selected_exercises = [];
  945. var c = 0;
  946. for (var i = 0; i < exercises.length; i++) {
  947. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  948. selected_exercises[c++] = exercises[i];
  949. }
  950. }
  951. if (selected_exercises.length == 0) {
  952. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  953. return;
  954. } else {
  955. $("input:checkbox").attr("disabled", true); //AJAX
  956. for (var i = 0; i < selected_exercises.length; i++) {
  957. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  958. //AJAX
  959. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  960. $("#table-results tbody tr").each(function(e) {
  961. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  962. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  963. });
  964. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  965. }
  966. //AJAX
  967. $("#button_start").prop("disabled", true);
  968. $("#button_stop").prop("disabled", false);
  969. $("#progress_bar").css("display", "block");
  970. }
  971. total_submissions = selected_exercises.length * students.length;
  972. count_steps = 0;
  973. value_by_step = 100/total_submissions;
  974. actual_exercise = 0;
  975. actual_student = 0;
  976. actual_submission = 0;
  977. get_original_propositions();
  978. var_interval = setInterval(verifyBreak, time_interval);
  979. } // function start_evaluation()
  980. var actual_exercise;
  981. var actual_student;
  982. var actual_submission;
  983. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  984. function run_individual_evaluation () {
  985. if (stoped) return;
  986. // Verify if student really sent his answer
  987. var found = false;
  988. for (var j = 0; j < submissions.length; j++) {
  989. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  990. for (var k = 0; k < submissions[j].submited.length; k++) {
  991. if (students[actual_student] == submissions[j].submited[k]) {
  992. found = true;
  993. break;
  994. }
  995. }
  996. break;
  997. }
  998. }
  999. if (found == false) {
  1000. postResultAutoEval();
  1001. } else {
  1002. // If it was sent, search it...
  1003. var final_url = "";
  1004. 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];
  1005. for (var j = 0; j < submissions.length; j++) {
  1006. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1007. final_url = submissions[j].ilm;
  1008. break;
  1009. }
  1010. }
  1011. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1012. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1013. window.frames["ifrm"].location=final_url;
  1014. }
  1015. } // function run_individual_evaluation()
  1016. var break_student = -1;
  1017. var break_exercise = -1;
  1018. function verifyBreak () {
  1019. if (actual_student == break_student && actual_exercise == break_exercise) {
  1020. postResultAutoEval(-6);
  1021. break_student = -1;
  1022. break_exercise = -1;
  1023. return;
  1024. } else {
  1025. break_student = actual_student;
  1026. break_exercise = actual_exercise;
  1027. }
  1028. }
  1029. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1030. function getStudentAnswerURL () {
  1031. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1032. }
  1033. // This function is called by the iLM!!!
  1034. function getAutoEvalOriginalData () {
  1035. return original_propositions[actual_exercise];
  1036. }
  1037. function updateProgressBar () {
  1038. if (stoped) return;
  1039. var temp = (count_steps * value_by_step)|0;
  1040. count_steps++;
  1041. temp = temp > 100 ? 100 : temp;
  1042. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1043. if (temp >= 100) {
  1044. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1045. $("#button_start").prop("disabled", false);
  1046. $("#button_stop").prop("disabled", true);
  1047. $("input:checkbox").attr("disabled", false);
  1048. clearInterval(var_interval);
  1049. }
  1050. }
  1051. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1052. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1053. function postResultAutoEval (grade = null) {
  1054. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1055. if (grade == null) {
  1056. $("#"+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>\');
  1057. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1058. } else {
  1059. // Verify if the re-evaluation grade is the of that one registered:
  1060. var actual_value = 0;
  1061. var actual_student_grade = 0;
  1062. for (var k = 0; k < submissions.length; k++) {
  1063. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1064. actual_value = submissions[k].grade;
  1065. for (var h = 0; h < submissions[k].submited.length; h++) {
  1066. if (submissions[k].submited[h] == students[actual_student]) {
  1067. actual_student_grade = submissions[k].allgrades[h];
  1068. break;
  1069. }
  1070. }
  1071. break;
  1072. }
  1073. }
  1074. // @FeedbackConvention
  1075. if (grade < 0) {
  1076. switch (grade) {
  1077. case -1:
  1078. // Test-cases are empty:
  1079. $("#"+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>\');
  1080. var mm = actual_exercise;
  1081. $("#"+id_t).find(".details-button").click(function(e) {
  1082. $(".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>\');
  1083. });
  1084. break;
  1085. case -2:
  1086. // Test-cases were manually altered by the student (fraud!):
  1087. $("#"+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>\');
  1088. var mm = actual_exercise;
  1089. $("#"+id_t).find(".details-button").click(function(e) {
  1090. $(".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>");
  1091. });
  1092. //AJAX
  1093. $.ajax({
  1094. dataType: "html",
  1095. 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",
  1096. success: function(d) {} });
  1097. break;
  1098. case -5:
  1099. // Execution failed:
  1100. $("#"+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>\');
  1101. var mm = actual_exercise;
  1102. //AJAX
  1103. $("#"+id_t).find(".details-button").click(function(e) {
  1104. $(".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>\');
  1105. });
  1106. break;
  1107. case -6: // iLM not answering was detected in "verifyBreak()"
  1108. // The iLM are not answering:
  1109. //AJAX
  1110. $("#"+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>\');
  1111. $("#"+id_t).find(".details-button").click(function(e) {
  1112. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1113. });
  1114. break;
  1115. }
  1116. //AJAX
  1117. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1118. } else {
  1119. console.log((grade), (actual_student_grade));
  1120. if ((grade) == (actual_student_grade)) {
  1121. $("#"+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>\');
  1122. } else { // Notas diferem:
  1123. $("#"+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>\');
  1124. var mm = actual_exercise;
  1125. //AJAX
  1126. $("#"+id_t).find(".details-button").click(function(e) {
  1127. $(".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>\');
  1128. });
  1129. //AJAX
  1130. // Send to the endpoint the post_auto_eval_result to verify:
  1131. $.ajax({
  1132. dataType: "html",
  1133. 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),
  1134. success: function(d) {}
  1135. });
  1136. }
  1137. //AJAX
  1138. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1139. }
  1140. }
  1141. updateProgressBar();
  1142. // Does it must continue in the same exercise or stop?
  1143. if (actual_student < students.length) {
  1144. actual_student++;
  1145. run_individual_evaluation();
  1146. } else {
  1147. actual_student = 0;
  1148. // Does it go to next exercise or is it finished?
  1149. if (actual_exercise < selected_exercises.length) {
  1150. actual_exercise++;
  1151. run_individual_evaluation();
  1152. } else {
  1153. //AJAX
  1154. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1155. }
  1156. }
  1157. }
  1158. var original_propositions;
  1159. function get_original_propositions () {
  1160. original_propositions = [];
  1161. var count = 0;
  1162. for (var i = 0; i < exercises.length; i++) {
  1163. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1164. //AJAX
  1165. $.ajax({
  1166. dataType: "html",
  1167. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1168. success: function(d) { // variable "d" has the iLM content
  1169. original_propositions[count] = d; // exercise original content
  1170. count++;
  1171. if (count == selected_exercises.length) {
  1172. run_individual_evaluation();
  1173. }
  1174. }
  1175. });
  1176. }
  1177. }
  1178. }
  1179. function stop_evaluation () {
  1180. stoped = true;
  1181. //AJAX
  1182. $("#button_start").prop("disabled", false);
  1183. $("#button_stop").prop("disabled", true);
  1184. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1185. $("input:checkbox").attr("disabled", false);
  1186. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1187. clearInterval(var_interval);
  1188. }
  1189. var exercises = [ '; // '
  1190. foreach ($exercises_list as $exercise) {
  1191. print $exercise->id . ',';
  1192. }
  1193. print ' ];';
  1194. print ' var students = [ ';
  1195. foreach ($students_list as $student) {
  1196. print $student->userid . ',';
  1197. }
  1198. print '];';
  1199. print ' var ilms = [';
  1200. foreach ($exercises_list as $exercise) {
  1201. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1202. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1203. }
  1204. print ']';
  1205. print '</script>';
  1206. print '
  1207. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1208. <div class="modal-dialog modal-dialog-centered" role="document">
  1209. <div class="modal-content">
  1210. <div class="modal-header">
  1211. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1212. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1213. <span aria-hidden="true">&times;</span>
  1214. </button>
  1215. </div>
  1216. <div class="modal-body">
  1217. ...
  1218. </div>
  1219. <div class="modal-footer">
  1220. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1221. </div>
  1222. </div>
  1223. </div>
  1224. </div>'; //
  1225. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1226. print '<table id="table-results" class="table table-hover m-t-1">
  1227. <thead>
  1228. <tr id="cols-exercises">
  1229. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1230. </tr>
  1231. </thead>
  1232. <tbody>'; // "
  1233. foreach ($students_list as $student) {
  1234. $user = $DB->get_record('user', array('id' => $student->userid));
  1235. $avatar = new user_picture($user);
  1236. $avatar->courseid = $COURSE->id;
  1237. $avatar->link = true;
  1238. print ' <tr data-student="' . $student->userid . '">
  1239. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1240. </tr>' . "\n"; // "
  1241. }
  1242. print " </tbody>
  1243. </table>\n";
  1244. print $OUTPUT->footer();
  1245. } // function auto_evaluate()
  1246. /// This method moves an iAssign activity
  1247. function move_activity () {
  1248. global $USER, $CFG, $DB, $COURSE;
  1249. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1250. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1251. $update_entry_new_iassign = new stdClass();
  1252. $update_entry_new_iassign->id = $iassign_id;
  1253. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1254. // Update the iassign_statement
  1255. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1256. // Update file context
  1257. $c_i = context_module::instance($this->cm->id);
  1258. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1259. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1260. $path_module = context_course::instance($COURSE->id);
  1261. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1262. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1263. if ($context_file) {
  1264. $id_context = $context_file->id;
  1265. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1266. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1267. $context = context_module::instance($USER->cm); //2021/12
  1268. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1269. //TODO 2022: trocar "$iassign_statement->id" por "$iassign_statement->file"???
  1270. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1271. foreach ($files as $value) {
  1272. if ($value->get_filename() != ".") {
  1273. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1274. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1275. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1276. $destiny_context = context_module::instance($course_module->id);
  1277. $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());
  1278. $updateentry = new stdClass();
  1279. $updateentry->id = $iassign_id;
  1280. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1281. $DB->update_record("iassign_statement", $updateentry);
  1282. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1283. break;
  1284. }
  1285. }
  1286. }
  1287. //2021/12 $this->return_home_course('moved_activity');
  1288. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1289. 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);
  1290. exit;
  1291. } // function move_activity()
  1292. /// This method duplicates an iAssign activity
  1293. function duplicate_activity () {
  1294. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1295. $id = $this->cm->id;
  1296. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1297. $context = context_module::instance($this->cm->id);
  1298. $contextuser = context_user::instance($USER->id);
  1299. // Get the the iAssign acitivity to be duplicated
  1300. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1301. // Remove the current id of activity
  1302. $id_source_copy = $iassign_statement->id;
  1303. $iassign_statement->id=0;
  1304. // Include prefix (Copy of ...)
  1305. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1306. // Get the information about current author, and add this information in author_modified field
  1307. $author = $DB->get_record("user", array('id' => $USER->id));
  1308. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1309. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1310. // Store the activity in the table
  1311. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1312. // Duplicate activity file
  1313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1314. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1315. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1316. foreach ($files as $value) {
  1317. if ($value->get_filename() != ".") {
  1318. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1319. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1320. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1321. $updateentry = new stdClass();
  1322. $updateentry->id = $id_;
  1323. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1324. $updateentry->filesid = $id_;
  1325. // Update the duplicated iLM iAssign with new file id
  1326. $DB->update_record("iassign_statement", $updateentry);
  1327. }
  1328. }
  1329. }
  1330. // log event --------------------------------------------------------------------------------------
  1331. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1332. $this->return_home_course('duplicated_activity');
  1333. exit;
  1334. }
  1335. // / This method gets the content from comment and register it
  1336. function add_comment () {
  1337. global $USER, $DB;
  1338. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1339. $comment = false;
  1340. if ($submission_comment)
  1341. $comment = $this->write_comment_submission();
  1342. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1343. if (!$id_submission) {
  1344. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1345. if ($iassign_submission) {
  1346. $id_submission = $iassign_submission->id;
  1347. }
  1348. }
  1349. $content = $this->search_comment_submission($id_submission);
  1350. ob_end_clean();
  1351. header("Connection: close\r\n");
  1352. header("Content-Encoding: none\r\n");
  1353. header('Content-Type: text/html');
  1354. ob_start();
  1355. print $this->search_comment_submission($id_submission);
  1356. $size = ob_get_length();
  1357. header("Content-Length: $size");
  1358. ob_end_flush();
  1359. flush();
  1360. ob_end_clean();
  1361. // Send email to users:
  1362. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1363. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1364. }
  1365. /// This method alerts envolved to new comment sent
  1366. function send_alert_new_comment ($comment, $student_id = -1) {
  1367. global $USER, $DB, $COURSE, $SITE;
  1368. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1369. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1370. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1371. // $url_curso; $url_submissao;
  1372. $text = "<p style='margin-top: 1rem;'>\n";
  1373. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811; \n";
  1374. $modinfo = get_fast_modinfo($COURSE);
  1375. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1376. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1377. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1378. $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";
  1379. break;
  1380. }
  1381. }
  1382. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1383. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811; \n";
  1384. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1385. array(
  1386. 'id' => $this->cm->id,
  1387. 'action' => 'viewsubmission',
  1388. 'iassign_current' => $this->activity->get_activity()->id,
  1389. 'userid_iassign' => $USER->id));
  1390. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1391. $text .= "<div style='margin-left: .5rem;'>\n";
  1392. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1393. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1394. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1395. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1396. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1397. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1398. $text .= " - " . userdate(time());
  1399. $text .= "</div><div style='margin: 2rem;'>\n";
  1400. $text .= $comment;
  1401. $text .= "</div><div>\n";
  1402. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1403. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1404. $text .= "</div>\n";
  1405. // Who has to receive?
  1406. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1407. $userfrom = \core_user::get_noreply_user();
  1408. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1409. // other teachers receive also: (excepts the sender)
  1410. foreach ($teachers as $teacher) {
  1411. if ($teacher->id != $USER->id) {
  1412. email_to_user(
  1413. $teacher,
  1414. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1415. $subject,
  1416. "",
  1417. $text,
  1418. '',
  1419. '',
  1420. false,
  1421. $userfrom->email,
  1422. 'Não responda a esta mensagem' //TODO: internacionalizar
  1423. );
  1424. $message = new \core\message\message();
  1425. $message->component = 'mod_iassign';
  1426. $message->name = 'message';
  1427. $message->userfrom = core_user::get_noreply_user();
  1428. $message->userto = $teacher;
  1429. $message->subject = $subject;
  1430. $message->fullmessage = $text;
  1431. $message->fullmessageformat = FORMAT_MARKDOWN;
  1432. $message->fullmessagehtml = $text;
  1433. $message->smallmessage = $subject;
  1434. $message->notification = 1;
  1435. $message->contexturl = $url_submissao . '#comments';
  1436. $message->contexturlname = $this->activity->get_activity()->name;
  1437. $messageid = message_send($message);
  1438. }
  1439. } // foreach ($teachers as $teacher)
  1440. // and student:
  1441. $student = $DB->get_record('user', array('id' => $student_id));
  1442. $formated_text = str_replace("viewsubmission", "view", $text);
  1443. email_to_user(
  1444. $student,
  1445. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1446. $subject,
  1447. "",
  1448. $formated_text,
  1449. '',
  1450. '',
  1451. false,
  1452. $userfrom->email,
  1453. 'Não responda a esta mensagem' //TODO: internacionalizar
  1454. );
  1455. $url_student = new moodle_url('/mod/iassign/view.php',
  1456. array(
  1457. 'id' => $this->cm->id,
  1458. 'action' => 'view',
  1459. 'iassign_current' => $this->activity->get_activity()->id));
  1460. $message = new \core\message\message();
  1461. $message->component = 'mod_iassign';
  1462. $message->name = 'message';
  1463. $message->userfrom = core_user::get_noreply_user();
  1464. $message->userto = $student;
  1465. $message->subject = $subject;
  1466. $message->fullmessage = $formated_text;
  1467. $message->fullmessageformat = FORMAT_MARKDOWN;
  1468. $message->fullmessagehtml = $formated_text;
  1469. $message->smallmessage = $subject;
  1470. $message->notification = 1;
  1471. $message->contexturl = $url_student . '#comments';
  1472. $message->contexturlname = $this->activity->get_activity()->name;
  1473. $messageid = message_send($message);
  1474. } // if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  1475. else { // a student has sent the comment:
  1476. foreach ($teachers as $teacher) {
  1477. email_to_user(
  1478. $teacher,
  1479. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1480. $subject,
  1481. "",
  1482. $text,
  1483. '',
  1484. '',
  1485. false,
  1486. $userfrom->email,
  1487. 'Não responda a esta mensagem' //TODO: internacionalizar
  1488. );
  1489. $message = new \core\message\message();
  1490. $message->component = 'mod_iassign';
  1491. $message->name = 'message';
  1492. $message->userfrom = core_user::get_noreply_user();
  1493. $message->userto = $teacher;
  1494. $message->subject = $subject;
  1495. $message->fullmessage = $text;
  1496. $message->fullmessageformat = FORMAT_MARKDOWN;
  1497. $message->fullmessagehtml = $text;
  1498. $message->smallmessage = $subject;
  1499. $message->notification = 1;
  1500. $message->contexturl = $url_submissao . '#comments';
  1501. $message->contexturlname = $this->activity->get_activity()->name;
  1502. $messageid = message_send($message);
  1503. } // foreach ($teachers as $teacher)
  1504. }
  1505. } // function send_alert_new_comment($comment, $student_id = -1)
  1506. /// This method gets the content from the iLM and register it
  1507. // It could be the "exercise template" (teacher) or an answer (student)
  1508. function get_answer () {
  1509. global $USER, $CFG, $DB, $OUTPUT;
  1510. $id = $this->cm->id;
  1511. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1512. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1513. if ($submission_ajax == 1) ob_start();
  1514. $comment = false;
  1515. if ($submission_comment)
  1516. $comment = $this->write_comment_submission();
  1517. // receives data of iLM using the current activity
  1518. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1519. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1520. // receives data of submission of current activity
  1521. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1522. // receives post and get
  1523. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1524. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1525. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1526. $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)
  1527. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1528. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1529. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1530. $msg = '';
  1531. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1532. $newentry = new stdClass();
  1533. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1534. $newentry->userid = $this->userid_iassign;
  1535. $newentry->timecreated = time();
  1536. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1537. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1538. $DB->insert_record("iassign_allsubmissions", $newentry);
  1539. }
  1540. // Feedback
  1541. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1542. $str_action = "view"; // repeat
  1543. if (strtolower($iassign_ilm->name) == "igeom") {
  1544. }
  1545. $title = get_string('evaluate_iassign', 'iassign');
  1546. print $OUTPUT->header();
  1547. print $OUTPUT->box_start();
  1548. // Action = { view ; repeat ; viewsubmission }
  1549. // * '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")
  1550. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1551. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1552. $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;
  1553. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1554. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1555. print '<table width=100% >';
  1556. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1557. //TODO alterar aqui???
  1558. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1559. // empty_answer_post = No solution was posted.
  1560. if ($comment)
  1561. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1562. else
  1563. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1564. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1565. } else {
  1566. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1567. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1568. // Correct answer!!
  1569. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1570. $this->write_solution = 1; //
  1571. $status = 3;
  1572. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1573. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1574. // log record
  1575. $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;
  1576. // Trigger module viewed event.
  1577. $event = \mod_iassign\event\submission_created::create(array(
  1578. 'objectid' => $this->iassign->id,
  1579. 'context' => $this->context,
  1580. 'other' => $info
  1581. ));
  1582. $event->add_record_snapshot('course', $this->course);
  1583. $event->trigger();
  1584. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1585. // Wrong answer...: get_answer_incorrect
  1586. $status = 2;
  1587. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1588. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1589. // log record
  1590. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1591. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1592. // Trigger module viewed event.
  1593. $event = \mod_iassign\event\submission_created::create(array(
  1594. 'objectid' => $this->iassign->id,
  1595. 'context' => $this->context,
  1596. 'other' => $info
  1597. ));
  1598. $event->add_record_snapshot('course', $this->course);
  1599. $event->trigger();
  1600. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1601. // Presents to the learner the result of the automatic evaluate?
  1602. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1603. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1604. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1605. print '<tr>';
  1606. // log record
  1607. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1608. // Trigger module viewed event.
  1609. $event = \mod_iassign\event\submission_created::create(array(
  1610. 'objectid' => $this->iassign->id,
  1611. 'context' => $this->context,
  1612. 'other' => $info
  1613. ));
  1614. $event->add_record_snapshot('course', $this->course);
  1615. $event->trigger();
  1616. } else { // yes!!!
  1617. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1618. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1619. print '<tr>';
  1620. print $msg;
  1621. }
  1622. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1623. $status = 1;
  1624. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1625. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1626. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1627. print '<tr>';
  1628. // log record
  1629. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1630. $event = \mod_iassign\event\submission_created::create(array(
  1631. 'objectid' => $this->iassign->id,
  1632. 'context' => $this->context,
  1633. 'other' => $info
  1634. ));
  1635. $event->add_record_snapshot('course', $this->course);
  1636. $event->trigger();
  1637. } // if ($iassign_ilm->evaluate == 1)
  1638. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1639. print '</tr></table>';
  1640. print $OUTPUT->box_end();
  1641. // add or update evaluate
  1642. if ($this->write_solution == 1) {
  1643. $timenow = time();
  1644. // new record
  1645. if (!$iassign_submission) {
  1646. $newentry = new stdClass();
  1647. $newentry->userid = $this->userid_iassign;
  1648. // $newentry->userid = $USER->id;
  1649. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1650. $newentry->timecreated = $timenow;
  1651. $newentry->timemodified = $timenow;
  1652. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1653. $newentry->grade = round($grade_student, 2);
  1654. $newentry->status = $status;
  1655. $newentry->experiment = 1;
  1656. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1657. print_error('error_insert', 'iassign');
  1658. } else {
  1659. // Trigger module viewed event.
  1660. $event = \mod_iassign\event\submission_created::create(array(
  1661. 'objectid' => $this->iassign->id,
  1662. 'context' => $this->context
  1663. ));
  1664. $event->add_record_snapshot('course', $this->course);
  1665. $event->trigger();
  1666. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1667. }
  1668. } elseif ($iassign_submission->status != 3) {
  1669. $newentry = new stdClass();
  1670. $newentry->id = $iassign_submission->id;
  1671. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1672. $newentry->userid = $iassign_submission->userid;
  1673. $newentry->timecreated = $iassign_submission->timecreated;
  1674. $newentry->timemodified = $timenow;
  1675. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1676. $newentry->grade = round($grade_student, 2);
  1677. $newentry->status = $status;
  1678. $newentry->experiment = $iassign_submission->experiment + 1;
  1679. if (!$DB->update_record("iassign_submission", $newentry)) {
  1680. print_error('error_update', 'iassign');
  1681. //D depurar...
  1682. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1683. //D $fp = fopen("teste1.txt","w");
  1684. //D fwrite($fp,$stringAux);
  1685. } else {
  1686. // Trigger module viewed event.
  1687. $event = \mod_iassign\event\submission_updated::create(array(
  1688. 'objectid' => $this->iassign->id,
  1689. 'context' => $this->context
  1690. ));
  1691. $event->add_record_snapshot('course', $this->course);
  1692. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1693. }
  1694. } else {
  1695. if ($return_get_answer == 1) {
  1696. $newentry = new stdClass();
  1697. $newentry->id = $iassign_submission->id;
  1698. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1699. $newentry->userid = $iassign_submission->userid;
  1700. $newentry->timecreated = $iassign_submission->timecreated;
  1701. $newentry->timemodified = $timenow;
  1702. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1703. $newentry->grade = round($grade_student, 2);
  1704. $newentry->status = $status;
  1705. $newentry->experiment = $iassign_submission->experiment + 1;
  1706. if (!$DB->update_record("iassign_submission", $newentry))
  1707. print_error('error_update', 'iassign');
  1708. else {
  1709. $event = \mod_iassign\event\submission_updated::create(array(
  1710. 'objectid' => $this->iassign->id,
  1711. 'context' => $this->context
  1712. ));
  1713. $event->add_record_snapshot('course', $this->course);
  1714. $event->trigger();
  1715. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1716. print $OUTPUT->box_start();
  1717. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1718. print $OUTPUT->box_end();
  1719. }
  1720. } elseif ($return_get_answer == 2) {
  1721. print $OUTPUT->box_start();
  1722. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1723. print $OUTPUT->box_end();
  1724. } else {
  1725. print $OUTPUT->box_start();
  1726. print "
  1727. <script type='text/javascript'>
  1728. //<![CDATA[
  1729. function overwrite () {
  1730. document.formEnvio.return_get_answer.value = 1;
  1731. document.formEnvio.submit();
  1732. }
  1733. function nooverwrite () {
  1734. document.formEnvio.return_get_answer.value = 2;
  1735. document.formEnvio.submit();
  1736. }
  1737. //]]>
  1738. </script>";
  1739. $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;
  1740. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1741. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1742. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1743. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1744. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1745. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1746. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1747. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1748. <input type='hidden' name='return_get_answer'/> ";
  1749. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1750. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1751. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1752. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1753. print " </form>";
  1754. print $OUTPUT->box_end();
  1755. }
  1756. }
  1757. } // if ($this->write_solution == 1)
  1758. print $OUTPUT->footer();
  1759. if ($submission_ajax == 1) {
  1760. ob_end_clean();
  1761. print 'OK';
  1762. }
  1763. die();
  1764. } // function get_answer()
  1765. /// Export in file the answer of student.
  1766. function export_file_answer () {
  1767. global $DB;
  1768. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1769. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1770. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1771. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1772. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1773. $extensions = explode(",", $iassign_ilm->extension);
  1774. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1775. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1776. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1777. header("Pragma: public");
  1778. header("Expires: 0");
  1779. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1780. header("Cache-Control: private", false);
  1781. header("Content-Type: document/unknown");
  1782. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1783. set_time_limit(0);
  1784. print($iassign_submission->answer);
  1785. exit;
  1786. } // function export_file_answer()
  1787. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1788. // @calledby $this->export_package_answer()
  1789. //TODO Precisa terminar! //TODO_HTML
  1790. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1791. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1792. <head>
  1793. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1794. $str_html .= " </head>
  1795. <body>\n";
  1796. $tam = sizeof($array_iassign_name);
  1797. for ($ii=0; $ii<$tam; $ii++) {
  1798. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1799. }
  1800. $str_html .= "
  1801. </body>\n</html>";
  1802. return $str_html;
  1803. }
  1804. /// Export an package (zip) with all answer of students
  1805. // @calledby $this->action()
  1806. function export_package_answer () {
  1807. global $DB, $CFG, $OUTPUT;
  1808. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1809. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1810. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1811. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1812. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1813. $userid = optional_param('userid', NULL, PARAM_INT);
  1814. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1815. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1816. //TODO_HTML echo "username=$username<br/>"; exit;
  1817. $current_date = date('Y_m_d_H');
  1818. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1819. // If temporary directory under Moodle data does not exists => create it
  1820. if (!is_dir($diretorio)) {
  1821. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1822. // created directory with permissions to be seen by everyone
  1823. }
  1824. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1825. if (!is_writable($diretorio)) { // send a highlighted message!
  1826. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1827. exit; // just in case
  1828. }
  1829. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1830. $zip = new zip_archive(); // create ZIP
  1831. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1832. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1833. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1834. $vet_student_filename = array();
  1835. $vet_student_content = array();
  1836. foreach ($iassign_statements as $iassign_statement) {
  1837. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1838. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1839. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1840. $extensions = explode(",", $iassign_ilm->extension);
  1841. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1842. if ($iassign_submission) {
  1843. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1844. $student_content = $iassign_submission->answer;
  1845. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1846. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1847. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1848. if ($resp) {
  1849. $vet_student_filename[] = $student_filename;
  1850. $vet_student_content[] = $student_content;
  1851. }
  1852. else { // send a highlighted message!
  1853. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1854. exit; // just in case
  1855. }
  1856. }
  1857. } // foreach ($iassign_statements as $iassign_statement)
  1858. $zip->close(); // close the ZIP file
  1859. if (count($vet_student_filename)>0) {
  1860. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1861. $result_tf = $vet_result[0];
  1862. $filenameZip = $vet_result[1]->filename;
  1863. }
  1864. iassign_utils::download_file($zip_filename); // download the ZIP file
  1865. exit;
  1866. } // function export_package_answer()
  1867. /// Editing status of interactive activities
  1868. function edit_status () {
  1869. global $USER, $DB, $OUTPUT;
  1870. $newentry = new stdClass();
  1871. $newentry->id = $this->iassign_submission_current;
  1872. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1873. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1874. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1875. $newentry->status = $iassign_submission->status;
  1876. $newentry->teacher = $USER->id;
  1877. if (!$DB->update_record('iassign_submission', $newentry))
  1878. print_error('error_update', 'iassign');
  1879. else {
  1880. // Trigger module viewed event.
  1881. $event = \mod_iassign\event\submission_updated::create(array(
  1882. 'objectid' => $this->iassign->id,
  1883. 'context' => $this->context
  1884. ));
  1885. $event->add_record_snapshot('course', $this->course);
  1886. $event->trigger();
  1887. $this->action = 'viewsubmission';
  1888. $this->view_iassign_current();
  1889. } // if (!$DB->update_record('iassign_submission', $newentry))
  1890. } // function edit_status()
  1891. /// Editing grade of interactive activities
  1892. function edit_grade () {
  1893. global $USER, $DB, $OUTPUT;
  1894. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1895. if ($newgrade && $newgrade >= 0) {
  1896. $newentry = new stdClass();
  1897. $newentry->id = $this->iassign_submission_current;
  1898. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1899. $newentry->teacher = $USER->id;
  1900. if (!$DB->update_record('iassign_submission', $newentry))
  1901. print_error('error_update', 'iassign');
  1902. else {
  1903. // Trigger module viewed event.
  1904. $event = \mod_iassign\event\submission_updated::create(array(
  1905. 'objectid' => $this->iassign->id,
  1906. 'context' => $this->context
  1907. ));
  1908. $event->add_record_snapshot('course', $this->course);
  1909. $event->trigger();
  1910. }
  1911. } // if ($newgrade >= 0)
  1912. $this->action = 'viewsubmission';
  1913. $this->view_iassign_current();
  1914. }
  1915. /// Add or Edit interactive activities
  1916. // Get here when editing form and and submitted form data
  1917. // @calledby $this->action()
  1918. function add_edit_iassign () {
  1919. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1920. require_once('iassign_form.php');
  1921. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1922. $iassignid = $this->iassign->id;
  1923. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1924. $param->action = $this->action; // hidden
  1925. $param->id = $id; // hidden
  1926. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1927. $COURSE->cm = $id;
  1928. $COURSE->iassignid = $iassignid;
  1929. $COURSE->iassign_file_id = NULL;
  1930. $context = context_module::instance($this->cm->id);
  1931. $contextuser = context_user::instance($USER->id);
  1932. $component = 'mod_iassign';
  1933. $filearea = 'exercise';
  1934. if (!empty($this->iassign_current))
  1935. $COURSE->iassign_id = $this->iassign_current;
  1936. else
  1937. $COURSE->iassign_id = 0;
  1938. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1939. if ($this->action == 'add') {
  1940. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1941. $params_temp = array('iassignid' => $iassignid);
  1942. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1943. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1944. $total_of_activities = count($iassign_statement);
  1945. $param->iassignid = $iassignid;
  1946. $param->name = "";
  1947. $param->oldname = "";
  1948. $param->type_iassign = 3;
  1949. $param->proposition = "";
  1950. $author = $DB->get_record("user", array("id" => $USER->id));
  1951. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1952. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1953. $param->author = $param->author_name;
  1954. $param->author_modified = $param->author_modified_name;
  1955. $COURSE->iassign_list = array();
  1956. $param->iassign_list = array();
  1957. if ($iassign_statement) {
  1958. foreach ($iassign_statement as $iassign) {
  1959. $iassignid = $iassign->id;
  1960. $param->iassign_list[$iassignid] = 0;
  1961. $COURSE->iassign_list[$iassignid] = new stdClass();
  1962. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1963. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1964. $COURSE->iassign_list[$iassignid]->enable = 1;
  1965. } // foreach ($iassign_statement as $iassign)
  1966. }
  1967. $param->iassign_ilmid = 0;
  1968. $param->file = 0;
  1969. $param->fileold = 0;
  1970. $param->filename = "";
  1971. $param->grade = $iassign_data->grade;
  1972. $param->timemodified = time();
  1973. $param->timecreated = time();
  1974. $param->timeavailable = $iassign_data->timeavailable;
  1975. $param->timedue = $iassign_data->timedue;
  1976. $param->preventlate = $iassign_data->preventlate;
  1977. $param->test = $iassign_data->test;
  1978. $param->special_param1 = 0;
  1979. $param->visible = 1;
  1980. $param->max_experiment = $iassign_data->max_experiment;
  1981. $param->dependency = 0;
  1982. $param->automatic_evaluate = 1;
  1983. $param->show_answer = 1;
  1984. } // if ($this->action == 'add')
  1985. elseif ($this->action == 'edit') {
  1986. $COURSE->iassign_list = array();
  1987. $this_activity = $this->activity->get_activity();
  1988. if ($this_activity != null) { // first enter here: fill form data
  1989. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1990. $param->iassign_id = $iassign_statement_current->id; // oculto
  1991. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1992. $param->name = $iassign_statement_current->name;
  1993. $param->oldname = $iassign_statement_current->name;
  1994. $param->type_iassign = $iassign_statement_current->type_iassign;
  1995. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1996. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1997. $param->author_name = $iassign_statement_current->author_name; // oculto
  1998. $param->author = $iassign_statement_current->author_name;
  1999. $author = $DB->get_record("user", array('id' => $USER->id));
  2000. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  2001. $param->author_modified = $param->author_modified_name;
  2002. $dependency = explode(';', $iassign_statement_current->dependency);
  2003. $param->iassign_list = array();
  2004. // Select all other iAssign activities inside this block with dependency
  2005. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  2006. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2007. $array_dependency = array();
  2008. $subdependency = "";
  2009. $sub_subdependency = "";
  2010. // Dependents on this exercise
  2011. if ($iassign_statement_dependency) {
  2012. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2013. // to whom this exercise depends
  2014. foreach ($inter as $tmp)
  2015. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2016. $list_dependency = $subdependency . $sub_subdependency;
  2017. $array_dependency = explode(";", $list_dependency);
  2018. }
  2019. // Get all activities in the same iAssigment block:
  2020. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2021. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2022. $total_of_activities = count($all_others_iassign_statement) + 1;
  2023. $inter = array();
  2024. if ($all_others_iassign_statement) {
  2025. foreach ($all_others_iassign_statement as $iassign)
  2026. if (in_array($iassign->id, $dependency))
  2027. $inter[] = $iassign->id;
  2028. }
  2029. if ($all_others_iassign_statement) {
  2030. foreach ($all_others_iassign_statement as $iassign) {
  2031. $iassignid = $iassign->id;
  2032. $COURSE->iassign_list[$iassignid] = new stdClass();
  2033. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2034. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2035. if (in_array($iassignid, $dependency))
  2036. $param->iassign_list[$iassignid] = 1;
  2037. else
  2038. $param->iassign_list[$iassignid] = 0;
  2039. if (in_array($iassignid, $array_dependency))
  2040. $COURSE->iassign_list[$iassignid]->enable = 0;
  2041. else
  2042. $COURSE->iassign_list[$iassignid]->enable = 1;
  2043. } // foreach ($all_others_iassign_statement as $iassign)
  2044. } // if ($all_others_iassign_statement)
  2045. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2046. $param->fileold = 0;
  2047. $param->filesid = 0;
  2048. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2049. $param->filename = '';
  2050. $param->grade = $iassign_statement_current->grade;
  2051. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2052. $param->timeavailable = $iassign_statement_current->timeavailable;
  2053. $param->timedue = $iassign_statement_current->timedue;
  2054. $param->preventlate = $iassign_statement_current->preventlate;
  2055. $param->test = $iassign_statement_current->test;
  2056. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2057. $param->position = $iassign_statement_current->position; // hidden
  2058. $param->visible = $iassign_statement_current->visible;
  2059. $param->max_experiment = $iassign_statement_current->max_experiment;
  2060. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2061. $param->show_answer = $iassign_statement_current->show_answer;
  2062. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2063. //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2064. //2022/02 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id); // em alguns "_files.id" tem 'file' NAO 'id'
  2065. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file); // It must have: {files}->id=$iassign_statement_current->file
  2066. if ($files) {
  2067. foreach ($files as $file) {
  2068. if ($file->get_filename() != '.') {
  2069. $param->filename = $file->get_filename();
  2070. $param->file = $file->get_id();
  2071. $param->fileold = $file->get_id();
  2072. $COURSE->iassign_file_id = $file->get_id();
  2073. }
  2074. }
  2075. }
  2076. //TODO //MOOC2014 -- inicio
  2077. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2078. //D if ($iassign_ilm_configs) {
  2079. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2080. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2081. //D } //MOOC2014 -- fim
  2082. } // if ($this_activity != null)
  2083. } // elseif ($this->action == 'edit')
  2084. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2085. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2086. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2087. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2088. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2089. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2090. $param->position = $total_of_activities;
  2091. // Create form and associate its data
  2092. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2093. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2094. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2095. if (isset($param->iassign_ilmid)) {
  2096. // array is additional atributes to 'form'
  2097. // '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)"
  2098. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2099. }
  2100. else {
  2101. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2102. }
  2103. $mform->set_data($param); // define data in the form
  2104. if ($mform->is_cancelled()) {
  2105. $this->return_home_course('iassign_cancel');
  2106. exit;
  2107. }
  2108. else { // else if ($mform->is_cancelled())
  2109. $result = $mform->get_data();
  2110. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2111. if ($result) {
  2112. $result->context = $context;
  2113. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2114. $result->grade = 0;
  2115. if ($result->type_iassign == 1) {
  2116. $result->automatic_evaluate = 0;
  2117. $result->show_answer = 0;
  2118. }
  2119. elseif ($result->automatic_evaluate == 0)
  2120. $result->show_answer = 0;
  2121. // $_POST['iassign_list']
  2122. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2123. if ($result->iassign_list) {
  2124. foreach ($result->iassign_list as $key => $value)
  2125. $result->dependency .= $key . ';';
  2126. }
  2127. else
  2128. $result->dependency = 0;
  2129. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2130. //TODO Then get it directly from the form data $_POST!
  2131. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2132. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2133. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2134. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2135. if ($this->action == 'add') {
  2136. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2137. if ($iassign_statement_name) {
  2138. $this->return_home_course('error_iassign_name');
  2139. die();
  2140. }
  2141. // Really insert the new iActivity in table '*_iassign_statement'
  2142. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2143. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2144. // Trigger module viewed event.
  2145. $event = \mod_iassign\event\iassign_created::create(array(
  2146. 'objectid' => $iassignid,
  2147. 'context' => $context
  2148. ));
  2149. $event->add_record_snapshot('course', $this->course);
  2150. $event->trigger();
  2151. $this->return_home_course('iassign_add');
  2152. } // if ($this->action == 'add')
  2153. elseif ($this->action == 'edit') {
  2154. $iassignid = $this->activity->update_iassign($result);
  2155. $this->activity->update_calendar($iassignid, $result->oldname);
  2156. // Trigger module viewed event.
  2157. $event = \mod_iassign\event\iassign_updated::create(array(
  2158. 'objectid' => $iassignid,
  2159. 'context' => $context
  2160. ));
  2161. $event->add_record_snapshot('course', $this->course);
  2162. $event->trigger();
  2163. $this->return_home_course('iassign_update');
  2164. } // elseif ($this->action == 'edit')
  2165. die();
  2166. } // if ($result)
  2167. } // else if ($mform->is_cancelled())
  2168. print $OUTPUT->header();
  2169. $mform->display();
  2170. print $OUTPUT->footer();
  2171. die();
  2172. } // function add_edit_iassign()
  2173. /// Search for dependencies
  2174. function search_dependency ($search_iassing_id, $iassign_statement) {
  2175. global $DB, $OUTPUT;
  2176. $dependency = "";
  2177. if ($iassign_statement)
  2178. foreach ($iassign_statement as $iassign) {
  2179. $inter_dependency = explode(';', $iassign->dependency);
  2180. if (in_array($search_iassing_id, $inter_dependency)) {
  2181. $dependency .= $iassign->id . ";";
  2182. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2183. } // if (in_array($search_iassing_id, $inter_dependency))
  2184. } // foreach ($iassign_statement as $iassign)
  2185. return $dependency;
  2186. }
  2187. /// Search for "sub"dependency
  2188. function search_sub_dependency ($search_iassing_id) {
  2189. global $DB, $OUTPUT;
  2190. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2191. $dependency = "";
  2192. if ($iassign_statement) {
  2193. $inter_dependency = explode(';', $iassign_statement->dependency);
  2194. foreach ($inter_dependency as $tmp) {
  2195. if ($tmp != 0)
  2196. $dependency .= $tmp . ";";
  2197. $dependency .= $this->search_sub_dependency($tmp);
  2198. } // foreach ($inter_dependency as $tmp)
  2199. } // if ($iassign_statement)
  2200. return $dependency;
  2201. }
  2202. // Warning message
  2203. static function warning_message_iassign ($strcode) {
  2204. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2205. }
  2206. /// Update grade of iAssign
  2207. // Called always any iAssign activity is created
  2208. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2209. static function update_grade_iassign ($iassignid) {
  2210. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2211. require_once($CFG->libdir . '/gradelib.php');
  2212. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2213. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2214. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2215. // Each iAssign item is associated with one item on the "gradebook"
  2216. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2217. //$sum_grade = 0;
  2218. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2219. //foreach($grade as $tmp) {
  2220. // $sum_grade += $tmp->grade;
  2221. // }
  2222. //1 Solution 1
  2223. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2224. //1 $sum_grade = 0; //1
  2225. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2226. //2 Solution 2
  2227. $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
  2228. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2229. if (key($array_sum_grade))
  2230. $sum_grade = key($array_sum_grade); //2
  2231. else
  2232. $sum_grade = 0; //2
  2233. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2234. $grades = NULL;
  2235. $params_temp = array('itemname' => $grade_iassign->name);
  2236. $params_temp['iteminstance'] = $iassignid;
  2237. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2238. //2016 if ($sum_grade != 0) {
  2239. $params_temp['grademax'] = $sum_grade;
  2240. $params_temp['rawgrademax'] = $sum_grade;
  2241. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2242. $params_temp['grademin'] = 0;
  2243. // @calls /lib/gradelib.php: call to grade_item->insert()
  2244. //TODO: is there any error here in Moodle version 3.0?
  2245. //TODO: Incorrect property 'grademax' found when inserting grade object
  2246. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2247. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2248. }
  2249. /// Update grade of student
  2250. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2251. global $CFG, $DB, $OUTPUT;
  2252. require_once($CFG->libdir . '/gradelib.php');
  2253. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2254. // Review all the student submission for this iAssign activity
  2255. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2256. $total_grade = 0;
  2257. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2258. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2259. if ($iassign_submission)
  2260. $total_grade += $iassign_submission->grade;
  2261. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2262. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2263. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2264. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2265. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2266. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2267. $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
  2268. if (key($array_sum_grade))
  2269. $sum_grade = key($array_sum_grade); //2
  2270. else
  2271. $sum_grade = 0; //2
  2272. $grades['userid'] = $userid;
  2273. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2274. $params_temp = array('itemname' => $grade_iassign->name);
  2275. $params_temp['iteminstance'] = $iassignid;
  2276. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2277. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2278. $params_temp['grademax'] = $sum_grade;
  2279. $params_temp['rawgrademax'] = $sum_grade;
  2280. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2281. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2282. }
  2283. /// Display caption of icons - to the bottom page of teacher's report
  2284. function view_legend_icons () {
  2285. global $USER, $CFG, $DB, $OUTPUT;
  2286. $id = $this->cm->id;
  2287. if ($this->action == 'print')
  2288. print '<table border=1 width=100%><tr>';
  2289. else
  2290. print '<table width=100%><tr>';
  2291. print '<td >';
  2292. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2293. if ($this->action != 'print') {
  2294. $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";
  2295. $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";
  2296. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2297. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2298. } // if ($this->action != 'print')
  2299. print '</tr></table>' . "\n";
  2300. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2301. print '</td></tr></table>' . "\n";
  2302. } // function view_legend_icons()
  2303. /// Display activity current
  2304. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2305. function view_iassign_current () {
  2306. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2307. $id = $this->cm->id;
  2308. $iassignid = $this->iassign->id;
  2309. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2310. $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
  2311. // 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 ...
  2312. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2313. if (!$iassign_statement_activity_item) {
  2314. print $OUTPUT->header();
  2315. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2316. print $OUTPUT->footer();
  2317. exit;
  2318. }
  2319. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2320. $ilm_name = '';
  2321. if ($ilm->ilm)
  2322. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2323. // 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
  2324. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2325. // log record
  2326. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2327. //Trigger module viewed event.
  2328. $event = \mod_iassign\event\submission_viewed::create(array(
  2329. 'objectid' => $iassign->id,
  2330. 'context' => $this->context,
  2331. 'other' => $info
  2332. ));
  2333. $event->add_record_snapshot('course', $this->course);
  2334. $event->trigger();
  2335. // Search of iLM data used in the current activity
  2336. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2337. // Add actual activity to navbar:
  2338. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2339. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2340. print $OUTPUT->header();
  2341. if ($this->action == 'viewsubmission') {
  2342. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2343. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2344. else
  2345. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2346. } else {
  2347. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2348. }
  2349. if ($iassign_submission)
  2350. $this->update_comment($iassign_submission->id);
  2351. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2352. $file = $iassign_statement_activity_item->id;
  2353. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2354. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2355. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2356. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2357. $this->bottonPost = 0; // hide submit button
  2358. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2359. $this->view_iassign = false; // disable visualization of activity
  2360. $repeat = "";
  2361. $last_iassign = "";
  2362. $student_answer = "";
  2363. $comment = "";
  2364. // *** Teacher access (view learner's submission)
  2365. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2366. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2367. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2368. // ---> access teacher for test
  2369. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2370. $this->bottonPost = 1;
  2371. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2372. $this->activity->view_dates();
  2373. $USER->iassignEdit = $this->bottonPost;
  2374. $this->activity->show_info_iassign();
  2375. if ($iassign_submission) {
  2376. //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;
  2377. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2378. } else {
  2379. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2380. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2381. }
  2382. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2383. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2384. // Prepare tags to present the iLM
  2385. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2386. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2387. // *** (end) Teacher access (view the activity)
  2388. // *** Teacher access (view learner's submission to the activity)
  2389. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2390. // It is teacher or 'nonediting teacher' that can evaluate
  2391. // ----> area teacher evaluate
  2392. $row = optional_param('row', 0, PARAM_INT);
  2393. $column = optional_param('column', 0, PARAM_INT);
  2394. $link_next = iassign_icons::insert('right_disable');
  2395. $link_previous = iassign_icons::insert('left_disable');
  2396. $link_up = iassign_icons::insert('up_disable');
  2397. $link_down = iassign_icons::insert('down_disable');
  2398. if (isset($USER->matrix_iassign[$row][$column])) {
  2399. $has_row_column = True;
  2400. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2401. }
  2402. else {
  2403. $has_row_column = False;
  2404. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2405. }
  2406. $msgViewAction = "view.php?action=viewsubmission&id=$id&iassign_submission_current=";
  2407. $msgUserId_current = "&userid_iassign=" . $this->userid_iassign . "&iassign_current=";
  2408. // next_activity
  2409. if ($has_row_column && $element_matrix_iassign->iassign_next != - 1) {
  2410. $url_next = $msgViewAction . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  2411. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2412. }
  2413. // previous_activity
  2414. if ($has_row_column && $element_matrix_iassign->iassign_previous != - 1) {
  2415. $url_previous = $msgViewAction . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . $msgUserId_current . $element_matrix_iassign->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  2416. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2417. }
  2418. // previous_student
  2419. if ($has_row_column && $element_matrix_iassign->user_next != - 1) {
  2420. $url_down = $msgViewAction . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  2421. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2422. }
  2423. // next_student
  2424. if ($has_row_column && $element_matrix_iassign->user_previous != - 1) {
  2425. $url_up = $msgViewAction . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $element_matrix_iassign->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  2426. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2427. }
  2428. if ($iassign_submission) {
  2429. $student_answer = $iassign_submission->answer;
  2430. }
  2431. $last_iassign = get_string('last_iassign', 'iassign');
  2432. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2433. // Messages related to due date (and user role)
  2434. $this->activity->view_dates();
  2435. print $OUTPUT->box_start();
  2436. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2437. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2438. if ($user_data) // additional security (if occurs programming errors in $$url_next, $url_previous...)
  2439. print $OUTPUT->user_picture($user_data);
  2440. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2441. print '</td>' . "\n";
  2442. print '<td width=20% align=right>' . "\n";
  2443. print '<table width=50 cellpadding="0">';
  2444. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2445. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2446. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2447. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2448. print '</table>' . "\n";
  2449. print '</td></tr></table>' . "\n";
  2450. print $OUTPUT->box_end();
  2451. print $OUTPUT->box_start();
  2452. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2453. print '<td width=60% valign="top">' . "\n";
  2454. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2455. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2456. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2457. $resp = get_string('yes');
  2458. else
  2459. $resp = get_string('no');
  2460. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2461. if ($iassign_statement_activity_item->show_answer == 1)
  2462. $resp = get_string('yes');
  2463. else
  2464. $resp = get_string('no');
  2465. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2466. print '</td>';
  2467. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2468. print '<td width=40% valign="top" align="left">';
  2469. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2470. // check status of solution sent by the student
  2471. if ($iassign_submission) {
  2472. switch ($iassign_submission->status) {
  2473. case 3 :
  2474. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2475. break;
  2476. case 2 :
  2477. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2478. break;
  2479. case 1 :
  2480. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2481. break;
  2482. default :
  2483. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2484. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2485. } // switch ($iassign_submission->status)
  2486. }
  2487. else { // if ($iassign_submission)
  2488. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2489. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2490. }
  2491. // update_status
  2492. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2493. $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);
  2494. print " <script type='text/javascript'>
  2495. //<![CDATA[
  2496. function overwriteStatus (newstatus) {
  2497. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2498. document.formEditStatus.return_status.value=newstatus;
  2499. document.formEditStatus.submit();
  2500. }
  2501. else
  2502. document.formEditStatus.return_status.value=-1;
  2503. }
  2504. //]]>
  2505. </script>";
  2506. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2507. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2508. 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";
  2509. print " <input type='hidden' name='return_status'>\n";
  2510. print "</form>\n";
  2511. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2512. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2513. $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);
  2514. print "
  2515. <script type='text/javascript'>
  2516. //<![CDATA[
  2517. function overwriteGrade (newgrade,maxgrade) {
  2518. if (newgrade<0 || newgrade>maxgrade) {
  2519. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2520. document.formEditGrade.return_grade.value=-1;
  2521. document.formEditGrade.submit();
  2522. }
  2523. else {
  2524. document.formEditGrade.return_grade.value=newgrade;
  2525. document.formEditGrade.submit();
  2526. }
  2527. }
  2528. //]]>
  2529. </script>";
  2530. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2531. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2532. print " <input type='text' name='grade' size='6'>";
  2533. print " <input type='hidden' name='return_grade'> ";
  2534. 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";
  2535. print "</form>";
  2536. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2537. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2538. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2539. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2540. if ($teacher)
  2541. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2542. } // if ($iassign_submission->experiment > 0)
  2543. print '</td>';
  2544. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2545. print '</tr></table>';
  2546. print $OUTPUT->box_end();
  2547. $USER->iassignEdit = $this->bottonPost;
  2548. print activity::toggle_columns_script();
  2549. if ($iassign_submission && $allow_resubmission) {
  2550. // Put the iLM to
  2551. print $OUTPUT->box_start();
  2552. print '<p><strong>' . $last_iassign . '</strong></p>';
  2553. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2554. $enderecoPOST = "";
  2555. // Prepare tags to present the iLM
  2556. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2557. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2558. print $OUTPUT->box_end();
  2559. } // if ($iassign_submission && $allow_resubmission)
  2560. else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2561. // If '$student_answer' is empty, then the student does not submit any solution to the exercice
  2562. // ATTENTION: exception used by iGeom (exercise with "script")
  2563. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2564. if (substr($ilm_name, 0, 5)=="igeom") {
  2565. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2566. $loadTeacherActivity = true;
  2567. }
  2568. else
  2569. if (!$student_answer) { //2022/01 this student does not submit any soluction => load the teacher content
  2570. $loadTeacherActivity = true;
  2571. }
  2572. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2573. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2574. print activity::toggle_columns_script();
  2575. // Prepare tags to present the iLM
  2576. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2577. }
  2578. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2579. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2580. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2581. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2582. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2583. // *** (end) Teacher access (view learner's submission to the activity)
  2584. // *** Student access (view the activity)
  2585. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2586. // It could be the learner (he could send or resend the activity)
  2587. // ---> access student
  2588. $time_now = time();
  2589. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2590. // activity of type example - not submit button for submission
  2591. $this->view_iassign = true;
  2592. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2593. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2594. // activity of type test - iLM automatic evaluator - submit button for submission
  2595. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2596. $this->bottonPost = 1;
  2597. $this->view_iassign = true;
  2598. } else
  2599. $this->view_iassign = false;
  2600. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2601. // activity of type exercise (learner can send his answer, if yet open...)
  2602. $this->view_iassign = true;
  2603. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2604. $this->view_iassign = false;
  2605. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2606. $this->bottonPost = 1; // allow the submit button
  2607. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2608. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2609. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2610. if (!$iassign_submission) {
  2611. $str_iassign_submission_id = '';
  2612. $str_iassign_submission_answer = '';
  2613. }
  2614. else {
  2615. $str_iassign_submission_id = $iassign_submission->id;
  2616. $str_iassign_submission_answer = $iassign_submission->answer;
  2617. }
  2618. if ($this->action != 'repeat') {
  2619. $repeat = "<a href='view.php?action=repeat&id="
  2620. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2621. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2622. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2623. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2624. }
  2625. $this->bottonPost = 1;
  2626. $this->write_solution = 1; // can register his submission
  2627. $student_answer = $str_iassign_submission_answer;
  2628. }
  2629. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2630. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2631. $last_iassign = get_string('last_iassign', 'iassign');
  2632. if ($iassign_submission) {
  2633. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2634. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2635. $student_answer = $iassign_submission->answer;
  2636. } else {
  2637. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2638. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2639. }
  2640. }
  2641. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2642. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2643. $this->bottonPost = 1;
  2644. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2645. } else {
  2646. $last_iassign = get_string('last_iassign', 'iassign');
  2647. if ($iassign_submission) {
  2648. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2649. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2650. $student_answer = $iassign_submission->answer;
  2651. } else {
  2652. // Symbol of "redo activity"
  2653. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2654. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2655. }
  2656. }
  2657. } // elseif ($iassign_statement_activity_item->test == 1)
  2658. elseif ($iassign_statement_activity_item->test == 0)
  2659. $this->view_iassign = false;
  2660. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2661. if ($iassign_submission)
  2662. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2663. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2664. else
  2665. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2666. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2667. $this->activity->view_dates();
  2668. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2669. print $OUTPUT->box_start();
  2670. print '<table width=100% border=0 valign="top">' . "\n";
  2671. print '<tr><td width=60% valign="top">' . "\n";
  2672. $flag_dependency = true;
  2673. if ($iassign_statement_activity_item->type_iassign == 3) {
  2674. if ($iassign_statement_activity_item->dependency == 0) {
  2675. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2676. } else {
  2677. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2678. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2679. foreach ($dependencys as $dependency) {
  2680. if ($dependency) {
  2681. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2682. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2683. if ($dependencysubmissions) {
  2684. if ($dependencysubmissions->status == 3)
  2685. $icon = iassign_icons::insert('correct');
  2686. elseif ($dependencysubmissions->status == 2) {
  2687. $icon = iassign_icons::insert('incorrect');
  2688. $flag_dependency = false;
  2689. } elseif ($dependencysubmissions->status == 1) {
  2690. $icon = iassign_icons::insert('post');
  2691. $flag_dependency = false;
  2692. } elseif ($dependencysubmissions->status == 0) {
  2693. $icon = iassign_icons::insert('not_post');
  2694. $flag_dependency = false;
  2695. }
  2696. } else {
  2697. $icon = iassign_icons::insert('not_post');
  2698. $flag_dependency = false;
  2699. } // if ($dependencysubmissions)
  2700. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2701. } // if ($dependency)
  2702. } // foreach ($dependencys as $dependency)
  2703. } // if ($iassign_statement_activity_item->dependency == 0)
  2704. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2705. if ($flag_dependency == false) {
  2706. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2707. $this->view_iassign = false;
  2708. print '</tr></table>' . "\n";
  2709. }
  2710. else {
  2711. $this->view_iassign = true;
  2712. print '</td>' . "\n";
  2713. } // if ($flag_dependency == false)
  2714. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2715. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2716. // receiver=1 - message to teacher
  2717. // receiver=2 - message to student
  2718. if ($iassign_submission) {
  2719. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2720. if ($verify_message)
  2721. $comment = iassign_icons::insert('comment_unread');
  2722. }
  2723. print '<td width=40% valign="top" align="left">';
  2724. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2725. if ($iassign_statement_activity_item->show_answer == 1) {
  2726. // check status of solution sent by the student
  2727. if ($iassign_submission) {
  2728. switch ($iassign_submission->status) {
  2729. case 3 :
  2730. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2731. break;
  2732. case 2 :
  2733. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2734. break;
  2735. case 1 :
  2736. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2737. break;
  2738. default :
  2739. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2740. $repeat = "";
  2741. $last_iassign = "";
  2742. } // switch ($iassign_submission->status)
  2743. } else {
  2744. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2745. $repeat = "";
  2746. $last_iassign = "";
  2747. }
  2748. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2749. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2750. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2751. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2752. if ($iassign_statement_activity_item->max_experiment == 0)
  2753. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2754. else {
  2755. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2756. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2757. $repeat = "";
  2758. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2759. $this->bottonPost = 0;
  2760. $this->write_solution = 0;
  2761. }
  2762. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2763. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2764. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2765. if ($teacher)
  2766. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2767. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2768. } // if ($iassign_statement_activity_item->show_answer==1)
  2769. else {
  2770. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2771. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2772. $repeat = "";
  2773. $last_iassign = "";
  2774. } elseif ($iassign_submission->status == 1) {
  2775. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2776. }
  2777. }
  2778. print '</td>';
  2779. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2780. print '</tr></table>' . "\n";
  2781. // Presents the iLM
  2782. print '<table width=100% border=0 valign="top">' . "\n";
  2783. print '<td width=80% align="left">';
  2784. 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\".
  2785. print '<td width=20% align="rigth">';
  2786. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2787. print $repeat; // symbol of "redo activity"
  2788. print '</td></tr></table>' . "\n";
  2789. //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)'
  2790. print activity::toggle_columns_script();
  2791. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2792. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2793. $output = '';
  2794. if (!$iassign_ilm) {
  2795. $iassign_ilm = new stdClass();
  2796. $iassign_ilm->file_jar = "";
  2797. }
  2798. $output .= $OUTPUT->box_start();
  2799. $USER->iassignEdit = $this->bottonPost;
  2800. // ---
  2801. // Presents the iLM
  2802. // Prepare tags to present the iLM
  2803. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2804. $student_answer = ""; //?
  2805. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2806. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2807. $student_answer = "";
  2808. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2809. } else {
  2810. // When student is redoing his activity
  2811. // ATTENTION: exception used by iGeom (exercise with "script")
  2812. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2813. if (substr($ilm_name, 0, 5)=="igeom") {
  2814. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2815. $loadTeacherActivity = true;
  2816. }
  2817. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2818. }
  2819. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2820. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2821. //1 $history_comment = '';
  2822. //1 if ($iassign_submission) {
  2823. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2824. //1 }
  2825. //1 if (!empty($history_comment)) {
  2826. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2827. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2828. //1 $output .= $history_comment;
  2829. //1 $output .= "</table>\n";
  2830. //1 }
  2831. //1 $output .= "</form></center>\n";
  2832. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2833. //1 }
  2834. $output .= $OUTPUT->box_end();
  2835. print $output;
  2836. } // if ($this->view_iassign)
  2837. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2838. } // if ($this->view_iassign)
  2839. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2840. else
  2841. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2842. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2843. print '<table width=100% border=0 valign="top">' . "\n";
  2844. print '<tr><td width=60% valign="top">' . "\n";
  2845. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2846. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2847. print '</tr></table>' . "\n";
  2848. $student_answer = "";
  2849. $enderecoPOST = "";
  2850. // Prepare tags to present the iLM
  2851. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2852. print $output;
  2853. }
  2854. //2020 Frame with area to send and read comments (in this point to allow everyone read)
  2855. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2856. 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
  2857. // Put a block with area to sent/answer comments
  2858. $output = '';
  2859. $history_comment = '';
  2860. $row = optional_param('row', 0, PARAM_INT);
  2861. $column = optional_param('column', 0, PARAM_INT);
  2862. if ($iassign_submission) {
  2863. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2864. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2865. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2866. }
  2867. else {
  2868. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2869. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2870. }
  2871. $output .= $OUTPUT->box_start();
  2872. //if (!empty($history_comment)) {
  2873. $output .= "<a id='comments'></a>";
  2874. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2875. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2876. $output .= "</table>";
  2877. print " <script type='text/javascript'>
  2878. //<![CDATA[
  2879. function submit_comment(url) {
  2880. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2881. var formData = new FormData();
  2882. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2883. var request = new XMLHttpRequest();
  2884. request.open('POST', url);
  2885. document.getElementById('comments_history').innerHTML = '';
  2886. request.onload = function (e) {
  2887. if (request.readyState === 4) {
  2888. if (request.status === 200) {
  2889. document.getElementById('comments_history').innerHTML = request.responseText;
  2890. document.getElementById('check-message-success').style.visibility = 'visible';
  2891. setTimeout(function(){
  2892. document.getElementById('check-message-success').style.visibility = 'hidden';
  2893. }, 3000);
  2894. }
  2895. }
  2896. };
  2897. document.formEnvioComment.submission_comment.value = '';
  2898. request.send(formData);
  2899. }
  2900. function event_text_area (event) {
  2901. if (event.ctrlKey && event.keyCode == 13)
  2902. submit_comment('" . $enderecoPOSTcomment . "');
  2903. }
  2904. //]]>
  2905. </script>";
  2906. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2907. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2908. $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";
  2909. $output .= "</form> </center>\n";
  2910. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2911. // }
  2912. $output .= $OUTPUT->box_end();
  2913. print $output;
  2914. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2915. // final block 'studant'
  2916. print $OUTPUT->footer();
  2917. die();
  2918. } // function view_iassign_current()
  2919. /// Export the data from performance report into CSV file format
  2920. function export_csv () {
  2921. global $USER, $CFG, $DB, $OUTPUT;
  2922. $str = "";
  2923. $fields = "student_id, student_name";
  2924. // Finding all iassign activities for the iassign:
  2925. $id = $this->cm->id;
  2926. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2927. $c = 1;
  2928. foreach ($iassign_list as $iassign) {
  2929. $fields .= ", activity_id_" . $c . ", activity_name_" . $c . ", total_submissions_activity_" . $c . ", grade_activity_" . $c . ""
  2930. . ", status_activity_" . $c . ", ilm_id_activity_" . $c . ", ilm_name_activity_" . $c;
  2931. $c++;
  2932. }
  2933. // Finding enrolled students:
  2934. $params_temp = array('shortname' => 'student');
  2935. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2936. $context = context_course::instance($this->course->id);
  2937. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2938. $students = $DB->get_records_sql(
  2939. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2940. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2941. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2942. foreach ($students as $student) {
  2943. $str .= $student->userid . ',';
  2944. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2945. foreach ($iassign_list as $iassign) {
  2946. $str .= ',' . $iassign->id . ',';
  2947. $str .= '"' . $iassign->name . '",';
  2948. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2949. if ($student_submissions) {
  2950. $str .= $student_submissions->experiment . ',';
  2951. $str .= $student_submissions->grade . ',';
  2952. switch ($student_submissions->status) {
  2953. case 3:
  2954. $str .= '"correct",';
  2955. break;
  2956. case 2:
  2957. $str .= '"incorrect",';
  2958. break;
  2959. case 1:
  2960. $str .= '"post",';
  2961. break;
  2962. case 0:
  2963. $str .= '"not_post",';
  2964. break;
  2965. }
  2966. }
  2967. else {
  2968. $str .= ',,"not_post",';
  2969. }
  2970. $str .= $iassign->iassign_ilmid . ',';
  2971. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2972. $str .= '"' . $ilm_activity->name . '"';
  2973. }
  2974. $str .= "\n";
  2975. }
  2976. $str = $fields . "\n" . $str;
  2977. header("Content-type: text/csv");
  2978. header("Content-disposition: attachment; filename=report.csv");
  2979. header("Pragma: no-cache");
  2980. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2981. header('Content-Length: ' . strlen($str));
  2982. header('Connection: close');
  2983. print $str;
  2984. flush();
  2985. } // function export_csv()
  2986. /// Display report of performance
  2987. function report () {
  2988. global $USER, $CFG, $DB, $OUTPUT;
  2989. $id = $this->cm->id;
  2990. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2991. if ($this->action != 'print') {
  2992. $title = get_string('report', 'iassign');
  2993. print $OUTPUT->header();
  2994. } // if ($this->action != 'print')
  2995. $this->print_main_menu();
  2996. print $OUTPUT->box_start();
  2997. $this->view_legend_icons();
  2998. print $OUTPUT->box_end();
  2999. if ($this->action == 'print')
  3000. print '<table border=1 width="100%">' . "\n";
  3001. else
  3002. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  3003. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3004. // $num = array();
  3005. $i = 1;
  3006. $num = array();
  3007. $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;";
  3008. foreach ($iassign_list as $iassign) { // for all exercise in this block
  3009. $test_exercise = "";
  3010. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3011. if (($iassign_submission) && $iassign->type_iassign < 3) {
  3012. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  3013. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  3014. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  3015. $num[$i] = new stdClass();
  3016. $num[$i]->name = $iassign->name;
  3017. $num[$i]->id = $i;
  3018. $num[$i]->iassignid = $iassign->id;
  3019. print ' <tr >' . "\n";
  3020. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  3021. print "<td class=\"cell c0 actvity\">";
  3022. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  3023. print ' </tr>' . "\n";
  3024. $i++;
  3025. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3026. } // foreach ($iassign_list as $iassign)
  3027. $num_exerc = $i; // total of exercises
  3028. print "</table>";
  3029. print "<p></p>";
  3030. if ($this->action == 'print')
  3031. print '<table border=1 width="100%">' . "\n";
  3032. else // ./theme/boost/style/moodle.css: .generaltable
  3033. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3034. $context = context_course::instance($this->course->id);
  3035. if ($num_exerc > 1) {
  3036. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3037. $params_temp = array('shortname' => 'student');
  3038. $role = $DB->get_record_sql(
  3039. "SELECT s.id, s.shortname FROM {role} s " .
  3040. " WHERE s.shortname = :shortname", $params_temp);
  3041. // $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");
  3042. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3043. $students = $DB->get_records_sql(
  3044. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3045. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3046. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3047. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3048. $width = 90/$num_exerc;
  3049. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3050. $sum_iassign_correct[$j] = 0;
  3051. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3052. }
  3053. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3054. $sum_iassign = $j - 1;
  3055. print '</tr>' . "\n";
  3056. $total = 0;
  3057. $sum_student = 0;
  3058. $comment = iassign_icons::insert('comment_read');
  3059. $sum_comment = 0;
  3060. $sum_correct_iassign = array();
  3061. $sum_correct_student = array();
  3062. $USER->matrix_iassign = array();
  3063. if ($students) {
  3064. $w = 0;
  3065. foreach ($students as $tmp) { // count students
  3066. $users_array[$w] = $tmp;
  3067. $w++;
  3068. }
  3069. for ($x=0; $x<$w; $x++) { // for all students
  3070. print '<tr>' . "\n";
  3071. $sum_student++;
  3072. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3073. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3074. $total_student = 0;
  3075. $tentativas = 0;
  3076. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3077. $sum_comment = $sum_verify_message = 0;
  3078. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3079. if ($student_submissions) {
  3080. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3081. $tentativas = $student_submissions->experiment;
  3082. // Get student comments
  3083. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3084. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3085. $student_submissions_comment = $DB->get_record_sql(
  3086. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3087. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3088. if ($student_submissions_comment) // student has comment
  3089. foreach ($student_submissions_comment as $tmp)
  3090. $sum_comment = $tmp;
  3091. // informations to previous activities
  3092. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3093. else $iassign_previous = $num[$j - 1]->iassignid;
  3094. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3095. else $user_previous = $users_array[$x - 1]->userid;
  3096. // next
  3097. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3098. else $iassign_next = "-1";
  3099. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3100. else $user_next = "-1";
  3101. $position = "&row= $x&column=$j";
  3102. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3103. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3104. $url .= $position;
  3105. // receiver=1 - message to teacher
  3106. // receiver=2 - message to student
  3107. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3108. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3109. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3110. $verify_message = $DB->get_record_sql(
  3111. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3112. "WHERE iassign_submissionid = :iassign_submissionid " .
  3113. " AND return_status= :return_status " .
  3114. " AND receiver= :receiver", $params_temp);
  3115. if ($verify_message)
  3116. foreach ($verify_message as $tmp)
  3117. $sum_verify_message = $tmp;
  3118. if ($sum_verify_message > 0)
  3119. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3120. else
  3121. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3122. if ($student_submissions->status == 3) {
  3123. $sum_iassign_correct[$j]++;
  3124. $total_student++;
  3125. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3126. }
  3127. elseif ($student_submissions->status == 2) {
  3128. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3129. }
  3130. elseif ($student_submissions->status == 1) {
  3131. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3132. }
  3133. elseif ($student_submissions->status == 0) {
  3134. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3135. }
  3136. if ($this->action != 'print') {
  3137. if ($tentativas > 0)
  3138. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3139. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3140. . $feedback
  3141. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3142. . $tentativas
  3143. . '</span> </button>'
  3144. . '</a>' . "\n";
  3145. else
  3146. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3147. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3148. . $feedback
  3149. .'</button>'
  3150. . '</a>' . "\n";
  3151. if ($sum_comment > 0 && $sum_verify_message > 0)
  3152. print '<a href="' . $url . '"> '
  3153. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3154. . $comment
  3155. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3156. . $sum_verify_message . '/' . $sum_comment
  3157. . '</span> </button>'
  3158. . '</a>';
  3159. else if ($sum_comment > 0)
  3160. print '<a href="' . $url . '"> '
  3161. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3162. . $comment
  3163. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3164. . $sum_comment
  3165. . '</span> </button>'
  3166. . '</a>';
  3167. print '</td>' . "\n";
  3168. }
  3169. if ($this->action == 'print')
  3170. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3171. } // if ($student_submissions)
  3172. else { // if ($student_submissions)
  3173. // Student does not have any submission
  3174. // informations to browse previous activities
  3175. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3176. else $iassign_previous = $num[$j - 1]->iassignid;
  3177. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3178. else $user_previous = $users_array[$x - 1]->userid;
  3179. // next
  3180. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3181. else $iassign_next = "-1";
  3182. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3183. else $user_next = "-1";
  3184. $position = "&row= $x&column=$j";
  3185. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3186. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3187. $url .= $position;
  3188. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3189. if ($this->action == 'print')
  3190. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3191. else {
  3192. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3193. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3194. . $feedback
  3195. .'</button>'
  3196. . '</a>' . "\n";
  3197. // print '<td> &nbsp;</td>';
  3198. if ($sum_comment > 0)
  3199. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3200. // else print '<td> &nbsp;</td>';
  3201. print '</td>';
  3202. }
  3203. } // else if ($student_submissions)
  3204. $USER->matrix_iassign[$x][$j] = new stdClass();
  3205. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3206. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3207. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3208. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3209. if ($student_submissions)
  3210. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3211. else
  3212. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3213. //print '</td>' . "\n";
  3214. } // for ($j=1; $j<$num_exerc; $j++)
  3215. $total = $total + $total_student;
  3216. $porcentagem = ($total_student / ($j - 1)) * 100;
  3217. if ($tentativas != 0 && $tentativas != null) {
  3218. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3219. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3220. }
  3221. else {
  3222. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3223. }
  3224. print '</tr>' . "\n";
  3225. $sum_correct_student[$sum_student] = new stdClass();
  3226. $sum_correct_student[$sum_student]->name = $name;
  3227. $sum_correct_student[$sum_student]->sum = $total_student;
  3228. } // for ($x = 0; $x < $w; $x++)
  3229. for ($i = 1; $i < $j; $i++) {
  3230. if (is_null($sum_iassign_correct[$i]))
  3231. $sum_iassign_correct[$i] = 0;
  3232. $sum_correct_iassign[$i] = new stdClass();
  3233. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3234. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3235. }
  3236. // print '</tr></table>' . "\n";
  3237. }
  3238. } // if ($i>1)
  3239. else {
  3240. print_string('no_activity', 'iassign');
  3241. }
  3242. print "</table>\n";
  3243. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3244. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3245. if ($this->action != 'print')
  3246. print $OUTPUT->footer();
  3247. die();
  3248. } // function report()
  3249. /// Display graphics of performance
  3250. function stats () {
  3251. global $USER, $CFG, $DB, $OUTPUT;
  3252. $id = $this->cm->id;
  3253. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3254. if ($this->action != 'printstats')
  3255. $title = get_string('graphic', 'iassign');
  3256. $num = array();
  3257. $sum_correct_iassign = array();
  3258. $sum_correct_student = array();
  3259. $sum_student = 0;
  3260. $i = 1;
  3261. foreach ($iassign_list as $iassign) {
  3262. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3263. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3264. $sum_iassign_correct[$i] = 0;
  3265. $num[$i] = new stdClass();
  3266. $num[$i]->name = $iassign->name;
  3267. $num[$i]->id = $i;
  3268. $num[$i]->iassignid = $iassign->id;
  3269. $i++;
  3270. } // if ($iassign->type_iassign == 3)
  3271. } // foreach ($iassign_list as $iassign)
  3272. $sum_iassign = $i - 1;
  3273. $context = context_course::instance($this->course->id);
  3274. if ($i > 1) {
  3275. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3276. $params_temp = array('shortname' => 'student');
  3277. $role = $DB->get_record_sql(
  3278. "SELECT s.id, s.shortname FROM {role} s " .
  3279. " WHERE s.shortname = :shortname", $params_temp);
  3280. // $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");
  3281. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3282. $students = $DB->get_records_sql(
  3283. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3284. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3285. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3286. $total = 0;
  3287. $sum_student = 0;
  3288. $j = 0;
  3289. $sum_correct_iassign = array();
  3290. $sum_correct_student = array();
  3291. $sum_experiment = array();
  3292. if ($students) {
  3293. foreach ($students as $users) {
  3294. $sum_student++;
  3295. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3296. // rows
  3297. $total_student = 0;
  3298. for ($j = 1; $j < $i; $j++) {
  3299. $total_experiment = 0;
  3300. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3301. if ($student_submissions) {
  3302. if ($student_submissions->status == 3) {
  3303. $sum_iassign_correct[$j]++;
  3304. $total_student++;
  3305. } // if ($student_submissions->status == 3)
  3306. $total_experiment += $student_submissions->experiment;
  3307. }
  3308. $sum_experiment[$j] = $total_experiment;
  3309. } // for ($j=1; $j<$i; $j++)
  3310. $total = $total + $total_student;
  3311. $sum_correct_student[$sum_student] = new stdClass();
  3312. $sum_correct_student[$sum_student]->name = $name;
  3313. $sum_correct_student[$sum_student]->sum = $total_student;
  3314. } // foreach ($students as $users)
  3315. }
  3316. for ($i = 1; $i < $j; $i++) {
  3317. if (is_null($sum_iassign_correct[$i]))
  3318. $sum_iassign_correct[$i] = 0;
  3319. $sum_correct_iassign[$i] = new stdClass();
  3320. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3321. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3322. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3323. } // for ($i = 1; $i < $j; $i++)
  3324. } // if ($i > 1)
  3325. print $OUTPUT->header();
  3326. $this->print_main_menu();
  3327. if ($this->action != 'printstats') {
  3328. $title = get_string('graphic', 'iassign');
  3329. $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>";
  3330. $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>";
  3331. print '<table width=100%><tr>';
  3332. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3333. print '<td width=15% align="right">' . $link_report . '</td>';
  3334. print '</td></tr></table>' . "\n";
  3335. print "<br><br>";
  3336. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3337. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3338. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3339. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3340. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3341. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3342. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3343. print '</tr>' . "\n";
  3344. $sum_correct = 0;
  3345. if ($sum_correct_iassign) {
  3346. foreach ($sum_correct_iassign as $iassign) {
  3347. if (is_null($iassign->experiment))
  3348. $iassign->experiment = 0;
  3349. $bar = "";
  3350. $sum = $iassign->sum;
  3351. $percent = ($sum / $sum_student) * 100;
  3352. $text = number_format($percent, 1) . '%';
  3353. $sum_correct += $sum;
  3354. if ($sum > 0) {
  3355. for ($i = 1; $i < $percent * 2; $i++)
  3356. $bar .= iassign_icons::insert('hbar_blue');
  3357. $bar .= iassign_icons::insert('hbar_blue_r');
  3358. } // if ($sum > 0)
  3359. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3360. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3361. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3362. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3363. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3364. print '</tr>' . "\n";
  3365. } // foreach ($sum_correct_iassign as $iassign)
  3366. }
  3367. print "</table>";
  3368. print "<br><br>";
  3369. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3370. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3371. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3372. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3373. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3374. print '</tr>' . "\n";
  3375. $sum_correct = 0;
  3376. foreach ($sum_correct_student as $student) {
  3377. $bar = "";
  3378. $sum = $student->sum;
  3379. $percent = ($sum / $sum_iassign) * 100;
  3380. $text = number_format($percent, 1) . '%';
  3381. $sum_correct += $sum;
  3382. if ($sum > 0) {
  3383. for ($i = 1; $i < $percent * 2; $i++)
  3384. $bar .= iassign_icons::insert('hbar_blue');
  3385. $bar .= iassign_icons::insert('hbar_blue_r');
  3386. } // if ($sum > 0)
  3387. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3388. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3389. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3390. print '</tr>' . "\n";
  3391. } // foreach ($sum_correct_student as $student)
  3392. print "</table>\n";
  3393. print "<br><br>\n";
  3394. $var = 0;
  3395. $cv = 0;
  3396. $dv = 0;
  3397. $avg = 0;
  3398. if ($sum_correct_student) {
  3399. $avg = $sum_correct / $sum_student;
  3400. if ($avg > 0) {
  3401. foreach ($sum_correct_student as $student)
  3402. $var += pow($student->sum - $avg, 2);
  3403. $var = $var / $sum_student;
  3404. $dv = sqrt($var);
  3405. $cv = ($dv / $avg) * 100;
  3406. }
  3407. }
  3408. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3409. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3410. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3411. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3412. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3413. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3414. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3415. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3416. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3417. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3418. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3419. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3420. print "</table>\n";
  3421. print $OUTPUT->footer();
  3422. } else {
  3423. print "<STYLE TYPE='text/css'>
  3424. <!--
  3425. .boldtable {
  3426. font-family:sans-serif;
  3427. font-size:10pt;
  3428. }
  3429. -->
  3430. </STYLE>\n";
  3431. print '<table border=1 width=100%>' . "\n";
  3432. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3433. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3434. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3435. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3436. print '</tr>' . "\n";
  3437. $sum_correct = 0;
  3438. foreach ($sum_correct_iassign as $iassign) {
  3439. $bar = "";
  3440. $sum = $iassign->sum;
  3441. $percent = ($sum / $sum_student) * 100;
  3442. $text = number_format($percent, 1) . '%';
  3443. $sum_correct += $sum;
  3444. if ($sum > 0) {
  3445. for ($i = 1; $i < $percent * 2; $i++)
  3446. $bar .= iassign_icons::insert('hbar_blue');
  3447. $bar .= iassign_icons::insert('hbar_blue_r');
  3448. } // if ($sum > 0)
  3449. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3450. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3451. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3452. print '</tr>' . "\n";
  3453. } // foreach ($sum_correct_iassign as $iassign)
  3454. print "</table>";
  3455. print "<br><br>";
  3456. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3457. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3458. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3459. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3460. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3461. print '</tr>' . "\n";
  3462. $sum_correct = 0;
  3463. foreach ($sum_correct_student as $student) {
  3464. $bar = "";
  3465. $sum = $student->sum;
  3466. $percent = ($sum / $sum_iassign) * 100;
  3467. $text = number_format($percent, 1) . '%';
  3468. $sum_correct += $sum;
  3469. if ($sum > 0) {
  3470. for ($i = 1; $i < $percent * 2; $i++)
  3471. $bar .= iassign_icons::insert('hbar_blue');
  3472. $bar .= iassign_icons::insert('hbar_blue_r');
  3473. } // if ($sum > 0)
  3474. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3475. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3476. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3477. print '</tr>' . "\n";
  3478. } // foreach ($sum_correct_student as $student)
  3479. print "</table>\n";
  3480. print "<br/><br/>\n";
  3481. $var = 0;
  3482. $cv = 0;
  3483. $dv = 0;
  3484. $avg = 0;
  3485. if ($sum_correct_student) {
  3486. $avg = $sum_correct / $sum_student;
  3487. if ($avg > 0) {
  3488. foreach ($sum_correct_student as $student)
  3489. $var += pow($student->sum - $avg, 2);
  3490. $var = $var / $sum_student;
  3491. $dv = sqrt($var);
  3492. $cv = ($dv / $avg) * 100;
  3493. }
  3494. }
  3495. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3496. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3497. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3498. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3499. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3500. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3501. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3502. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3503. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3504. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3505. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3506. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3507. print "</table>\n";
  3508. } // if ($this->action != 'printstats')
  3509. die();
  3510. }
  3511. /// Display graphics of performance for students
  3512. function stats_students () {
  3513. global $USER, $CFG, $DB, $OUTPUT;
  3514. $id = $this->cm->id;
  3515. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3516. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3517. $title = get_string('results', 'iassign');
  3518. $sum_correct = 0;
  3519. $sum_incorrect = 0;
  3520. $sum_post = 0;
  3521. $sum_nopost = 0;
  3522. $sum_iassign = count($iassign_statement_list);
  3523. $bar_nopost = "";
  3524. $bar_correct = "";
  3525. $bar_incorrect = "";
  3526. $bar_post = "";
  3527. $text_nopost = "";
  3528. $text_correct = "";
  3529. $text_incorrect = "";
  3530. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3531. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3532. if ($iassign_submission) {
  3533. if ($iassign_submission->status == 3)
  3534. $sum_correct++;
  3535. elseif ($iassign_submission->status == 2)
  3536. $sum_incorrect++;
  3537. elseif ($iassign_submission->status == 1)
  3538. $sum_post++;
  3539. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3540. $sum_nopost++;
  3541. } // if ($iassign_submission)
  3542. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3543. if ($sum_iassign > 0) {
  3544. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3545. $text_correct = number_format($percent_correct, 1) . '%';
  3546. }
  3547. if ($sum_correct > 0) {
  3548. for ($i = 1; $i < $percent_correct * 2; $i++)
  3549. $bar_correct .= iassign_icons::insert('hbar_green');
  3550. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3551. } // if ($sum_correct > 0)
  3552. if ($sum_iassign > 0) {
  3553. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3554. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3555. }
  3556. if ($sum_incorrect > 0) {
  3557. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3558. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3559. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3560. } // if ($sum_incorrect > 0)
  3561. if ($sum_iassign > 0) {
  3562. $percent_post = ($sum_post / $sum_iassign) * 100;
  3563. $text_post = number_format($percent_post, 1) . '%';
  3564. }
  3565. if ($sum_post > 0) {
  3566. for ($i = 1; $i < $percent_post * 2; $i++)
  3567. $bar_post .= iassign_icons::insert('hbar_blue');
  3568. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3569. } // if ($sum_post > 0)
  3570. if ($sum_iassign > 0) {
  3571. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3572. $text_nopost = number_format($percent_nopost, 1) . '%';
  3573. }
  3574. if ($sum_nopost > 0) {
  3575. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3576. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3577. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3578. } // if ($sum_nopost > 0)
  3579. print $OUTPUT->header();
  3580. $this->print_main_menu();
  3581. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3582. //2021/12 print '<table width=100%><tr>';
  3583. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3584. //2021/12 print '</td></tr></table>' . "\n";
  3585. print "<br/><br/>\n";
  3586. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3587. print '<tr><th colspan=3 class="header c1">' . "\n";
  3588. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3589. // $imagetext = '');
  3590. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3591. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3592. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3593. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3594. print '</tr>' . "\n";
  3595. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3596. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3597. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3598. print '</tr>' . "\n";
  3599. if ($sum_post) {
  3600. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3601. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3602. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3603. print '</tr>' . "\n";
  3604. } // if ($sum_post)
  3605. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3606. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3607. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3608. print '</tr>' . "\n";
  3609. print "</table>";
  3610. print "<br><br>";
  3611. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3612. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3613. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3614. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3615. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3616. $sum_grade = 0;
  3617. $sum_grade_student = 0;
  3618. $avg = 0;
  3619. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3620. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3621. if (!$iassign_submission) {
  3622. $iassign_submission = new stdClass();
  3623. $iassign_submission->grade = 0;
  3624. }
  3625. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3626. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3627. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3628. print '</tr>' . "\n";
  3629. $sum_grade += $iassign_statement_activity_item->grade;
  3630. $sum_grade_student += $iassign_submission->grade;
  3631. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3632. if ($sum_grade > 0)
  3633. $avg = $sum_grade_student / $sum_grade * 100;
  3634. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3635. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3636. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3637. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3638. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3639. print "</table>";
  3640. print $OUTPUT->footer();
  3641. die();
  3642. } // function stats_students()
  3643. function get_total_notifications () {
  3644. global $DB, $USER, $COURSE;
  3645. $total_messages = 0;
  3646. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3647. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3648. $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 "
  3649. . " 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);
  3650. }
  3651. else {
  3652. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3653. $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 "
  3654. . " 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);
  3655. }
  3656. return $total_messages->total;
  3657. }
  3658. function get_iassign_statement_messages () {
  3659. global $DB, $USER, $COURSE;
  3660. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3661. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3662. $totais = array();
  3663. $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 "
  3664. . " 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);
  3665. foreach($messages as $item) {
  3666. if (isset($totais[$item->subid])) {
  3667. $totais[$item->subid]->total++;
  3668. }
  3669. else {
  3670. $totais[$item->subid] = new stdclass();
  3671. $item->total = 1;
  3672. $totais[$item->subid] = $item;
  3673. }
  3674. }
  3675. return $totais;
  3676. }
  3677. else {
  3678. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3679. $totais = array();
  3680. $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 "
  3681. . " 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);
  3682. foreach($messages as $item) {
  3683. if (isset($totais[$item->subid])) {
  3684. $totais[$item->subid]->total++;
  3685. }
  3686. else {
  3687. $totais[$item->subid] = new stdclass();
  3688. $item->total = 1;
  3689. $totais[$item->subid] = $item;
  3690. }
  3691. }
  3692. return $totais;
  3693. }
  3694. }
  3695. function view_notifications_teachers () {
  3696. global $OUTPUT, $USER, $DB;
  3697. $messages = $this->get_iassign_statement_messages();
  3698. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3699. // 1º. listar as mensagens recebidas no bloco atual:
  3700. $actual_block = $this->iassign->id;
  3701. $id = $this->cm->id;
  3702. $total_include = 0;
  3703. $activities_actual_block = array();
  3704. if ($messages)
  3705. foreach ($messages as $item)
  3706. if ($item->iasid == $actual_block)
  3707. if (!in_array($item->stid, $activities_actual_block))
  3708. array_push($activities_actual_block, $item->stid);
  3709. if ($activities_actual_block)
  3710. foreach ($activities_actual_block as $activity_id) {
  3711. $printed = false;
  3712. foreach ($messages as $item) {
  3713. if ($item->stid == $activity_id) {
  3714. if (!$printed) {
  3715. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3716. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3717. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3718. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3719. $printed = true;
  3720. }
  3721. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3722. $user = $DB->get_record('user', array('id' => $item->user));
  3723. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3724. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3725. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3726. '<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>'
  3727. .'</tr>';
  3728. $total_include++;
  3729. }
  3730. }
  3731. print '</td></tr></table>';
  3732. }
  3733. print '</table>';
  3734. if (count($activities_actual_block) == 0) {
  3735. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3736. print '<hr class="my-4">';
  3737. }
  3738. if ($messages && $total_include == count($messages)) {
  3739. print $OUTPUT->footer();
  3740. return;
  3741. }
  3742. 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>';
  3743. $iassign_ids = array();
  3744. if ($messages)
  3745. foreach ($messages as $item)
  3746. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3747. array_push($iassign_ids, $item->iasid);
  3748. foreach ($iassign_ids as $id_iassign) {
  3749. $printed = false;
  3750. $activities_in_block = array();
  3751. foreach ($messages as $subitem)
  3752. if ($subitem->iasid == $id_iassign)
  3753. if (!in_array($item->stid, $activities_in_block))
  3754. array_push($activities_in_block, $item->stid);
  3755. foreach ($messages as $item) {
  3756. if ($item->iasid == $id_iassign) {
  3757. if (!$printed) {
  3758. $printed = true;
  3759. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3760. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3761. }
  3762. foreach ($activities_in_block as $id_activity) {
  3763. $print = false;
  3764. foreach ($messages as $subitem) {
  3765. if ($subitem->stid == $id_activity) {
  3766. if (!$print) {
  3767. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3768. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3769. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3770. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3771. $print = true;
  3772. }
  3773. foreach ($messages as $comment_student) {
  3774. if ($comment_student->stid == $id_activity) {
  3775. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3776. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3777. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3778. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3779. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3780. '<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>'
  3781. .'</tr>';
  3782. }
  3783. }
  3784. break;
  3785. }
  3786. }
  3787. }
  3788. print '</table></td></tr></table>';
  3789. break;
  3790. }
  3791. }
  3792. }
  3793. print $OUTPUT->footer();
  3794. }
  3795. function view_notifications () {
  3796. global $OUTPUT, $USER;
  3797. print $OUTPUT->header();
  3798. $this->print_main_menu();
  3799. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3800. if ($this->get_total_notifications() == 0) {
  3801. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3802. print '<hr class="my-4">';
  3803. print $OUTPUT->footer();
  3804. return;
  3805. }
  3806. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3807. $this->view_notifications_teachers();
  3808. return;
  3809. }
  3810. $messages = $this->get_iassign_statement_messages();
  3811. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3812. // 1º. listar as mensagens recebidas no bloco atual:
  3813. $actual_block = $this->iassign->id;
  3814. $id = $this->cm->id;
  3815. $total_include = 0;
  3816. if ($messages)
  3817. foreach ($messages as $item) {
  3818. if ($item->iasid == $actual_block) {
  3819. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3820. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3821. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3822. 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>';
  3823. $total_include++;
  3824. }
  3825. }
  3826. print '</table>';
  3827. if ($total_include == 0) {
  3828. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3829. print '<hr class="my-4">';
  3830. }
  3831. if ($messages && $total_include == count($messages)) {
  3832. print $OUTPUT->footer();
  3833. return;
  3834. }
  3835. 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>';
  3836. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3837. $iassign_ids = array();
  3838. if ($messages)
  3839. foreach ($messages as $item)
  3840. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3841. array_push($iassign_ids, $item->iasid);
  3842. foreach ($iassign_ids as $id_iassign) {
  3843. $printed = false;
  3844. foreach ($messages as $item) {
  3845. if ($item->iasid == $id_iassign) {
  3846. if (!$printed) {
  3847. $printed = true;
  3848. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3849. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3850. }
  3851. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3852. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3853. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3854. 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>';
  3855. }
  3856. }
  3857. print '</table>';
  3858. }
  3859. print $OUTPUT->footer();
  3860. }
  3861. function print_main_menu () {
  3862. global $USER;
  3863. $id = $this->cm->id;
  3864. $actual_action = optional_param('action', '', PARAM_TEXT);
  3865. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3866. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3867. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3868. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3869. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3870. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3871. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3872. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3873. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3874. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  3875. print '<div class="btn-group" role="group" aria-label="">';
  3876. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  3877. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  3878. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3879. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3880. // Has capability to see "report": teacher or up
  3881. 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>';
  3882. print '<div class="btn-group"><div class="btn-group">
  3883. <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">
  3884. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3885. <div class="dropdown-menu">
  3886. <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>
  3887. <div class="dropdown-divider"></div>
  3888. <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>
  3889. <div class="dropdown-divider"></div>
  3890. <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>
  3891. </div>
  3892. </div>
  3893. '; // "
  3894. 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>';
  3895. 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>';
  3896. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3897. $notifications = $this->get_total_notifications();
  3898. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  3899. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  3900. if ($notifications > 0)
  3901. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3902. print '</a></div><div class="btn-group">';
  3903. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3904. 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";
  3905. print '
  3906. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3907. </button>
  3908. <div class="dropdown-menu">
  3909. <a class="dropdown-item" href="' . $url_import_activity . '">' . get_string('import_activity', 'iassign') . '</a>
  3910. </div>'; // "
  3911. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3912. print '</div></div>' . "\n";
  3913. }
  3914. /// Display page of iAssign's block of activities
  3915. function view_iassigns () {
  3916. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3917. $id = $this->cm->id;
  3918. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3919. $notice = optional_param('notice', '', PARAM_TEXT);
  3920. if (strpos($notice, 'error'))
  3921. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3922. else if ($notice != '')
  3923. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3924. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  3925. print $OUTPUT->box_start();
  3926. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3927. print '<div class="border float-right">' . "\n";
  3928. if ($iassign_list) {
  3929. // $USER->iassignEdit == 0 view 'Turn editing off'
  3930. // $USER->iassignEdit == 1 view 'Turn editing on'
  3931. if (!isset($USER->iassignEdit))
  3932. $USER->iassignEdit = 0;
  3933. if ($USER->iassignEdit == 0) {
  3934. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3935. $botton = 1;
  3936. }
  3937. elseif ($USER->iassignEdit == 1) {
  3938. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3939. $botton = 0;
  3940. }
  3941. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3942. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3943. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  3944. print "</form>\n";
  3945. } // if ($iassign_list)
  3946. print "</div>\n";
  3947. }
  3948. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3949. // $this->view_legend_icons();
  3950. print $OUTPUT->box_end();
  3951. $iassign_array_exercise = array();
  3952. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  3953. $iassign_array_test = array();
  3954. $i_test = 0; // count total number of activities of type 'test' inside the block
  3955. $iassign_array_example = array();
  3956. $i_example = 0; // count total number of activities of type 'example' inside the block
  3957. $iassign_array_general = array();
  3958. $i_general = 0;
  3959. if ($iassign_list) {
  3960. if ($this->iassign->activity_group == 0) {
  3961. foreach ($iassign_list as $iassign) {
  3962. $iassign_array_general[$i_general] = $iassign;
  3963. $i_general++;
  3964. }
  3965. } // if ($this->iassign->activity_group == 0)
  3966. else {
  3967. foreach ($iassign_list as $iassign) {
  3968. if ($iassign->type_iassign == 3) {
  3969. $iassign_array_exercise[$i_exercise] = $iassign;
  3970. $i_exercise++;
  3971. } // if ($iassign->type_iassign == 3)
  3972. if ($iassign->type_iassign == 2) {
  3973. $iassign_array_test[$i_test] = $iassign;
  3974. $i_test++;
  3975. } // if ($iassign->type_iassign == 2)
  3976. if ($iassign->type_iassign == 1) {
  3977. $iassign_array_example[$i_example] = $iassign;
  3978. $i_example++;
  3979. } // if ($iassign->type_iassign == 1)
  3980. }
  3981. }
  3982. if ($iassign_array_exercise) {
  3983. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3984. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3985. }
  3986. if ($iassign_array_test) {
  3987. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3988. $this->show_iassign($title, $iassign_array_test, $i_test);
  3989. }
  3990. if ($iassign_array_example) {
  3991. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3992. $this->show_iassign($title, $iassign_array_example, $i_example);
  3993. }
  3994. if ($iassign_array_general) {
  3995. $title = "";
  3996. $this->show_iassign($title, $iassign_array_general, $i_general);
  3997. }
  3998. } else { // if ($iassign_list)
  3999. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  4000. }
  4001. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  4002. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4003. print $OUTPUT->box_start();
  4004. print '<table width=100% border=0><tr>' . "\n";
  4005. print '<td width=10% align="left">' . "\n";
  4006. print $link_report;
  4007. print '</td>' . "\n";
  4008. print '</tr></table>' . "\n";
  4009. print $OUTPUT->box_end();
  4010. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4011. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4012. print $OUTPUT->box_start();
  4013. print '<table width=100% border=0><tr>' . "\n";
  4014. print '<td align="left">' . "\n";
  4015. print $link_add;
  4016. print '</td>' . "\n";
  4017. print '</tr></table>' . "\n";
  4018. print $OUTPUT->box_end();
  4019. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4020. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  4021. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4022. // $this->view_legend_icons();
  4023. } // function view_iassigns()
  4024. /// Display all iAssigns: the list of activities inside the iAssign block
  4025. // HTTP: ./mod/iassign/view.php?id= <$id>
  4026. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4027. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4028. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4029. print $OUTPUT->box_start();
  4030. print " <script type='text/javascript'>
  4031. //<![CDATA[
  4032. function validate_move () {
  4033. var radios = document.getElementsByName('iassign_destiny');
  4034. var formValid = false;
  4035. //alert('aqui validate_move()');
  4036. var i = 0;
  4037. while (!formValid && i < radios.length) {
  4038. if (radios[i].checked) formValid = true;
  4039. i++;
  4040. }
  4041. if (!formValid) {
  4042. document.getElementById('move_dest').classList.add('alert-danger');
  4043. }
  4044. return formValid;
  4045. }
  4046. var modal;
  4047. function load_move(id_ias) {
  4048. document.form_move_activity.iassign_current.value = id_ias;
  4049. modal.style.display = 'block';
  4050. var radios = document.getElementsByName('iassign_destiny');
  4051. var i = 0;
  4052. while (i < radios.length) {
  4053. radios[i].checked = false;
  4054. i++;
  4055. }
  4056. document.getElementById('move_dest').classList.remove('alert-danger');
  4057. }
  4058. function closeModal () {
  4059. modal.style.display = 'none';
  4060. }
  4061. function load_modal_elements () {
  4062. modal = document.getElementById('myModal');
  4063. var span = document.getElementById('close_modal');
  4064. span.onclick = function() {
  4065. modal.style.display = 'none';
  4066. }
  4067. window.onclick = function(event) {
  4068. if (event.target == modal) {
  4069. modal.style.display = 'none';
  4070. }
  4071. }
  4072. }
  4073. window.onload = load_modal_elements;
  4074. //]]>
  4075. </script>\n";
  4076. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4077. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4078. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4079. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4080. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4081. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4082. <input type='hidden' name='iassign_current' value='' />";
  4083. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4084. $section = $course_sections[0];
  4085. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4086. for ($k = 0; $k < count($ids_sections); $k++) {
  4087. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4088. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4089. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4090. if ($c_cm) {
  4091. if ($ccm->instance == $c_cm->instance) {
  4092. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4093. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4094. }
  4095. else {
  4096. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4097. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4098. }
  4099. }
  4100. }
  4101. $radio_buttons .= "</ul>";
  4102. }
  4103. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4104. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4105. </form>
  4106. </div></div> </div></div>\n";
  4107. print " <style>.modal {
  4108. display: none;
  4109. position: fixed;
  4110. z-index: 1;
  4111. left: 0;
  4112. top: 0;
  4113. width: 100%;
  4114. height: 100%;
  4115. overflow: scroll;
  4116. background-color: rgb(0,0,0);
  4117. background-color: rgba(0,0,0,0.4);
  4118. }
  4119. .modal-content {
  4120. background-color: #fefefe;
  4121. margin: 15% auto;
  4122. padding: 10px 10px;
  4123. border: 1px solid #888;
  4124. width: 50%;
  4125. }
  4126. #close_modal {
  4127. color: #aaa;
  4128. float: right;
  4129. font-size: 28px;
  4130. font-weight: bold;
  4131. margin-top: -15px;
  4132. margin-right: -3px;
  4133. }
  4134. #close_modal:hover,
  4135. #close_modal:focus {
  4136. color: black;
  4137. text-decoration: none;
  4138. cursor: pointer;
  4139. }
  4140. #modal_title {
  4141. min-height: 3rem;
  4142. color: initial;
  4143. background: initial;
  4144. font-size: 1.5rem;
  4145. line-height: 1.5;
  4146. padding: 15px;
  4147. border-bottom: 1px solid #e5e5e5;
  4148. }
  4149. .input_move {
  4150. width: 90%;
  4151. padding: 2px;
  4152. }
  4153. .input_move:hover {
  4154. background: #eff0ef;
  4155. }
  4156. </style>";
  4157. $action_links = "";
  4158. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4159. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4160. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4161. for ($j=0; $j<$total_of_activities; $j++) {
  4162. $iassign_current = $iassign_array[$j]->id;
  4163. // receiver=1 - message to teacher
  4164. // receiver=2 - message to student
  4165. $sum_comment = 0;
  4166. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4167. foreach ($iassign_submissions as $iassign_submission) {
  4168. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4169. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4170. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4171. if ($verify_message)
  4172. foreach ($verify_message as $tmp)
  4173. $sum_comment += $tmp;
  4174. } // foreach ($iassign_submissions as $iassign_submission)
  4175. if ($sum_comment == 0)
  4176. $comment_unread = "";
  4177. else {
  4178. $comment_unread_message = get_string('comment_unread', 'iassign');
  4179. if ($sum_comment == 1)
  4180. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4181. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4182. ' <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 .
  4183. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4184. }
  4185. if ($j == $total_of_activities - 1)
  4186. $iassign_down = $iassign_array[$j]->id;
  4187. else
  4188. $iassign_down = $iassign_array[$j + 1]->id;
  4189. if ($j > 0)
  4190. $iassign_up = $iassign_array[$j - 1]->id;
  4191. else
  4192. $iassign_up = $iassign_array[$j]->id;
  4193. if ($iassign_array[$j]->visible == 0)
  4194. $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";
  4195. else
  4196. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4197. $links .= $comment_unread;
  4198. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4199. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4200. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4201. $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";
  4202. if ($j==0) // first activity
  4203. $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";
  4204. else
  4205. $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";
  4206. $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";
  4207. $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";
  4208. $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";
  4209. $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";
  4210. $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";
  4211. $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";
  4212. if (count($iassign_array) > 1) {
  4213. if ($j == 0)
  4214. $action_links .= $link_down;
  4215. elseif ($j == $total_of_activities - 1)
  4216. $action_links .= $link_up;
  4217. else
  4218. $action_links .= $link_up . $link_down;
  4219. } // if (count($iassign_array) > 1)
  4220. $action_links .= $link_edit . $link_delete;
  4221. if ($iassign_array[$j]->visible == 0)
  4222. $action_links .= $link_visible_show;
  4223. else
  4224. $action_links .= $link_visible_hide;
  4225. $action_links .= $link_duplicate_activity . $link_move_activity;
  4226. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4227. $action_links .= "</ul></nav>\n";
  4228. 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";
  4229. } // for ($j=0; $j<$total_of_activities; $j++)
  4230. //D echo "locallib.php: show_iassign():<br/>";
  4231. //EXTRA: This for is to correct error in ordem inside the block, to detect (and fix it) 'iassign_statement.position' errors
  4232. $vector_final_order = array(); // get the final order to be used to correct existent one
  4233. for ($j=0; $j<$total_of_activities; $j++) { // List all iAssign activity inside this block
  4234. //D echo $j . ": id=" . $iassign_array[$j]->id . ", position=" . $iassign_array[$j]->position . "<br/>";
  4235. if ($iassign_array[$j]->position!=($j+1)) {
  4236. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $j+1, $j+1);
  4237. }
  4238. }
  4239. print "</tbody></table>\n";
  4240. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4241. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4242. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4243. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4244. for ($j=0; $j<$total_of_activities; $j++) {
  4245. $icon_status = "";
  4246. $icon_comment = "";
  4247. if ($iassign_array[$j]->visible == 1) {
  4248. $iassign_current = $iassign_array[$j]->id;
  4249. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4250. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4251. $icon_status = "";
  4252. $icon_comment = "";
  4253. if ($iassign_submission) {
  4254. // receiver=1 - message to teacher
  4255. // receiver=2 - message to student
  4256. // $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");
  4257. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4258. $verify_message = $DB->get_record_sql(
  4259. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4260. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4261. if ($verify_message)
  4262. foreach ($verify_message as $tmp)
  4263. $sum_comment = $tmp;
  4264. if ($sum_comment > 0) {
  4265. $comment_unread_message = get_string('comment_unread', 'iassign');
  4266. if ($sum_comment == 1)
  4267. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4268. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4269. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4270. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4271. }
  4272. // $icon_comment = iassign_icons::insert('comment_unread');
  4273. if ($iassign_array[$j]->type_iassign == 3) {
  4274. if ($iassign_array[$j]->show_answer == 1) {
  4275. if ($iassign_submission->status == 3)
  4276. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign') . '"></i>' . "\n";
  4277. elseif ($iassign_submission->status == 2)
  4278. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign') . '"></i>' . "\n";
  4279. elseif ($iassign_submission->status == 1)
  4280. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4281. //2021/12 $icon_status = iassign_icons::insert('post');
  4282. elseif ($iassign_submission->status == 0)
  4283. $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";
  4284. } // if ($iassign_array[$j]->show_answer==1)
  4285. else {
  4286. if ($iassign_submission->status == 0) {
  4287. //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";
  4288. $icon_status = iassign_icons::insert('not_post');
  4289. }
  4290. else {
  4291. //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";
  4292. $icon_status = iassign_icons::insert('post');
  4293. }
  4294. }
  4295. } // if ($iassign_array[$j]->type_iassign == 3)
  4296. } // if ($iassign_submission)
  4297. elseif ($iassign_array[$j]->type_iassign == 3) {
  4298. $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";
  4299. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4300. } // if ($iassign_array[$j]->type_iassign == 3)
  4301. 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;">'
  4302. . $links . '</td><td>' . $icon_comment . '</td></tr>' . "\n";
  4303. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4304. } // if ($iassign_array[$j]->visible == 1)
  4305. } // for ($j=0; $j<$total_of_activities; $j++)
  4306. print "</table>\n";
  4307. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4308. else if (isguestuser()) {
  4309. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4310. print '<table width=100% ><tr>' . "\n";
  4311. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4312. print '</tr></table>' . "\n";
  4313. for ($j=0; $j<$total_of_activities; $j++) {
  4314. $icon_status = "";
  4315. $icon_comment = "";
  4316. if ($iassign_array[$j]->visible == 1) {
  4317. $iassign_current = $iassign_array[$j]->id;
  4318. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4319. print '<p>' . $links . '</p>' . "\n";
  4320. } // if ($iassign_array[$j]->visible == 1)
  4321. }
  4322. }
  4323. print $OUTPUT->box_end();
  4324. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4325. /// Show message of return
  4326. function return_home_course ($message) {
  4327. //D global $DB, $OUTPUT;
  4328. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4329. //D echo $OUTPUT->box_start();
  4330. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4331. //D echo '<tr><td align="left"><strong>' . "\n";
  4332. //D print_string($message, 'iassign');
  4333. //D echo '</strong></td>' . "\n";
  4334. //D echo '<td width=20% align="right">' . "\n";
  4335. //D echo $link_return;
  4336. //D echo '</td></tr></table>' . "\n";
  4337. //D echo $OUTPUT->box_end();
  4338. //D // echo $OUTPUT->footer();
  4339. redirect(new moodle_url($this->return . '&notice=' . $message));
  4340. exit;
  4341. }
  4342. /// Search comment of activity
  4343. function search_comment_submission ($iassign_submissionid) {
  4344. global $USER, $DB, $OUTPUT, $COURSE;
  4345. // $context = context_course::instance($COURSE->id);
  4346. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4347. $colorEdit2 = "#d2e5fc";
  4348. $has_capability = 0;
  4349. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4350. $text = "";
  4351. if ($comments) {
  4352. $even = 1;
  4353. foreach ($comments as $tmp) {
  4354. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4355. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4356. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4357. // $text .= $tmp->comment . "</td></tr>";
  4358. //} else {
  4359. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4360. $avatar = new user_picture($user_data);
  4361. $avatar->courseid = $COURSE->id;
  4362. $avatar->link = true;
  4363. $user_picture = $OUTPUT->render($avatar);
  4364. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4365. if ($even) {
  4366. $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";
  4367. $even = 0;
  4368. } else {
  4369. $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";
  4370. $even = 1;
  4371. }
  4372. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4373. } // foreach ($comments as $tmp)
  4374. }
  4375. return $text;
  4376. }
  4377. /// Update comment of activity
  4378. function update_comment ($iassign_submissionid) {
  4379. global $USER, $DB, $OUTPUT;
  4380. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4381. $receiver = 1; // student message to teacher
  4382. else
  4383. $receiver = 2; // teacher message to student
  4384. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4385. if ($verify_message) {
  4386. foreach ($verify_message as $message) {
  4387. if ($message->receiver == $receiver) {
  4388. $newentry = new stdClass();
  4389. $newentry->id = $message->id;
  4390. $newentry->return_status = 1;
  4391. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4392. print_error('error_update', 'iassign');
  4393. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4394. } // if ($message->receiver == $receiver)
  4395. // Trigger module viewed event.
  4396. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4397. 'objectid' => $this->iassign->id,
  4398. 'context' => $this->context
  4399. ));
  4400. $event->add_record_snapshot('course', $this->course);
  4401. $event->trigger();
  4402. } // foreach ($verify_message as $message)
  4403. }
  4404. }
  4405. /// Record comment of activity
  4406. function write_comment_submission () {
  4407. global $USER, $CFG, $DB;
  4408. $id = $this->cm->id;
  4409. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4410. $row = optional_param('row', 0, PARAM_INT);
  4411. $column = optional_param('column', 0, PARAM_INT);
  4412. $sum_comment = 0;
  4413. $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);
  4414. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4415. $str1 = trim($submission_comment);
  4416. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4417. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4418. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4419. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4420. $receiver = 1; // student message to teacher
  4421. $this->action = 'view';
  4422. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4423. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4424. } else {
  4425. $receiver = 2; // teacher message to student
  4426. $this->action = 'viewsubmission';
  4427. //D $tousers = array(); //MOOC 2016
  4428. //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
  4429. }
  4430. //MOOC 2016: foi p/ 15 linhas acima:
  4431. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4432. // verificar se existe uma submissão para o exercício e aluno informados
  4433. if (!$iassign_submission) {
  4434. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4435. }
  4436. if (!$iassign_submission) {
  4437. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4438. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4439. $this->iassign_submission_current = $id_submission;
  4440. }
  4441. else {
  4442. $id_submission = $iassign_submission->id;
  4443. } // if (!$iassign_submission)
  4444. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4445. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4446. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4447. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4448. $comments = $DB->get_record_sql(
  4449. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4450. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4451. if ($comments)
  4452. foreach ($comments as $tmp)
  4453. $sum_comment = $tmp;
  4454. if ($sum_comment == 0) {
  4455. $newentry = new stdClass();
  4456. $newentry->iassign_submissionid = $id_submission;
  4457. $newentry->comment_authorid = $USER->id;
  4458. $newentry->timecreated = time();
  4459. $newentry->comment = $submission_comment;
  4460. $newentry->receiver = $receiver;
  4461. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4462. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4463. // Trigger module viewed event
  4464. $event = \mod_iassign\event\submission_comment_created::create(array(
  4465. 'objectid' => $this->iassign->id,
  4466. 'context' => $this->context
  4467. ));
  4468. $event->add_record_snapshot('course', $this->course);
  4469. $event->trigger();
  4470. }
  4471. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4472. // if ($this->action=='viewsubmission') {
  4473. // echo $OUTPUT->header();
  4474. // $this->return_last('confirm_add_comment', $link_return);
  4475. // die;
  4476. // }
  4477. return true;
  4478. } // function write_comment_submission()
  4479. /// Writes a new submission
  4480. // The first student answer is under 'function get_answer()'
  4481. function new_submission ($iassignid, $id_user, $receiver) {
  4482. global $USER, $DB, $OUTPUT;
  4483. $newentry = new stdClass();
  4484. $newentry->iassign_statementid = $iassignid;
  4485. $newentry->userid = $id_user;
  4486. $newentry->timecreated = time();
  4487. $newentry->timemodified = time();
  4488. $newentry->answer = 0; // student only submit message
  4489. if ($receiver == 2) // teacher message to student (write id teacher)
  4490. $newentry->teacher = $USER->id;
  4491. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4492. return_home_course('error_insert_submissions');
  4493. else {
  4494. // Trigger module view event
  4495. $event = \mod_iassign\event\submission_created::create(array(
  4496. 'objectid' => $this->iassign->id,
  4497. 'context' => $this->context
  4498. ));
  4499. $event->add_record_snapshot('course', $this->course);
  4500. $event->trigger();
  4501. }
  4502. return $newentry->id;
  4503. }
  4504. /// Return to a specific address of page
  4505. function return_last ($message, $link_return) {
  4506. global $DB, $OUTPUT;
  4507. print $OUTPUT->box_start();
  4508. print '<table width=100% border=0 valign="top">' . "\n";
  4509. print '<tr><td align="left"><strong>' . "\n";
  4510. print_string($message, 'iassign');
  4511. print '</strong></td>' . "\n";
  4512. print '<td width=20% align="right">' . "\n";
  4513. print $link_return;
  4514. print '</td></tr></table>' . "\n";
  4515. print $OUTPUT->box_end();
  4516. print $OUTPUT->footer();
  4517. die();
  4518. } // function return_last($message, $link_return)
  4519. } // class iassign
  4520. /// Class for manage activities
  4521. class activity {
  4522. var $activity;
  4523. /// Constructor of class.
  4524. // @param int $id Id of activity
  4525. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4526. //D public function activity($id) { self::__construct($id); }
  4527. function __construct ($id) {
  4528. global $DB;
  4529. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4530. if (empty($this->activity))
  4531. $this->activity = null;
  4532. }
  4533. /// Get an activity
  4534. // @return NULL
  4535. function get_activity () {
  4536. if ($this->activity != null)
  4537. return $this->activity;
  4538. else
  4539. return null;
  4540. }
  4541. /// Delete interactive activities
  4542. function delete ($return) {
  4543. global $USER, $CFG, $DB, $OUTPUT;
  4544. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4545. print $OUTPUT->header();
  4546. $output .= $OUTPUT->box_start();
  4547. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4548. if ($iassign_submission_currents) {
  4549. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4550. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4551. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4552. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4553. $output .= $OUTPUT->box_end();
  4554. $output .= $OUTPUT->footer();
  4555. print $output;
  4556. die();
  4557. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4558. } // if ($iassign_submission_currents)
  4559. else
  4560. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>\n";
  4561. $output .= '<table width=50% border=0>';
  4562. $output .= '<tr valign="top"><td>';
  4563. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>\n";
  4564. $output .= '</td><td>';
  4565. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4566. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4567. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>\n";
  4568. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4569. $output .= "</form>\n";
  4570. $output .= '</td><td>';
  4571. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4572. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4573. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4574. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4575. $output .= "</form>\n";
  4576. $output .= '</td></tr></table>' . "\n";
  4577. $output .= $OUTPUT->box_end();
  4578. $output .= $OUTPUT->footer();
  4579. print $output;
  4580. } // function delete($return)
  4581. /// Function for confirm the delete of activity
  4582. // @param String $return Url of return
  4583. // @param Object $iassign Object content an activity
  4584. function deleteyes ($return, $iassign) {
  4585. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4586. $msg = '';
  4587. if (!empty($this->activity->id)) {
  4588. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4589. if ($iassign_submission_currents) {
  4590. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4591. foreach ($iassign_submission_currents as $iassign_submission)
  4592. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4593. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4594. } // if ($iassign_submission_currents)
  4595. }
  4596. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4597. // Remove all files associated to this activity:
  4598. $fs = get_file_storage();
  4599. //TODO 2022: nao deveria ser "$this->activity->file" no lugar de "$this->activity->id"?
  4600. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4601. $this->delete_calendar($this->activity->id);
  4602. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4603. iassign::update_grade_iassign($this->activity->iassignid);
  4604. if ($delete_iassign_current) {
  4605. $iassign->return_home_course('confirm_delete_iassign');
  4606. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4607. }
  4608. else {
  4609. $iassign->return_home_course('error_confirm_delete_iassign');
  4610. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4611. }
  4612. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4613. }
  4614. } // function deleteyes($return, $iassign)
  4615. /// Change fields 'iassign_statement.position' between 2 activities
  4616. // @calledby : class this->move_iassign($move_action, $target, $return)
  4617. // @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})
  4618. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4619. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4620. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4621. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4622. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4623. print_error('error_update_move_iassign', 'iassign');
  4624. }
  4625. // If $idFrom == $idTo then came here from 'this->show_iassign(.)' above, to correct order!
  4626. if ($idFrom != $idTo) { // if $idFrom != $idTo then must update also the targe position
  4627. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4628. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4629. if (!$DB->update_record('iassign_statement', $newentry))
  4630. print_error('error_update_move_iassign', 'iassign');
  4631. }
  4632. }
  4633. /// Changes position of activities (between those inside a group of interactive activities)
  4634. // @param $move_action = must be "up" or "down"
  4635. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4636. function move_iassign ($move_action, $target, $return) {
  4637. global $DB, $OUTPUT;
  4638. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4639. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4640. if ($move_action=="firstdown") {
  4641. $final_position_source = 2;
  4642. $final_position_target = 1;
  4643. }
  4644. else
  4645. if ($move_action=="down") {
  4646. $final_position_target = $this->activity->position;
  4647. $final_position_source = $final_position_target + 1;
  4648. }
  4649. else
  4650. if ($move_action=="up") {
  4651. $final_position_target = $this->activity->position;
  4652. $final_position_source = $final_position_target - 1;
  4653. }
  4654. else { // error:
  4655. print_error('error_update_move_iassign', 'iassign');
  4656. exit;
  4657. }
  4658. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4659. redirect($return);
  4660. } // function move_iassign($move_action, $target, $return)
  4661. /// Enable or disable the display of interactive activities
  4662. function visible_iassign ($return) {
  4663. global $DB;
  4664. $newentry = new stdClass();
  4665. $newentry->id = $this->activity->id;
  4666. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4667. if (!$DB->update_record('iassign_statement', $newentry))
  4668. print_error('error_update_visible_iassign', 'iassign');
  4669. redirect($return);
  4670. }
  4671. /// Add news interactive activities (register in table 'iassign_statement')
  4672. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4673. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4674. function new_iassign ($param) {
  4675. global $DB;
  4676. $newentry = new stdClass();
  4677. $newentry->iassignid = $param->iassignid;
  4678. $newentry->name = $param->name;
  4679. $newentry->type_iassign = $param->type_iassign;
  4680. $newentry->store_all_submissions = $param->store_all_submissions;
  4681. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4682. $proposition = $param->proposition;
  4683. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4684. else $proposition_text = $proposition;
  4685. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4686. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4687. //TODO Then get it directly from the form data $_POST!
  4688. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4689. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4690. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4691. $newentry->author_name = $param->author_name;
  4692. $newentry->author_modified_name = $param->author_modified_name;
  4693. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4694. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4695. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4696. $newentry->grade = $param->grade;
  4697. $newentry->timemodified = time();
  4698. $newentry->timecreated = time();
  4699. if ($param->type_iassign == 1) {
  4700. $newentry->timedue = 0;
  4701. $newentry->timeavailable = 0;
  4702. } // if ($param->type_iassign == 1)
  4703. else {
  4704. $newentry->timedue = $param->timedue;
  4705. $newentry->timeavailable = $param->timeavailable;
  4706. }
  4707. $newentry->preventlate = $param->preventlate;
  4708. $newentry->test = $param->test;
  4709. $newentry->special_param1 = $param->special_param1;
  4710. $newentry->visible = $param->visible;
  4711. $newentry->position = $param->position;
  4712. $newentry->max_experiment = $param->max_experiment;
  4713. $newentry->dependency = $param->dependency;
  4714. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4715. $newentry->show_answer = $param->show_answer;
  4716. $id = $DB->insert_record("iassign_statement", $newentry);
  4717. if ($id) {
  4718. $component = 'mod_iassign';
  4719. $filearea = 'exercise';
  4720. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4721. $file = $fs->get_file_by_id($param->file);
  4722. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4723. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4724. //$itemid = $id;
  4725. // File already inserted in other context!
  4726. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4727. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4728. $updateentry = new stdClass();
  4729. $updateentry->id = $id;
  4730. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4731. $updateentry->filesid = $newfile->get_itemid();
  4732. if (!$DB->update_record("iassign_statement", $updateentry))
  4733. print_error('error_add', 'iassign');
  4734. if ($param->type_iassign == 3)
  4735. iassign::update_grade_iassign($param->iassignid);
  4736. //TODO iLM_HTML5 :: //MOOC2014
  4737. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4738. //D if ($iassign_ilm_configs) {
  4739. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4740. //D if ($iassign_ilm_config->param_type != 'static') {
  4741. //D $newentry = new stdClass();
  4742. //D $newentry->iassign_statementid = $id;
  4743. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4744. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4745. //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});
  4746. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4747. //D print_error('error_add_param', 'iassign');
  4748. //D }
  4749. //D }
  4750. //D }
  4751. // log event --------------------------------------------------------------------------------------
  4752. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4753. // log event --------------------------------------------------------------------------------------
  4754. return $id;
  4755. }
  4756. else
  4757. print_error('error_add', 'iassign');
  4758. } // function new_iassign($param)
  4759. /// Add the calendar entries for this iassign
  4760. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4761. // @return bool
  4762. static function add_calendar ($iassignid) {
  4763. global $DB, $CFG;
  4764. require_once($CFG->dirroot . '/calendar/lib.php');
  4765. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4766. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4767. $event = new stdClass();
  4768. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4769. $event->description = $iassign_statement_activity_item->name;
  4770. $event->courseid = $iassign->course;
  4771. $event->groupid = 0;
  4772. $event->userid = 0;
  4773. $event->modulename = 'iassign';
  4774. $event->instance = $iassign->id;
  4775. $event->eventtype = 'due';
  4776. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4777. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4778. calendar_event::create($event);
  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 update_calendar ($iassignid, $olddescription) {
  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. $event = new stdClass();
  4789. $event->id = 0;
  4790. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4791. if ($events) {
  4792. foreach ($events as $value) {
  4793. if ($value->description == $olddescription) {
  4794. $event->id = $value->id;
  4795. }
  4796. }
  4797. }
  4798. if ($event->id != 0) {
  4799. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4800. $event->description = $iassign_statement_activity_item->name;
  4801. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4802. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4803. $calendarevent = calendar_event::load($event->id);
  4804. $calendarevent->update($event);
  4805. } else
  4806. $this->add_calendar($iassignid);
  4807. }
  4808. /// Update the calendar entries for this iassign
  4809. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4810. // @return bool
  4811. function delete_calendar ($iassignid) {
  4812. global $DB, $CFG;
  4813. require_once($CFG->dirroot . '/calendar/lib.php');
  4814. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4815. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4816. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4817. if ($events) {
  4818. foreach ($events as $value) {
  4819. if ($value->description == $iassign_statement_activity_item->name) {
  4820. $DB->delete_records('event', array('id' => $value->id));
  4821. }
  4822. }
  4823. }
  4824. }
  4825. /// Update interactive activities
  4826. function update_iassign ($param) {
  4827. global $DB;
  4828. $component = 'mod_iassign';
  4829. $filearea = 'exercise';
  4830. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4831. $file = $fs->get_file_by_id($param->file);
  4832. $fileold = $fs->get_file_by_id($param->fileold);
  4833. if ($param->file != $param->fileold) {
  4834. if ($fileold) {
  4835. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4836. foreach ($fileoldarea as $value) {
  4837. $value->delete();
  4838. }
  4839. }
  4840. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4841. $itemid = $file->get_itemid() + $param->iassign_id;
  4842. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4843. $param->file = $newfile->get_itemid();
  4844. }
  4845. else
  4846. $param->file = $file->get_itemid();
  4847. }
  4848. else {
  4849. $param->file = $file->get_itemid();
  4850. }
  4851. $newentry = new stdClass();
  4852. $newentry->id = $param->iassign_id;
  4853. $newentry->name = $param->name;
  4854. $newentry->type_iassign = $param->type_iassign;
  4855. $newentry->store_all_submissions = $param->store_all_submissions;
  4856. //2019 $newentry->proposition = $param->proposition;
  4857. $proposition = $param->proposition;
  4858. if (is_array($proposition))
  4859. $proposition_text = $proposition['text'];
  4860. else
  4861. $proposition_text = $proposition;
  4862. $newentry->proposition = $proposition_text;
  4863. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4864. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4865. $newentry->grade = $param->grade;
  4866. $newentry->author_modified_name = $param->author_modified_name;
  4867. $newentry->timemodified = time();
  4868. if ($param->type_iassign == 1) {
  4869. $newentry->timedue = 0;
  4870. $newentry->timeavailable = 0;
  4871. } // if ($param->type_iassign == 1)
  4872. else {
  4873. $newentry->timedue = $param->timedue;
  4874. $newentry->timeavailable = $param->timeavailable;
  4875. }
  4876. $newentry->preventlate = $param->preventlate;
  4877. $newentry->test = $param->test;
  4878. if (isset($param->special_param1))
  4879. $newentry->special_param1 = $param->special_param1;
  4880. else
  4881. $newentry->special_param1 = NULL;
  4882. $newentry->visible = $param->visible;
  4883. $newentry->max_experiment = $param->max_experiment;
  4884. $newentry->dependency = $param->dependency;
  4885. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4886. $newentry->show_answer = $param->show_answer;
  4887. if (!$DB->update_record("iassign_statement", $newentry))
  4888. print_error('error_update', 'iassign');
  4889. if ($param->type_iassign == 3) {
  4890. iassign::update_grade_iassign($param->iassignid);
  4891. }
  4892. //$id = $newentry->id; // MOOC 2016 --- inicio
  4893. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4894. //if ($iassign_activity_item_configs) {
  4895. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4896. // $newentry = new stdClass();
  4897. // $newentry->id = $iassign_activity_item_config->id;
  4898. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4899. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4900. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4901. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4902. // print_error('error_edit_param', 'iassign');
  4903. // }
  4904. // } // MOOC 2016 --- final
  4905. // log event --------------------------------------------------------------------------------------
  4906. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4907. // log event --------------------------------------------------------------------------------------
  4908. return $newentry->id;
  4909. // if ($param->type_iassign==3)
  4910. // $this->update_grade_iassign($param->iassignid);
  4911. } // function update_iassign($param)
  4912. /// Show information of activity
  4913. function show_info_iassign () {
  4914. global $DB, $OUTPUT;
  4915. $output = '';
  4916. if ($this->activity->type_iassign == 3) {
  4917. if ($this->activity->dependency == 0) {
  4918. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4919. } else {
  4920. $dependencys = explode(';', $this->activity->dependency);
  4921. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4922. foreach ($dependencys as $dependency) {
  4923. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4924. if ($dependencyiassign)
  4925. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4926. } // foreach ($dependencys as $dependency)
  4927. } // if ($iassign_statement_activity_item->dependency == 0)
  4928. if ($this->activity->max_experiment == 0)
  4929. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4930. else
  4931. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4932. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4933. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4934. $output .= $this->toggle_columns_script();
  4935. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4936. print $OUTPUT->box($output);
  4937. } // function show_info_iassign()
  4938. /// Provide script to toggle columns
  4939. static function toggle_columns_script () {
  4940. $output = "";
  4941. $output .= '<script>
  4942. function toLeft () {
  4943. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4944. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4945. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4946. document.getElementById("columnsbutton").style.color = "#1da075";
  4947. }
  4948. function toDefault () {
  4949. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4950. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4951. document.getElementById("fullscreen").style.marginTop = "0";
  4952. document.getElementById("columnsbutton").style.color = "#343a40";
  4953. }
  4954. var activate = false;
  4955. function toggleColumns () {
  4956. if (activate) {
  4957. activate = false;
  4958. toDefault();
  4959. } else {
  4960. activate = true;
  4961. toLeft();
  4962. }
  4963. }
  4964. </script>'; // '
  4965. $output .= '<span tabindex="0" data-toggle="tooltip" title="' . get_string('enable_disable_columns', 'iassign')
  4966. . '" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>' . "\n";
  4967. return $output;
  4968. } // function write_comment_submission()
  4969. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the greatest grade?
  4970. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  4971. $item = NULL;
  4972. foreach ($iassign_statement as $item) ; // get the last item!
  4973. if ($item) return $item; // return the last one
  4974. return NULL;
  4975. }
  4976. /// Shows date of opening and closing activities
  4977. function view_dates () {
  4978. global $USER, $CFG, $DB, $OUTPUT;
  4979. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4980. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4981. $status_iassign = "";
  4982. $status_iassign1 = "";
  4983. $status_iassign2 = "";
  4984. if ($this->activity->type_iassign == 1) // activity of type example
  4985. $type_iassign = get_string('example_iassign', 'iassign');
  4986. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4987. $type_iassign = get_string('test_iassign', 'iassign');
  4988. if ($this->activity->timeavailable > time()) {
  4989. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4990. } elseif ($this->activity->timedue < time()) {
  4991. $status_iassign = get_string('last_timedue', 'iassign');
  4992. }
  4993. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4994. $type_iassign = get_string('exercise_iassign', 'iassign');
  4995. if ($this->activity->timeavailable > time()) {
  4996. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4997. } elseif ($this->activity->timedue < time()) { // after delivery
  4998. $status_iassign = get_string('last_timedue', 'iassign');
  4999. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  5000. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  5001. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  5002. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  5003. if ($this->activity->test == 1) // allowed to test after of deadline
  5004. $status_iassign2 = get_string('test_preventlate', 'iassign');
  5005. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  5006. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  5007. } // elseif ($iassign_statement_activity_item->test == 0)
  5008. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  5009. } // elseif ($iassign_statement_activity_item->timedue < time())
  5010. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  5011. $output = '<table width=100% >' . "\n";
  5012. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  5013. $output .= '<tr>' . "\n";
  5014. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  5015. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  5016. //leo $output .= '<td width=80%>' . $type_iassign;
  5017. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  5018. // $output .= '</td>' . "\n";
  5019. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  5020. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  5021. $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>";
  5022. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  5023. }
  5024. else {
  5025. // Get all previous/next solution sent by this student (present link to his last answer)
  5026. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  5027. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  5028. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  5029. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  5030. $link_next = "";
  5031. $link_previous = "";
  5032. if ($iassign_previous) { // previous_activity
  5033. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5034. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5035. }
  5036. if ($iassign_next) { // next_activity
  5037. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5038. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5039. }
  5040. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5041. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5042. $output .= '</tr></table>' . "\n";
  5043. $output .= '<table width=100% >' . "\n";
  5044. if ($this->activity->type_iassign > 1) {
  5045. if ($this->activity->timeavailable)
  5046. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5047. if ($this->activity->timedue)
  5048. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5049. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5050. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5051. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5052. $output .= '</table>' . "\n";
  5053. print $OUTPUT->box($output);
  5054. } // function view_dates()
  5055. } // class activity
  5056. /// Class to manage Interactive Learning Module (iLM)
  5057. class ilm {
  5058. var $ilm;
  5059. /// Constructor of class
  5060. // @param int $id Id of iLM
  5061. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5062. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5063. function __construct ($id) {
  5064. global $DB;
  5065. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5066. if (empty($this->ilm))
  5067. $this->ilm = null;
  5068. }
  5069. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5070. // @calledby view_iassign_current()
  5071. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5072. global $USER, $CFG, $DB;
  5073. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5074. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5075. $typec = strtolower($iassign_ilm->type);
  5076. require_once 'ilm_handlers/' . $typec . '.php';
  5077. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5078. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5079. return $retorno;
  5080. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5081. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5082. // @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);
  5083. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5084. // @param Object $file File in use in activity
  5085. // @return int Return the id of log
  5086. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5087. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5088. $newentry = new stdClass();
  5089. $newentry->iassign_statementid = $iassign_activity_itemid;
  5090. $newentry->userid = $USER->id;
  5091. $newentry->filesid = $content_or_id_from_ilm_security;
  5092. $newentry->timecreated = time();
  5093. $newentry->view = 1;
  5094. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5095. if (!$id_iLM_security) {
  5096. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5097. } // from (!$DB->insert_record("iassign_security", $newentry))
  5098. return $id_iLM_security;
  5099. }
  5100. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5101. // @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);
  5102. // @param int $userid
  5103. // @param int $iassign_activity_itemid Id of iassign statement
  5104. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5105. global $DB;
  5106. // 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")
  5107. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5108. }
  5109. } // class ilm
  5110. /// Class to manage settings of iLM.
  5111. class ilm_settings {
  5112. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5113. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5114. // @param int $ilm_id Id of iLM
  5115. // @param array $options An array with options for create dynamic tag html APPLET
  5116. // @return string Return with a tag html APPLET created
  5117. static function build_ilm_tags ($ilm_id, $options = array()) {
  5118. global $DB;
  5119. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5120. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5121. $typec = strtolower($iassign_ilm->type);
  5122. require_once 'ilm_handlers/' . $typec . '.php';
  5123. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5124. return $retorno;
  5125. } // static function build_ilm_tags($ilm_id, $options = array())
  5126. /// Function for get modified date of iLM file
  5127. // @param string $file_jar String with Ids of iLM files
  5128. // @return string Return with the filenames and modified date
  5129. static function applet_filetime ($file_jar) {
  5130. $filetime = "";
  5131. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5132. $files_jar = explode(",", $file_jar);
  5133. foreach ($files_jar as $one_file) {
  5134. $file = $fs->get_file_by_id($one_file);
  5135. if ($file)
  5136. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5137. }
  5138. return $filetime;
  5139. }
  5140. /// Function for verify an default applet
  5141. // @param String $file_jar String containing an list de ids of applet files
  5142. // @return boolean Return true or fale if applet is default
  5143. static function applet_default ($file_jar) {
  5144. $is_default = true;
  5145. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5146. $files_jar = explode(",", $file_jar);
  5147. foreach ($files_jar as $one_file) {
  5148. $file = $fs->get_file_by_id($one_file);
  5149. if ($file)
  5150. $is_default &= ($file->get_itemid() == 0);
  5151. }
  5152. return $is_default;
  5153. }
  5154. /// Function for get form variables for add, edit, or copy iLM
  5155. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  5156. // @see settings_form.php
  5157. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5158. // @param int $ilm_id Id of iLM
  5159. // @param string $action String with the action
  5160. // @return object Return an object with forms variables
  5161. static function add_edit_copy_ilm ($ilm_id, $action) {
  5162. global $USER, $DB, $CFG;
  5163. require_once('settings_form.php'); // put the form
  5164. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5165. $param = new stdClass();
  5166. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  5167. $param->action = $action;
  5168. $param->ilm_id = $ilm_id;
  5169. $CFG->action_ilm = $action;
  5170. $CFG->ilm_id = $ilm_id;
  5171. if ($action == 'add') {
  5172. $param->title = get_string('add_ilm', 'iassign');
  5173. $param->name = "";
  5174. $param->version = "";
  5175. $param->url = "";
  5176. $param->description = "";
  5177. $param->extension = "";
  5178. $param->author = $USER->id;
  5179. $param->file_jar = "";
  5180. $param->file_jar_static = "";
  5181. $param->file_class = "";
  5182. $param->width = 800;
  5183. $param->height = 600;
  5184. $param->enable = 0; // 0 - hide / 1 - show
  5185. $param->timecreated = time();
  5186. $param->timemodified = time();
  5187. $param->evaluate = 0;
  5188. $param->parent = 0;
  5189. }
  5190. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5191. if ($iassign_ilm) {
  5192. $description = json_decode($iassign_ilm->description);
  5193. $param->title = get_string('edit_ilm', 'iassign');
  5194. $param->id = $iassign_ilm->id;
  5195. $param->name_ilm = $iassign_ilm->name;
  5196. $param->name = $iassign_ilm->name;
  5197. $param->version = $iassign_ilm->version;
  5198. $param->ilm_type = $iassign_ilm->type;
  5199. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5200. $param->url = $iassign_ilm->url; // iLM official URL
  5201. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5202. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5203. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5204. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5205. if (!isset($description->{current_language()})) {
  5206. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5207. else
  5208. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5209. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5210. }
  5211. else
  5212. $param->description = $description->{current_language()};
  5213. $param->description_lang = $iassign_ilm->description;
  5214. $param->extension = $iassign_ilm->extension;
  5215. $param->author = $iassign_ilm->author;
  5216. $param->file_jar = $iassign_ilm->file_jar;
  5217. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5218. $param->file_class = $iassign_ilm->file_class;
  5219. $param->width = $iassign_ilm->width;
  5220. $param->height = $iassign_ilm->height;
  5221. $param->enable = $iassign_ilm->enable;
  5222. $param->timecreated = $iassign_ilm->timecreated;
  5223. $param->timemodified = time();
  5224. $param->evaluate = $iassign_ilm->evaluate;
  5225. $param->parent = $iassign_ilm->parent;
  5226. }
  5227. }
  5228. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5229. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5230. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5231. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5232. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5233. // echo "Sem dados<br/>"; exit;
  5234. return;
  5235. }
  5236. $description = json_decode($iassign_ilm->description);
  5237. if ($iassign_ilm) {
  5238. if ($iassign_ilm->parent == 0)
  5239. $iassign_ilm->parent = $ilm_id;
  5240. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5241. $param->title = get_string('new_version_ilm', 'iassign');
  5242. $param->name_ilm = $iassign_ilm->name;
  5243. $param->name = $iassign_ilm->name;
  5244. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5245. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5246. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5247. $param->ilm_type = $iassign_ilm->type;
  5248. $param->url = $iassign_ilm->url;
  5249. $param->description = $description->{current_language()};
  5250. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5251. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5252. $param->extension = $iassign_ilm->extension;
  5253. $param->author = $USER->id;
  5254. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5255. $param->file_jar = $iassign_ilm->file_jar; // do not erase field '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. elseif ($action == 'copy') {
  5268. $description = json_decode($iassign_ilm->description);
  5269. if ($iassign_ilm) {
  5270. if ($iassign_ilm->parent == 0)
  5271. $iassign_ilm->parent = $ilm_id;
  5272. $param->title = get_string('copy_ilm', 'iassign');
  5273. $param->id = $iassign_ilm->id;
  5274. $param->name_ilm = $iassign_ilm->name;
  5275. $param->name = $iassign_ilm->name;
  5276. $param->version = "";
  5277. $param->ilm_type = $iassign_ilm->type;
  5278. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5279. $param->url = $iassign_ilm->url;
  5280. $param->description = $description->{current_language()};
  5281. $param->description_lang = $iassign_ilm->description;
  5282. $param->extension = $iassign_ilm->extension;
  5283. $param->author = $USER->id;
  5284. $param->file_jar = '';
  5285. $param->file_jar_static = '';
  5286. $param->file_class = $iassign_ilm->file_class;
  5287. $param->width = $iassign_ilm->width;
  5288. $param->height = $iassign_ilm->height;
  5289. $param->enable = 0;
  5290. $param->timecreated = time();
  5291. $param->timemodified = time();
  5292. $param->evaluate = $iassign_ilm->evaluate;
  5293. $param->parent = $iassign_ilm->parent;
  5294. }
  5295. }
  5296. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5297. //D var_dump(debug_backtrace());
  5298. //D print_r(debug_backtrace());
  5299. return $param;
  5300. } // static function add_edit_copy_ilm($ilm_id, $action)
  5301. /// Function for save iLM file in moodledata
  5302. // @param int $itemid Itemid of file save in draft (upload file)
  5303. // @param int $ilm_id Id of iLM
  5304. // @return string Return an string with ids of iLM files
  5305. static function new_file_ilm ($itemid, $iassign_ilm) {
  5306. global $CFG, $USER, $DB;
  5307. $return = null;
  5308. $file_jar = array();
  5309. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5310. $contextuser = context_user::instance($USER->id);
  5311. $contextsystem = context_system::instance();
  5312. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5313. if ($files_ilm) {
  5314. foreach ($files_ilm as $value) {
  5315. // CHECK IF file is HTML type
  5316. if ($iassign_ilm->type == 1) {
  5317. // Check if the file extension is ZIP
  5318. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5319. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5320. if ((strtolower($ext) == 'zip')) {
  5321. // Coping...:
  5322. $destination = 'ilm_debug/' . $value->get_filename();
  5323. $value->copy_content_to($destination);
  5324. // Extracting content...:
  5325. $zip = new ZipArchive();
  5326. $extracted = './ilm';
  5327. $dir = "";
  5328. if ($zip->open($destination) === TRUE) {
  5329. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5330. if (is_dir($dir)) {
  5331. $i = 1;
  5332. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5333. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5334. $i++;
  5335. }
  5336. $name = $previous . "_" . $i;
  5337. $dir = './ilm/' . $name . "/";
  5338. $j = 0;
  5339. while ($item_name = $zip->getNameIndex($j)) {
  5340. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5341. $j++;
  5342. }
  5343. $zip->close();
  5344. }
  5345. $zip->open($destination);
  5346. $zip->extractTo($extracted);
  5347. $zip->close();
  5348. // After the extraction, remove it from DEBUG
  5349. unlink($destination);
  5350. } else { // Error trying to open destination...
  5351. // After the extraction error, also remove it from DEBUG
  5352. unlink($destination);
  5353. print_error('error_add_ilm_zip', 'iassign');
  5354. }
  5355. return $dir;
  5356. }
  5357. } // if ($iassign_ilm->type == 1)
  5358. if ($value->get_filename() != '.') {
  5359. $file_ilm = array(
  5360. 'userid' => $USER->id,
  5361. 'contextid' => $contextsystem->id,
  5362. 'component' => 'mod_iassign',
  5363. 'filearea' => 'ilm',
  5364. 'itemid' => rand(1, 999999999),
  5365. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5366. 'filename' => $value->get_filename());
  5367. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5368. array_push($file_jar, $file_ilm->get_id());
  5369. }
  5370. }
  5371. if (!empty($file_jar)) {
  5372. $return = implode(",", $file_jar);
  5373. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5374. foreach ($old_file_jar as $value) {
  5375. $file = $fs->get_file_by_id($value);
  5376. if ($file)
  5377. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5378. }
  5379. }
  5380. }
  5381. else // if ($files_ilm)
  5382. $return = $iassign_ilm->file_jar;
  5383. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5384. return $return;
  5385. } // static function new_file_ilm($itemid, $iassign_ilm)
  5386. /// Function for save in database an new iLM
  5387. // @param object $param An object with iLM params
  5388. static function new_ilm ($itemid) {
  5389. global $CFG, $USER, $OUTPUT;
  5390. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5391. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5392. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5393. }
  5394. $pathtemp = $CFG->dataroot . '/temp/';
  5395. $contextuser = context_user::instance($USER->id);
  5396. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5397. $zip = new zip_packer();
  5398. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5399. foreach ($files as $file) {
  5400. if (!$file->is_directory())
  5401. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5402. }
  5403. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5404. // Verifica se o pacote possui o XML
  5405. if (!$application_xml) {
  5406. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5407. return;
  5408. } else {
  5409. $missing = "";
  5410. if (!isset($application_xml->name)) {
  5411. $missing .= "name";
  5412. }
  5413. if (!isset($application_xml->version)) {
  5414. $missing .= ", version";
  5415. }
  5416. if (!isset($application_xml->type)) {
  5417. $missing .= ", type";
  5418. }
  5419. if (!isset($application_xml->extension)) {
  5420. $missing .= ", extension";
  5421. }
  5422. if (!isset($application_xml->file_jar)) {
  5423. $missing .= ", file_jar";
  5424. }
  5425. if (!isset($application_xml->file_class)) {
  5426. $missing .= ", file_class";
  5427. }
  5428. if (!isset($application_xml->width)) {
  5429. $missing .= ", width";
  5430. }
  5431. if (!isset($application_xml->height)) {
  5432. $missing .= ", height";
  5433. }
  5434. if (!isset($application_xml->evaluate)) {
  5435. $missing .= ", evaluate";
  5436. }
  5437. if (strlen($missing) > 2) {
  5438. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5439. return;
  5440. }
  5441. }
  5442. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5443. $typec = strtolower($application_xml->type);
  5444. require_once 'ilm_handlers/' . $typec . '.php';
  5445. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5446. return $retorno;
  5447. } // static function new_ilm($itemid)
  5448. /// Function for save in database an iLM edit
  5449. // @param object $param An object with iLM params
  5450. static function edit_ilm ($param, $itemid) {
  5451. // Descobrir o tipo de iLM:
  5452. global $DB, $USER, $CFG;
  5453. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5454. $pathtemp = $CFG->dataroot . '/temp/';
  5455. $contextuser = context_user::instance($USER->id);
  5456. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5457. $zip = new zip_packer();
  5458. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5459. $files_extract = null;
  5460. foreach ($files as $file) {
  5461. if (!$file->is_directory())
  5462. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5463. }
  5464. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5465. $typec = strtolower($iassign_t->type);
  5466. require_once 'ilm_handlers/' . $typec . '.php';
  5467. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5468. }
  5469. /// Function for register the new iLM (in database and in the directory)
  5470. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5471. // @param object $param An object with iLM params
  5472. static function copy_new_version_ilm ($param) {
  5473. global $DB, $CFG, $USER;
  5474. $itemid = $param->file;
  5475. $pathtemp = $CFG->dataroot . '/temp/';
  5476. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5477. //D echo "pathtemp=$pathtemp<br/>";
  5478. $contextuser = context_user::instance($USER->id);
  5479. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5480. $zip = new zip_packer();
  5481. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5482. $files_extract = null;
  5483. foreach ($files as $file) {
  5484. if (!$file->is_directory())
  5485. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5486. }
  5487. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5488. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5489. $typec = strtolower($iassign_t->type);
  5490. require_once 'ilm_handlers/' . $typec . '.php';
  5491. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5492. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5493. } // static function copy_new_version_ilm($param)
  5494. //VER::
  5495. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5496. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5497. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5498. /// Function for change visibility of iLM
  5499. // @param int $ilm_id Id of iLM
  5500. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5501. static function visible_ilm ($ilm_id, $status) {
  5502. global $DB;
  5503. if ($status == 0)
  5504. $visible = 1;
  5505. else
  5506. $visible = 0;
  5507. $newentry = new stdClass();
  5508. $newentry->id = $ilm_id;
  5509. $newentry->enable = $visible;
  5510. if (!$DB->update_record("iassign_ilm", $newentry))
  5511. error(get_string('error_edit_ilm', 'iassign'));
  5512. }
  5513. /// Function for confirm change default iLM
  5514. // @param int $ilm_id Id of iLM
  5515. // @param int $ilm_parent Id of parent iLM
  5516. // @return string Return with an string for create default page confirmation
  5517. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5518. global $OUTPUT, $DB;
  5519. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5520. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5521. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5522. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5523. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5524. return $return;
  5525. }
  5526. /// Function for change the default iLM
  5527. // @see settings_ilm.php
  5528. // @param int $ilm_id Id of iLM
  5529. // @return int Return Id of default iLM
  5530. static function default_ilm ($ilm_id) {
  5531. global $DB;
  5532. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5533. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5534. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5535. $iassign_ilm_default->id = $iassign_ilm->id;
  5536. $iassign_ilm_default->parent = 0;
  5537. $iassign_ilm->parent = $iassign_ilm_default->id;
  5538. $iassign_ilm->id = 0;
  5539. $iassign_ilm_default->enable = 1;
  5540. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5541. print_error('error_edit_ilm', 'iassign');
  5542. }
  5543. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5544. if (!$inserted) {
  5545. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5546. print_error($msg_error);
  5547. //xx print_error('error_add_ilm', 'iassign');
  5548. }
  5549. return $iassign_ilm_default->id;
  5550. } // static function default_ilm ($ilm_id)
  5551. /// Function for confirm delete iLM
  5552. // @param int $ilm_id Id of iLM
  5553. // @param int $ilm_parent Id of parent iLM
  5554. // @return string Return with an string for create delete page confirmation
  5555. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5556. global $OUTPUT, $DB;
  5557. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5558. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5559. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5560. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5561. }
  5562. /// Function for delete directory where the iLM is allocated.
  5563. // @param string $dirPath
  5564. // @throws InvalidArgumentException
  5565. public static function delete_dir ($dirPath) {
  5566. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5567. $dirPath .= '/';
  5568. }
  5569. $files = glob($dirPath . '*', GLOB_MARK);
  5570. foreach ($files as $file) {
  5571. if (is_dir($file)) {
  5572. ilm_settings::delete_dir($file);
  5573. } else {
  5574. unlink($file);
  5575. }
  5576. }
  5577. rmdir($dirPath);
  5578. }
  5579. /// Function for delete iLM
  5580. // @param int $ilm_id Id of iLM
  5581. // @return int Return Id of parent iLM
  5582. static function delete_ilm ($ilm_id) {
  5583. global $DB;
  5584. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5585. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5586. $typec = strtolower($iassign_ilm->type);
  5587. require_once 'ilm_handlers/' . $typec . '.php';
  5588. $retorno = $typec::delete_ilm($ilm_id);
  5589. return $retorno;
  5590. }
  5591. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5592. // @param int $ilm_id Id of iLM
  5593. static function export_ilm ($ilm_id) {
  5594. global $DB;
  5595. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5596. if (!$iassign_ilm) return; // security debug...
  5597. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5598. $typec = strtolower($iassign_ilm->type);
  5599. if (!$typec) $typec = "html5"; // security debug...
  5600. require_once 'ilm_handlers/' . $typec . '.php';
  5601. $typec::export_ilm($ilm_id);
  5602. } // static function export_ilm($ilm_id)
  5603. //TODO iLM_HTML5 :: //MOOC 2016
  5604. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5605. // @param int $ilm_id Id of iLM
  5606. static function export_update_ilm ($ilm_id) {
  5607. global $DB, $CFG;
  5608. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5609. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5610. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5611. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5612. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5613. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5614. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5615. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5616. $upgrade_descriptor .= '</upgrade>' . "\n";
  5617. file_put_contents($xml_filename, $upgrade_descriptor);
  5618. header("Pragma: public");
  5619. header("Expires: 0");
  5620. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5621. header("Cache-Control: private", false);
  5622. header('Content-Type: application/xml; charset=utf-8');
  5623. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5624. header("Content-Length: " . @filesize($xml_filename));
  5625. set_time_limit(0);
  5626. @readfile("$xml_filename") || die("File not found.");
  5627. unlink($xml_filename);
  5628. exit;
  5629. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5630. /// Function for save iLM from XML descriptor
  5631. // @param array $application_xml Data of XML descriptor
  5632. // @param array $files_extract Filenames of extract files
  5633. // @return array Return an array content id of JAR files
  5634. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5635. global $CFG, $USER;
  5636. // Tratamento diferenciado se for do tipo HTML5:
  5637. $source = "";
  5638. $diretorio = "";
  5639. if (strtolower($application_xml->type) == 'html5') {
  5640. $i = 0;
  5641. foreach ($files_extract as $key => $value) {
  5642. $file = $CFG->dataroot . '/temp/' . $key;
  5643. // Verifica se já existe a pasta no diretório dos iLM:
  5644. if ($i == 0) {
  5645. $source = $file;
  5646. if (file_exists("ilm/" . basename($file))) {
  5647. $j = 1;
  5648. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5649. $j++;
  5650. }
  5651. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5652. // mkdir($diretorio, 0777, true);
  5653. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5654. }
  5655. else {
  5656. $diretorio = 'ilm/' . basename($file);
  5657. // mkdir($diretorio, 0777, true);
  5658. mkdir($diretorio, 0755, true);
  5659. }
  5660. break;
  5661. }
  5662. $i++;
  5663. }
  5664. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5665. if ($item->isDir()) {
  5666. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5667. }
  5668. else {
  5669. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5670. }
  5671. }
  5672. ilm_settings::delete_dir($source);
  5673. return "./" . $diretorio;
  5674. }
  5675. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5676. $file_jar = array();
  5677. $files_ilm = explode(",", $application_xml->file_jar);
  5678. $contextsystem = context_system::instance();
  5679. foreach ($files_ilm as $value) {
  5680. $file_ilm = array(
  5681. 'userid' => $USER->id,
  5682. 'contextid' => $contextsystem->id,
  5683. 'component' => 'mod_iassign',
  5684. 'filearea' => 'ilm',
  5685. 'itemid' => rand(1, 999999999),
  5686. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5687. 'filename' => $value);
  5688. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5689. array_push($file_jar, $file_ilm->get_id());
  5690. }
  5691. foreach ($files_extract as $key => $value) {
  5692. $file = $CFG->dataroot . '/temp/' . $key;
  5693. if (file_exists($file))
  5694. unlink($file);
  5695. }
  5696. return $file_jar;
  5697. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5698. /// Function for import the iLM from an package
  5699. // @param int $itemid Itemid of zip file
  5700. static function import_ilm ($itemid) {
  5701. global $CFG, $USER, $OUTPUT;
  5702. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5703. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5704. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5705. }
  5706. $pathtemp = $CFG->dataroot . '/temp/';
  5707. $contextuser = context_user::instance($USER->id);
  5708. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5709. $zip = new zip_packer();
  5710. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5711. foreach ($files as $file) {
  5712. if (!$file->is_directory())
  5713. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5714. }
  5715. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5716. // Verifica se o pacote possui o XML
  5717. if (!$application_xml) {
  5718. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5719. return;
  5720. } else {
  5721. $missing = "";
  5722. if (!isset($application_xml->name)) {
  5723. $missing .= "name";
  5724. }
  5725. if (!isset($application_xml->version)) {
  5726. $missing .= ", version";
  5727. }
  5728. if (!isset($application_xml->type)) {
  5729. $missing .= ", type";
  5730. }
  5731. if (!isset($application_xml->extension)) {
  5732. $missing .= ", extension";
  5733. }
  5734. if (!isset($application_xml->file_jar)) {
  5735. $missing .= ", file_jar";
  5736. }
  5737. if (!isset($application_xml->file_class)) {
  5738. $missing .= ", file_class";
  5739. }
  5740. if (!isset($application_xml->width)) {
  5741. $missing .= ", width";
  5742. }
  5743. if (!isset($application_xml->height)) {
  5744. $missing .= ", height";
  5745. }
  5746. if (!isset($application_xml->evaluate)) {
  5747. $missing .= ", evaluate";
  5748. }
  5749. if (strlen($missing) > 2) {
  5750. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5751. return;
  5752. }
  5753. }
  5754. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5755. $typec = strtolower($application_xml->type);
  5756. require_once 'ilm_handlers/' . $typec . '.php';
  5757. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5758. } // static function import_ilm($itemid)
  5759. /// Function for list iLM defaults
  5760. // @return string Return an string with a table of iLM
  5761. static function list_ilm () {
  5762. global $DB, $OUTPUT;
  5763. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5764. $str = '';
  5765. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5766. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5767. if ($iassign_ilm) {
  5768. foreach ($iassign_ilm as $ilm) {
  5769. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5770. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5771. $str .= '<tr><td>';
  5772. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5773. $str .= '<tr>';
  5774. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5775. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5776. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5777. $str .= '</tr>';
  5778. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5779. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5780. $str .= '</table>';
  5781. $str .= '</td></tr>';
  5782. }
  5783. }
  5784. $str .= '</table>';
  5785. return $str;
  5786. }
  5787. /// Function for download and install an upgrade of an iLM
  5788. // @param int $ilm_id Id of iLM
  5789. static function upgrade_ilm ($ilm_id) {
  5790. global $DB, $CFG, $USER;
  5791. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5792. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5793. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5794. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5795. if (!$result)
  5796. print_error('error_upgrade_ilm', 'iassign');
  5797. else {
  5798. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5799. $extension = explode(".", $zip_filename);
  5800. if ($extension[count($extension) - 1] != 'ipz') {
  5801. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5802. die;
  5803. }
  5804. $zip = new zip_packer();
  5805. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5806. $contextuser = context_user::instance($USER->id);
  5807. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5808. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5809. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5810. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5811. if (file_exists($zip_filename))
  5812. unlink($zip_filename);
  5813. if (empty($file_jar)) {
  5814. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5815. print_error($msg_error);
  5816. //xx print_error('error_add_ilm', 'iassign');
  5817. }
  5818. else {
  5819. $newentry = new stdClass();
  5820. $newentry->name = (String) $application_xml->name;
  5821. $newentry->version = (String) $application_xml->version;
  5822. $newentry->url = (String) $application_xml->url;
  5823. $newentry->description = $description_str;
  5824. $newentry->extension = strtolower((String) $application_xml->extension);
  5825. $newentry->file_jar = implode(",", $file_jar);
  5826. $newentry->file_class = (String) $application_xml->file_class;
  5827. $newentry->width = (String) $application_xml->width;
  5828. $newentry->height = (String) $application_xml->height;
  5829. $newentry->enable = 0;
  5830. $newentry->timemodified = time();
  5831. $newentry->author = $USER->id;
  5832. $newentry->timecreated = time();
  5833. $newentry->evaluate = (String) $application_xml->evaluate;
  5834. $newentry->parent = $ilm_id;
  5835. }
  5836. }
  5837. return $iassign_ilm->id;
  5838. } // static function upgrade_ilm($ilm_id)
  5839. //MOOC2014 -- inicio
  5840. //TODO: REVIEW
  5841. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5842. // static function move_iassign($ilm_id)
  5843. //MOOC2014 -- final
  5844. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  5845. // @return string Return an string with a table of iLM
  5846. static function view_ilm ($ilmid, $from) {
  5847. global $DB;
  5848. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5849. // Get the iLM type and calls its correspondent handler ('Java' or 'HTML5')
  5850. $typec = strtolower($iassign_ilm->type);
  5851. require_once 'ilm_handlers/' . $typec . '.php';
  5852. $retorno = $typec::view_ilm($ilmid, $from);
  5853. return $retorno;
  5854. }
  5855. /// Function for get form variables for add, edit, or copy iLM params
  5856. // @param int $ilm_param_id Id of iLM param
  5857. // @param string $action String with the action
  5858. // @return object Return an object with forms variables
  5859. static function add_edit_copy_param ($ilm_param_id, $action) {
  5860. global $DB;
  5861. require_once('params_form.php');
  5862. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5863. $param = new stdClass();
  5864. $param->action = $action;
  5865. $param->ilm_param_id = $ilm_param_id;
  5866. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5867. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5868. $type = $iassign_ilm_config->param_type;
  5869. if ($action == 'add') {
  5870. $param->title = get_string('add_ilm', 'iassign');
  5871. $param->iassign_ilmid = $ilm_param_id;
  5872. $param->param_name = "";
  5873. $param->param_value = "";
  5874. $param->description = "";
  5875. $param->visible = 1;
  5876. }
  5877. elseif ($action == 'edit') {
  5878. if ($iassign_ilm_config) {
  5879. $param->title = get_string('edit_ilm', 'iassign');
  5880. $param->id = $iassign_ilm_config->id;
  5881. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5882. $param->param_type = $type; //MOOC2014
  5883. $param->param_name = $iassign_ilm_config->param_name;
  5884. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5885. $param->param_value = $iassign_ilm_config->param_value;
  5886. else //MOOC2014
  5887. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5888. $param->param_value = $iassign_ilm_config->param_value;
  5889. $param->description = $iassign_ilm_config->description;
  5890. $param->visible = $iassign_ilm_config->visible;
  5891. }
  5892. }
  5893. elseif ($action == 'copy') {
  5894. if ($iassign_ilm_config) {
  5895. $param->title = get_string('copy_ilm', 'iassign');
  5896. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5897. $param->param_type = $type; //MOOC2014
  5898. $param->param_name = $iassign_ilm_config->param_name;
  5899. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5900. $param->param_value = $iassign_ilm_config->param_value;
  5901. else //MOOC2014
  5902. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5903. $param->description = $iassign_ilm_config->description;
  5904. $param->visible = $iassign_ilm_config->visible;
  5905. }
  5906. }
  5907. return $param;
  5908. } // static function add_edit_copy_param($ilm_param_id, $action)
  5909. /// Function for change visibility of iLM param
  5910. // @param int $ilm_param_id Id of iLM param
  5911. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5912. static function visible_param ($ilm_param_id, $status) {
  5913. global $DB, $CFG;
  5914. if ($status == 0)
  5915. $visible = 1;
  5916. else
  5917. $visible = 0;
  5918. $newentry = new stdClass();
  5919. $newentry->id = $ilm_param_id;
  5920. $newentry->visible = $visible;
  5921. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5922. error(get_string('error_edit_param', 'iassign'));
  5923. }
  5924. /// Function for save in database an new iLM param
  5925. // @param object $param An object with iLM params
  5926. static function add_param ($param) {
  5927. global $DB;
  5928. $newentry = new stdClass();
  5929. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5930. //MOOC2014 $newentry->param_name = $param->param_name;
  5931. $newentry->param_type = $param->param_type; //MOOC2014
  5932. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5933. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5934. $newentry->param_value = $param->param_value;
  5935. else //MOOC2014
  5936. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5937. $newentry->description = $param->description;
  5938. $newentry->visible = $param->visible;
  5939. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5940. if (!$newentry->id) {
  5941. print_error('error_add_param', 'iassign');
  5942. }
  5943. }
  5944. /// Function for save in database a iLM param edit
  5945. // @param object $param An object with iLM params
  5946. static function edit_param ($param) {
  5947. global $DB;
  5948. $updentry = new stdClass();
  5949. $updentry->id = $param->id;
  5950. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5951. $updentry->param_type = $param->param_type; //MOOC2014
  5952. // $updentry->param_name = $param->param_name;
  5953. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5954. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5955. $updentry->param_value = $param->param_value;
  5956. else //MOOC2014
  5957. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5958. $updentry->description = $param->description;
  5959. $updentry->visible = $param->visible;
  5960. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5961. error(get_string('error_edit_param', 'iassign'));
  5962. }
  5963. }
  5964. /// Function for save in database a iLM param copy
  5965. // @param object $param An object with iLM params
  5966. static function copy_param ($param) {
  5967. global $DB;
  5968. $newentry = new stdClass();
  5969. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5970. //$newentry->param_name = $param->param_name;
  5971. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5972. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5973. $newentry->param_value = $param->param_value;
  5974. else //MOOC2014
  5975. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5976. $newentry->description = $param->description;
  5977. $newentry->visible = $param->visible;
  5978. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5979. if (!$newentry->id) {
  5980. print_error('error_add_param', 'iassign');
  5981. }
  5982. }
  5983. /// Function for delete iLM param of database
  5984. // @param int $param_id Id of iLM param
  5985. static function delete_param ($param_id) {
  5986. global $DB;
  5987. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5988. print_error('error_delete_param', 'iassign');
  5989. }
  5990. }
  5991. } // class ilm_settings
  5992. /// Class for manage iLM files (editor).
  5993. class ilm_manager {
  5994. var $id; // course id
  5995. var $url;
  5996. var $from;
  5997. /// Constructor for the base ilm_manager class
  5998. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5999. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  6000. function __construct ($id, $url, $from) {
  6001. $this->id = $id; // course id
  6002. $this->url = $url;
  6003. $this->from = $from;
  6004. }
  6005. /// Function to get iAssign content file in Moodle data (exercise)
  6006. // @calledby x function preview_ilm($iassign_ilm) :
  6007. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  6008. function get_file_ilm () {
  6009. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6010. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6011. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  6012. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6013. $md_file = $fs->get_file_by_id($fileid);
  6014. $ilm_content_file = $md_file->get_content();
  6015. return $ilm_content_file;
  6016. }
  6017. /// Function for creating a new file from the iLM online editor
  6018. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  6019. function ilm_editor_new () {
  6020. global $CFG, $DB, $OUTPUT, $PAGE;
  6021. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6022. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6023. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6024. $context = context_course::instance($this->id);
  6025. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6026. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  6027. if (!$iassign) {
  6028. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  6029. die();
  6030. }
  6031. $temp = explode(",", $iassign->extension);
  6032. $extension = $temp[0]; // default extension for this iLM
  6033. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6034. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6035. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6036. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6037. if ($stringArchiveContent != NULL) {
  6038. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6039. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6040. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6041. $filename = optional_param('filename', NULL, PARAM_RAW);
  6042. //Leo $filename = iassign_utils::format_filename($filename); //
  6043. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6044. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6045. //2019/02 $arrayfilename = explode(".", $filename);
  6046. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6047. //2019/02 $count_dots = count($arrayfilename);
  6048. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6049. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6050. //2019/02 if ($last_name != $extension)
  6051. //2019/02 $filename = $filename . '.' . $extension;
  6052. //2019/02 }
  6053. //2019/02 else { // no extension...
  6054. //2019/02 $filename = $filename . '.' . $extension;
  6055. //2019/02 }
  6056. // Store the name of recent created file
  6057. $_SESSION['file_name'] = $filename;
  6058. //$this->write_file_iassign($string, $filename);
  6059. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6060. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6061. die();
  6062. }
  6063. else { // if ($stringArchiveContent != NULL)
  6064. // iLM On-line editor
  6065. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6066. $str_get_iLM = "window.frames.iLM";
  6067. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6068. }
  6069. else { // otherwise it is JAR named 'iLM'
  6070. $str_get_iLM = "document.iLM";
  6071. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6072. }
  6073. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6074. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6075. $files_array = '';
  6076. foreach ($files as $value) {
  6077. if ($value->get_filename() != ".")
  6078. $files_array .= "'" . $value->get_filename() . "',";
  6079. }
  6080. $files_array .= "''";
  6081. $file = null;
  6082. $ia_content = "";
  6083. $filename = "";
  6084. $error_files_exists = get_string('error_file_exists', 'iassign');
  6085. $output = "<script type='text/javascript'>
  6086. //<![CDATA[
  6087. //D alert('locallib.php: ilm_editor_new');
  6088. function submit_iLM_Answer () {
  6089. var docFormOnLineEditor = document.formEnvio;
  6090. var resposta_exerc = new Array(3);
  6091. var valor_resposta = new Array(3);
  6092. var sessao = new Array(3);
  6093. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6094. resposta_exerc[0] = doc_iLM.getAnswer();
  6095. valor_resposta[0] = doc_iLM.getEvaluation();
  6096. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6097. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6098. var files = new Array(" . $files_array . ");
  6099. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6100. if (docFormOnLineEditor.filename.value=='') {
  6101. // ERROR: the file name is empty
  6102. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6103. return false;
  6104. }
  6105. // }
  6106. for (i=0; i<files.length; i++) {
  6107. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6108. alert('" . $error_files_exists . "');
  6109. return false;
  6110. }
  6111. }
  6112. docFormOnLineEditor.submit();
  6113. return true;
  6114. }
  6115. //]]>
  6116. </script>\n";
  6117. $output .= "
  6118. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6119. $output .= $OUTPUT->box_start();
  6120. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6121. $output .= "
  6122. <table width='100%' cellpadding='20'>
  6123. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6124. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6125. </tr>
  6126. </table>\n";
  6127. $output .= $OUTPUT->box_end();
  6128. $output .= "<center>\n";
  6129. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6130. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6131. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6132. $output .= $output_ilm;
  6133. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6134. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6135. </center>
  6136. </form>\n";
  6137. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6138. $PAGE->navbar->add($title);
  6139. $PAGE->set_title($title);
  6140. $PAGE->set_heading($title); // insert title above the navigation bar
  6141. print $OUTPUT->header();
  6142. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6143. print $output;
  6144. print $OUTPUT->footer();
  6145. }
  6146. die();
  6147. } // function ilm_editor_new()
  6148. /// Function for editing an file in online editor
  6149. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6150. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6151. global $CFG, $DB, $OUTPUT, $PAGE;
  6152. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6153. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6154. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6155. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6156. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6157. // If iLM is not registered, error!
  6158. if (!$iassign) {
  6159. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6160. die;
  6161. }
  6162. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6163. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6164. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6165. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6166. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6167. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6168. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6169. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6170. if ($stringArchiveContent != NULL) {
  6171. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6172. die();
  6173. } else { // if ($stringArchiveContent != NULL)
  6174. $end_file = '';
  6175. if ($content_file) {
  6176. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6177. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6178. }
  6179. $temp = explode(",", $iassign->extension);
  6180. $extension = $temp[0]; // default extension for this iLM
  6181. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6182. $str_get_iLM = "window.frames.iLM";
  6183. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6184. } else { // otherwise it is JAR named 'iLM'
  6185. $str_get_iLM = "document.iLM";
  6186. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6187. }
  6188. $output = "<script type='text/javascript'>
  6189. //<![CDATA[
  6190. function submit_iLM_Answer () {
  6191. var docFormEditor = document.formEnvio;
  6192. var activityAnswer; // to get activity answer (text)
  6193. var activityValue; // to get activity answer value (float)
  6194. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6195. //activityAnswer = doc_iLM.getAnswer();
  6196. //activityValue = doc_iLM.getEvaluation();
  6197. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6198. activityValue = " . $str_get_iLM . ".getEvaluation();
  6199. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6200. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6201. docFormEditor.submit();
  6202. return true;
  6203. }
  6204. //]]>
  6205. </script>\n";
  6206. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6207. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6208. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6209. // return true;
  6210. // }
  6211. $output .= "
  6212. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6213. $output .= $OUTPUT->box_start();
  6214. $output .= "
  6215. <table width='100%' cellpadding='20'>
  6216. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6217. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6218. <input type='hidden' name='filename' value='$filename'/></td>
  6219. <td>
  6220. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6221. </tr>
  6222. </table>\n";
  6223. $output .= $OUTPUT->box_end();
  6224. $output .= " <center>\n";
  6225. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6226. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6227. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6228. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6229. </center>
  6230. </form>\n";
  6231. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6232. $PAGE->navbar->add($title);
  6233. $PAGE->set_title($title);
  6234. $PAGE->set_heading($title); // insert title above the navigation bar
  6235. print $OUTPUT->header();
  6236. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6237. print $output;
  6238. print $OUTPUT->footer();
  6239. } // else if ($stringArchiveContent != NULL)
  6240. die();
  6241. } // function ilm_editor_update()
  6242. /// Function for write iAssign file in Moodle data (exercise)
  6243. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6244. // @param string $stringArchiveContent Content of iassign file
  6245. // @param string $filename Filename of iassign file
  6246. function write_file_iassign ($stringArchiveContent, $filename) {
  6247. global $USER;
  6248. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6249. $context = context_course::instance($this->id);
  6250. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6251. $dirid = $this->get_dir_ilm('dirid');
  6252. $dir = $fs->get_file_by_id($dirid);
  6253. $fileinfo = array('contextid' => $context->id, // ID of course
  6254. 'component' => 'mod_iassign', // usually = table name
  6255. 'filearea' => 'activity', // usually = table name
  6256. 'itemid' => 0, // usually = ID of row in table
  6257. 'filepath' => '/', // any path beginning and ending whith '/'
  6258. 'userid' => $USER->id,
  6259. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6260. 'filename' => $filename); // any filename
  6261. // Create file containing text. '$stringArchiveContent'
  6262. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6263. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6264. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6265. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6266. // 'Activité interactive enregistrée avec succès sous le nom:';
  6267. // 'Atividade interativa gravada com sucesso sob o nome:'
  6268. $output = "
  6269. <script type='text/javascript'>
  6270. //<![CDATA[
  6271. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6272. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6273. //]]>
  6274. </script>";
  6275. print $output;
  6276. die();
  6277. }
  6278. /// Function for write iAssign file in Moodle data (exercise)
  6279. // @param string $stringArchiveContent Content of iassign file
  6280. // @param string $filename Filename of iassign file
  6281. // @param int $itemid Itemid of iassign file
  6282. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6283. global $OUTPUT, $USER;
  6284. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6285. $context = context_course::instance($this->id);
  6286. $dirid = $this->get_dir_ilm('dirid');
  6287. if ($stringArchiveContent != (-1)) {
  6288. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6289. $file = $fs->get_file_by_id($fileid);
  6290. if (!$file) {
  6291. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6292. die;
  6293. }
  6294. $fileinfo = array('contextid' => $context->id, // ID of context
  6295. 'component' => 'mod_iassign', // usually = table name
  6296. 'filearea' => 'activity', // usually = table name
  6297. 'itemid' => 0, // usually = ID of row in table
  6298. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6299. 'userid' => $USER->id,
  6300. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6301. 'license' => 'allrightsreserved', // allrightsreserved
  6302. 'timecreated' => $file->get_timecreated(),
  6303. 'filename' => $file->get_filename()); // any filename
  6304. $file->delete();
  6305. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6306. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6307. }
  6308. $output = "<script type='text/javascript'>
  6309. //<![CDATA[
  6310. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6311. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6312. //]]>
  6313. </script>";
  6314. print $output;
  6315. die();
  6316. }
  6317. /// Function for create an tag for iAssign filter
  6318. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6319. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6320. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6321. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6322. // @param int $fileid Id of file
  6323. // @return string Return an string with an tag of iassign filter
  6324. function tag_ilm ($fileid) {
  6325. global $DB;
  6326. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6327. $width = '600';
  6328. $height = '400';
  6329. $file = $fs->get_file_by_id($fileid);
  6330. $filetype = explode(".", $file->get_filename());
  6331. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6332. foreach ($iassign_ilm as $value) {
  6333. $extensions = explode(",", $value->extension);
  6334. if (in_array($filetype[1], $extensions)) {
  6335. $width = $value->width;
  6336. $height = $value->height;
  6337. }
  6338. }
  6339. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6340. }
  6341. /// Function for delete iAssign file in Moodle data (exercise)
  6342. function delete_file_ilm () {
  6343. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6344. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6345. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6346. $file = $fs->get_file_by_id($fileid);
  6347. if ($file)
  6348. $file->delete();
  6349. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6350. die();
  6351. }
  6352. /// Function for delete selected iAssign file in Moodle data (exercise)
  6353. function delete_selected_ilm () {
  6354. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6355. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6356. $context = context_course::instance($this->id);
  6357. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6358. $dirid = $this->get_dir_ilm('dirid');
  6359. foreach ($files_id as $file_id) {
  6360. $file = $fs->get_file_by_id($file_id);
  6361. if ($file) {
  6362. if (!$file->is_directory())
  6363. $file->delete();
  6364. else {
  6365. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6366. foreach ($files_delete as $value)
  6367. $value->delete();
  6368. $file->delete();
  6369. }
  6370. }
  6371. }
  6372. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6373. die();
  6374. }
  6375. /// Function for duplicate iAssign file from "online" edition
  6376. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6377. function duplicate_file_ilm () {
  6378. global $USER, $COURSE;
  6379. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6380. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6381. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6382. $filename = optional_param('filename', NULL, PARAM_RAW);
  6383. $file = $fs->get_file_by_id($fileid);
  6384. $context = context_course::instance($this->id);
  6385. $fileinfo = array(
  6386. 'contextid' => $context->id, // ID of context
  6387. 'component' => 'mod_iassign', // usually = table name
  6388. 'filearea' => 'activity', // usually = table name
  6389. 'itemid' => 0, // usually = ID of row in table
  6390. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6391. 'userid' => $USER->id,
  6392. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6393. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6394. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6395. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6396. die();
  6397. }
  6398. /// Function for rename iAssign file
  6399. function rename_file_ilm () {
  6400. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6401. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6402. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6403. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6404. $file = $fs->get_file_by_id($fileid);
  6405. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6406. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6407. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6408. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6409. die();
  6410. }
  6411. /// Function for get iassign file for iassign form
  6412. function add_ilm () {
  6413. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6414. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6415. $output = "
  6416. <script type='text/javascript'>
  6417. //<![CDATA[
  6418. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6419. iassign_file_link.innerHTML = '$filename';
  6420. window.opener.document.forms['mform1'].file.value='$fileid';
  6421. window.opener.document.forms['mform1'].filename.value='$filename';
  6422. window.close();
  6423. //]]>
  6424. </script>";
  6425. print $output;
  6426. die();
  6427. }
  6428. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6429. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6430. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6431. function preview_ilm ($courseid, $iassign_ilm) {
  6432. global $OUTPUT, $CFG, $USER;
  6433. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6434. $title = get_string('modulename', 'iassign'); // iAssign
  6435. print $OUTPUT->header();
  6436. print $OUTPUT->box_start();
  6437. $javascript = "
  6438. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6439. <script type='text/javascript'>
  6440. //<![CDATA[
  6441. function submit_close () {
  6442. window.opener.location.reload();
  6443. window.close();
  6444. }
  6445. //]]>
  6446. </script>\n";
  6447. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6448. // to the complete "applet" tag
  6449. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6450. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6451. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6452. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6453. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6454. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6455. if ($ilm_name != "ivprog") {
  6456. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6457. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6458. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6459. } else {
  6460. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6461. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6462. $timecreated = time();
  6463. $token = md5($timecreated);
  6464. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6465. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6466. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6467. $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)
  6468. }
  6469. $html = "
  6470. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6471. <table border='1'>
  6472. <tr><td>
  6473. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6474. <!-- iLM calls : end -->
  6475. </td></tr>
  6476. </table>
  6477. <table>
  6478. <tr>
  6479. <td align='center'>
  6480. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6481. </td></tr>
  6482. </table>
  6483. </form>\n";
  6484. print $javascript . $html;
  6485. print $OUTPUT->box_end();
  6486. //NAO echo format_string($html); // Moodle 3.X
  6487. die();
  6488. } // function preview_ilm($courseid, $iassign_ilm)
  6489. //r_ function preview_ilm ($iassign_ilm)
  6490. //r_ /// Function for preview iassign file from iassign filter.
  6491. //r_ function preview_ilm() {
  6492. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6493. //r_ $tag_filter = $this->tag_ilm($fileid);
  6494. //r_ $javascript = "<script type='text/javascript'>
  6495. //r_ //<![CDATA[
  6496. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6497. //r_ //]]>
  6498. //r_ </script>";
  6499. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6500. //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>
  6501. //r_ </table></form></body></html>";
  6502. //r_ echo $javascript . format_text($html);
  6503. //r_ die;
  6504. //r_ }
  6505. /// Function for export an package (zip) of iassign files
  6506. function export_files_ilm () {
  6507. global $CFG;
  6508. $context = context_course::instance($this->id);
  6509. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6510. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6511. $zip = new zip_archive();
  6512. $zip->open($zip_filename);
  6513. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6514. foreach ($files_id as $file_id) {
  6515. $file = $fs->get_file_by_id($file_id);
  6516. if (!$file->is_directory())
  6517. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6518. else {
  6519. $zip->add_directory($file->get_filepath());
  6520. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6521. foreach ($files_zip as $value) {
  6522. if (!$value->is_directory())
  6523. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6524. else
  6525. $zip->add_directory($value->get_filepath());
  6526. }
  6527. }
  6528. }
  6529. $zip->close();
  6530. header("Pragma: public");
  6531. header("Expires: 0");
  6532. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6533. header("Cache-Control: private", false);
  6534. header("Content-Type: application/zip");
  6535. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6536. header("Content-Transfer-Encoding: binary");
  6537. header("Content-Length: " . @filesize($zip_filename));
  6538. set_time_limit(0);
  6539. @readfile("$zip_filename") || die("File not found.");
  6540. unlink($zip_filename);
  6541. exit;
  6542. }
  6543. /// Function of execute a command in button editor tinymce
  6544. // @param int $fileid Id of file
  6545. function tinymce_ilm ($fileid) {
  6546. $tag_filter = $this->tag_ilm($fileid);
  6547. $output = "<script type='text/javascript'>
  6548. //<![CDATA[
  6549. var tag_filter = '$tag_filter';
  6550. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6551. // all right, insert it
  6552. } else {
  6553. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6554. }
  6555. // window.close();
  6556. //]]>
  6557. </script>\n";
  6558. print $output;
  6559. die();
  6560. }
  6561. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6562. /// Function to add content to the Editor Window
  6563. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6564. // @param int $fileid Id of file
  6565. function editor_ilm ($fileid, $editor) {
  6566. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6567. $output1 = "<script type='text/javascript'>
  6568. //<![CDATA[
  6569. var tag_filter = '$tag_filter';\n";
  6570. if ($editor == 'atto') {
  6571. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6572. } elseif ($editor == 'tinyMCE') {
  6573. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6574. } else
  6575. $output2 = "";
  6576. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6577. window.close();
  6578. //]]>
  6579. </script>\n";
  6580. //D var_dump($output);
  6581. print $output1 . $output2 . $output3;
  6582. die();
  6583. }
  6584. /// Function to add content to the Atto Editor Window
  6585. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6586. // @param int $fileid Id of file
  6587. function atto_ilm ($fileid) {
  6588. global $CFG, $DB;
  6589. $tag_filter = $this->tag_ilm($fileid);
  6590. $output = "<script type='text/javascript'>
  6591. //<![CDATA[
  6592. var tag_filter = '$tag_filter';
  6593. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6594. // all right, insert iLM tag to this editor
  6595. } else {
  6596. // error trying to insert
  6597. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6598. }
  6599. //window.close();
  6600. //]]>
  6601. </script>\n";
  6602. print $output;
  6603. die();
  6604. }
  6605. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6606. // @param string $key Key for return information
  6607. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6608. function get_dir_ilm ($key) {
  6609. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6610. $context = context_course::instance($this->id);
  6611. $dirid = optional_param('dirid', 0, PARAM_INT);
  6612. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6613. if ($dirid == 0) {
  6614. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6615. $dirid = $dir->get_id();
  6616. }
  6617. else {
  6618. $dir = $fs->get_file_by_id($dirid);
  6619. $dir_base = $dir->get_filepath();
  6620. }
  6621. $dir_parent = $dir->get_parent_directory();
  6622. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6623. return $data[$key];
  6624. }
  6625. /// Function for create an new dir
  6626. function new_dir_ilm () {
  6627. global $USER;
  6628. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6629. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6630. $dir_base = $this->get_dir_ilm('dir_base');
  6631. $context = context_course::instance($this->id);
  6632. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6633. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6634. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6635. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6636. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6637. }
  6638. /// Function for delete an dir
  6639. function delete_dir_ilm () { //
  6640. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6641. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6642. $context = context_course::instance($this->id);
  6643. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6644. $dir_parent = $this->get_dir_ilm('dir_parent');
  6645. if ($dir) {
  6646. if ($dir->is_directory()) {
  6647. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6648. foreach ($files_delete as $value)
  6649. $value->delete();
  6650. $dir->delete();
  6651. }
  6652. }
  6653. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6654. die();
  6655. }
  6656. /// Function for rename an dir
  6657. function rename_dir_ilm () {
  6658. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6659. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6660. $context = context_course::instance($this->id);
  6661. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6662. $dir_parent = $this->get_dir_ilm('dir_parent');
  6663. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6664. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6665. if ($dir->is_directory()) {
  6666. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6667. foreach ($files_rename_path as $value)
  6668. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6669. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6670. }
  6671. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6672. die();
  6673. }
  6674. /// Function for move an dir and your content for other dir
  6675. function selected_move_ilm () {
  6676. global $PAGE, $OUTPUT, $CFG;
  6677. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6678. $context = context_course::instance($this->id);
  6679. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6680. $dirid = $this->get_dir_ilm('dirid');
  6681. $dir_base = $this->get_dir_ilm('dir_base');
  6682. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6683. $code_javascript_ilm = "
  6684. <script type='text/javascript'>
  6685. //<![CDATA[
  6686. function getRadiobutton () {
  6687. var radioButtons = document.getElementsByTagName('input');
  6688. var param = '';
  6689. for (var counter=0; counter < radioButtons.length; counter++) {
  6690. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6691. param = radioButtons[counter].value;
  6692. }
  6693. return param;
  6694. }
  6695. function move_selected_ilm () {
  6696. var msgAnswer;
  6697. if (getRadiobutton() != '') {
  6698. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6699. if (msgAnswer)
  6700. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6701. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6702. }
  6703. else
  6704. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6705. }
  6706. function cancel_selected_ilm () {
  6707. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6708. }
  6709. //]]>
  6710. </script>\n";
  6711. $title = get_string('move_files', 'iassign');
  6712. $PAGE->set_title($title);
  6713. $PAGE->set_pagelayout('base');
  6714. print $OUTPUT->header();
  6715. print $OUTPUT->heading($title);
  6716. $dir_paths = array();
  6717. print $OUTPUT->box_start();
  6718. print "<center>";
  6719. foreach ($files_id as $file_id) {
  6720. $file = $fs->get_file_by_id($file_id);
  6721. if ($file) {
  6722. if (!$file->is_directory())
  6723. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6724. else {
  6725. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6726. array_push($dir_paths, $file->get_filepath());
  6727. }
  6728. }
  6729. }
  6730. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6731. if ($dir_base != '/') {
  6732. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6733. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6734. }
  6735. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6736. foreach ($files_tree as $file) {
  6737. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6738. $is_parent = false;
  6739. foreach ($dir_paths as $dir) {
  6740. $path = explode("/", $dir);
  6741. array_pop($path);
  6742. $path[count($path) - 1] = '';
  6743. $path = implode("/", $path);
  6744. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6745. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6746. }
  6747. if ($is_parent == false) {
  6748. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6749. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6750. }
  6751. }
  6752. }
  6753. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6754. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6755. print "</center>";
  6756. print $OUTPUT->box_end();
  6757. print $OUTPUT->footer();
  6758. print $code_javascript_ilm;
  6759. die;
  6760. }
  6761. /// Function for move files for an dir
  6762. function move_files_ilm () {
  6763. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6764. $context = context_course::instance($this->id);
  6765. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6766. $dirid = $this->get_dir_ilm('dirid');
  6767. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6768. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6769. foreach ($files_id as $file_id) {
  6770. $file = $fs->get_file_by_id($file_id);
  6771. if ($file) {
  6772. if ($file->is_directory()) {
  6773. $pathname = explode("/", $file->get_filepath());
  6774. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6775. foreach ($files_move_path as $value) {
  6776. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6777. $value->rename($path_move, $value->get_filename());
  6778. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6779. }
  6780. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6781. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6782. $file->rename($path_move, $file->get_filename());
  6783. } else {
  6784. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6785. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6786. }
  6787. }
  6788. }
  6789. //die;
  6790. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6791. die();
  6792. } // function move_files_ilm()
  6793. /// Function for recover files in use on all activities of a course
  6794. function recover_files_ilm () {
  6795. global $DB, $USER;
  6796. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6797. $courseid = optional_param('id', NULL, PARAM_INT);
  6798. $dirid = $this->get_dir_ilm('dirid');
  6799. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6800. $contextfile = context_course::instance($this->id);
  6801. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6802. foreach ($iassigns as $iassign) {
  6803. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6804. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6805. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6806. $context = context_module::instance($cm->id);
  6807. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6808. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6809. if ($files) {
  6810. foreach ($files as $value) {
  6811. $extension = explode(".", $value->get_filename());
  6812. if (!$value->is_directory()) {
  6813. $fileinfo = array('contextid' => $contextfile->id,
  6814. 'component' => 'mod_iassign',
  6815. 'filearea' => 'activity',
  6816. 'itemid' => 0,
  6817. 'filepath' => $this->get_dir_ilm('dir_base'),
  6818. 'userid' => $USER->id,
  6819. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6820. 'license' => 'allrightsreserved',
  6821. 'timecreated' => time(),
  6822. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6823. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6824. }
  6825. }
  6826. } // if ($files)
  6827. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6828. } // foreach ($iassigns as $iassign)
  6829. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6830. die();
  6831. } // function recover_files_ilm()
  6832. /// Auxiliary function the get all files in a given context
  6833. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6834. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6835. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6836. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6837. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6838. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6839. // (NAO s_iassign_statement.file = s_files.id)
  6840. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6841. $dir_base = $this->get_dir_ilm('dir_base');
  6842. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6843. $countf = 0;
  6844. $array_files_id = array(); // all files from this context
  6845. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6846. //$filename = $item_fc->get_filename();
  6847. //$filepath = $item_fc->get_filepath();
  6848. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6849. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6850. // $array_files_aux[] = $item_fc;
  6851. $itemid = $item_fc->get_id();
  6852. if (!in_array($itemid, $array_files_id)) {
  6853. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6854. if ($fileuserid == $userid)
  6855. $filesfrommine[] = $item_fc;
  6856. else
  6857. $filesfromothers[] = $item_fc;
  6858. $array_files_id[] = $itemid;
  6859. $countf++;
  6860. }
  6861. }
  6862. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6863. return $countf;
  6864. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6865. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6866. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6867. function get_all_ilm_files_by_fileid ($fileid) {
  6868. global $DB, $USER;
  6869. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6870. //TODO Criar coluna 'authorid'
  6871. $str_query = "SELECT * FROM {iassign_statement} WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6872. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6873. return $array_iassign_ilm;
  6874. }
  6875. //NN
  6876. //NN
  6877. // Build string with JavaScript code with function to edit/remove/double iLM files
  6878. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6879. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6880. global $CFG;
  6881. $error_files_exists = get_string('error_file_exists', 'iassign');
  6882. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6883. $code_javascript_ilm = "
  6884. <script type='text/javascript'>
  6885. //<![CDATA[
  6886. function preview_ilm (fileid, ilmid) { //JavaScript function
  6887. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6888. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6889. }
  6890. function update_ilm (ilmid, fileid) { //JavaScript function
  6891. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6892. }
  6893. function delete_ilm (ilmid, fileid) { //JavaScript function
  6894. var msgAnswer;
  6895. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6896. if (msgAnswer) {
  6897. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6898. }
  6899. }
  6900. function delete_selected_ilm () { //JavaScript function
  6901. var msgAnswer;
  6902. var param = getCheckbox();
  6903. if (param.join() != '') {
  6904. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6905. if (msgAnswer)
  6906. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6907. }
  6908. else
  6909. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6910. }
  6911. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6912. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6913. }
  6914. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6915. var filenamecopy;
  6916. var i;
  6917. var files = new Array(" . $files_array . ");
  6918. do {
  6919. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6920. } while (filenamecopy == '');
  6921. if (filenamecopy == null)
  6922. return false;\n
  6923. else {
  6924. for (i=0;i<files.length;i++) {
  6925. if (files[i]==filenamecopy) {
  6926. alert('" . $error_files_exists . "');
  6927. return false;\n
  6928. }
  6929. }\n" .
  6930. // @see: function 'duplicate_file_ilm()' above
  6931. "
  6932. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6933. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6934. } // else
  6935. }
  6936. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6937. var filenamecopy;
  6938. var i;
  6939. var files = new Array($files_array);
  6940. do {
  6941. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6942. } while (filenamecopy == '');
  6943. if (filenamecopy == null)
  6944. return false;
  6945. else {
  6946. for (i=0;i<files.length;i++) {
  6947. if (files[i]==filenamecopy) {
  6948. alert('" . $error_files_exists . "');
  6949. return false;
  6950. }
  6951. }
  6952. 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;
  6953. }
  6954. }
  6955. function export_files_ilm () { //JavaScript function
  6956. var param = getCheckbox();
  6957. if (param.join() != '')
  6958. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6959. else
  6960. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6961. }
  6962. function select_all_ilm () { //JavaScript function
  6963. var checkBoxes = document.getElementsByTagName('input');
  6964. var selectAll = document.getElementById('select_all');
  6965. for (var counter=0; counter < checkBoxes.length; counter++) {
  6966. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6967. checkBoxes[counter].checked = selectAll.checked;
  6968. }
  6969. }
  6970. function getCheckbox () { //JavaScript function
  6971. var checkBoxes = document.getElementsByTagName('input');
  6972. var param = new Array();
  6973. for (var counter=0; counter < checkBoxes.length; counter++) {
  6974. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6975. param.push(checkBoxes[counter].value);
  6976. }
  6977. return param;
  6978. }
  6979. function new_dir_ilm () { //JavaScript function
  6980. var dirname = '';
  6981. var i;
  6982. var dirs = new Array(" . $dirs_array . ");
  6983. do {
  6984. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6985. } while (dirname == '');
  6986. if (dirname == null)
  6987. return false;\n
  6988. else {
  6989. for (i=0;i<dirs.length;i++) {
  6990. if (dirs[i]==dirname) {
  6991. alert('" . $error_dir_exists . "');
  6992. return false;\n
  6993. }
  6994. }
  6995. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6996. }
  6997. }
  6998. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6999. var msgAnswer;
  7000. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7001. if (msgAnswer) {
  7002. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7003. }
  7004. }
  7005. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  7006. var dirnamecopy;
  7007. var i;
  7008. var dirs = new Array($dirs_array);
  7009. do {
  7010. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7011. } while (dirnamecopy == '');
  7012. if (dirnamecopy == null)
  7013. return false;\n
  7014. else {
  7015. for (i=0;i<dirs.length;i++) {
  7016. if (dirs[i]==dirnamecopy) {
  7017. alert('" . $error_dir_exists . "');
  7018. return false;\n
  7019. }
  7020. }
  7021. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7022. }
  7023. }
  7024. function move_selected_ilm (ilmid) { //JavaScript function
  7025. var param = getCheckbox();
  7026. if (param.join() != '')
  7027. 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();
  7028. else
  7029. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7030. }
  7031. function recover_files_ilm () { //JavaScript function
  7032. var msgAnswer;
  7033. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7034. if (msgAnswer) {
  7035. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7036. }
  7037. }
  7038. window.onload = function() { //JavaScript function
  7039. var xPosition = 0;
  7040. var yPosition = 0;
  7041. element=document.getElementById('new_file');
  7042. while(element) {
  7043. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7044. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7045. element = element.offsetParent;
  7046. }
  7047. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7048. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7049. location.hash = '#new_file';
  7050. };
  7051. //]]>
  7052. </script>\n"; // end of $code_javascript_ilm
  7053. return $code_javascript_ilm;
  7054. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7055. /// List iassign files from course directory
  7056. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7057. function view_files_ilm ($iassign_ilm_class, $extension) {
  7058. global $CFG, $DB, $USER, $OUTPUT;
  7059. $fs = get_file_storage();
  7060. $context = context_course::instance($this->id);
  7061. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7062. $dirid = $this->get_dir_ilm('dirid');
  7063. $dir_base = $this->get_dir_ilm('dir_base');
  7064. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7065. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7066. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7067. $files_array = '';
  7068. foreach ($files_course as $value) {
  7069. if (!$value->is_directory())
  7070. $files_array .= "'" . $value->get_filename() . "',";
  7071. }
  7072. $files_array .= "''";
  7073. $error_files_exists = get_string('error_file_exists', 'iassign');
  7074. $dirs_array = '';
  7075. foreach ($files_course as $value) {
  7076. if ($value->is_directory()) {
  7077. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7078. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7079. }
  7080. }
  7081. $dirs_array .= "''";
  7082. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7083. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7084. $code_javascript_ilm = "
  7085. <script type='text/javascript'>
  7086. //<![CDATA[
  7087. function preview_ilm (fileid, ilmid) {
  7088. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7089. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7090. }
  7091. function update_ilm (ilmid, fileid) {
  7092. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7093. }
  7094. function delete_ilm (ilmid, fileid) {
  7095. var msgAnswer;
  7096. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7097. if (msgAnswer) {
  7098. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7099. }
  7100. }
  7101. function delete_selected_ilm () {
  7102. var msgAnswer;
  7103. var param = getCheckbox();
  7104. if (param.join() != '') {
  7105. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7106. if (msgAnswer)
  7107. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7108. }
  7109. else
  7110. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7111. }
  7112. function add_ilm_iassign (ilmid, filename, fileid) {
  7113. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7114. }
  7115. function duplicate_ilm (ilmid, filename, fileid) {
  7116. var filenamecopy;
  7117. var i;
  7118. var files = new Array($files_array);
  7119. do {
  7120. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7121. } while (filenamecopy == '');
  7122. if (filenamecopy == null)
  7123. return false;\n
  7124. else {
  7125. for (i=0;i<files.length;i++) {
  7126. if (files[i]==filenamecopy) {
  7127. alert('$error_files_exists');
  7128. return false;\n
  7129. }
  7130. }\n" .
  7131. // @see: function 'duplicate_file_ilm()' above
  7132. "
  7133. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7134. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7135. } // else
  7136. }
  7137. function rename_ilm (ilmid, filename, fileid) {
  7138. var filenamecopy;
  7139. var i;
  7140. var files = new Array($files_array);
  7141. do {
  7142. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7143. } while (filenamecopy == '');
  7144. if (filenamecopy == null)
  7145. return false;
  7146. else {
  7147. for (i=0;i<files.length;i++) {
  7148. if (files[i]==filenamecopy) {
  7149. alert('$error_files_exists');
  7150. return false;
  7151. }
  7152. }
  7153. 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;
  7154. }
  7155. }
  7156. function export_files_ilm () {
  7157. var param = getCheckbox();
  7158. if (param.join() != '')
  7159. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7160. else
  7161. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7162. }
  7163. function select_all_ilm () {
  7164. var checkBoxes = document.getElementsByTagName('input');
  7165. var selectAll = document.getElementById('select_all');
  7166. for (var counter=0; counter < checkBoxes.length; counter++) {
  7167. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7168. checkBoxes[counter].checked = selectAll.checked;
  7169. }
  7170. }
  7171. function getCheckbox () {
  7172. var checkBoxes = document.getElementsByTagName('input');
  7173. var param = new Array();
  7174. for (var counter=0; counter < checkBoxes.length; counter++) {
  7175. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7176. param.push(checkBoxes[counter].value);
  7177. }
  7178. return param;
  7179. }
  7180. function new_dir_ilm () {
  7181. var dirname = '';
  7182. var i;
  7183. var dirs = new Array($dirs_array);
  7184. do {
  7185. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7186. } while (dirname == '');
  7187. if (dirname == null)
  7188. return false;\n
  7189. else {
  7190. for (i=0;i<dirs.length;i++) {
  7191. if (dirs[i]==dirname) {
  7192. alert('$error_dir_exists');
  7193. return false;\n
  7194. }
  7195. }
  7196. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7197. }
  7198. }
  7199. function delete_dir_ilm (ilmid, dirid) {
  7200. var msgAnswer;
  7201. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7202. if (msgAnswer) {
  7203. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7204. }
  7205. }
  7206. function rename_dir_ilm (ilmid, dirname, dirid) {
  7207. var dirnamecopy;
  7208. var i;
  7209. var dirs = new Array($dirs_array);
  7210. do {
  7211. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7212. } while (dirnamecopy == '');
  7213. if (dirnamecopy == null)
  7214. return false;\n
  7215. else {
  7216. for (i=0;i<dirs.length;i++) {
  7217. if (dirs[i]==dirnamecopy) {
  7218. alert('$error_dir_exists');
  7219. return false;\n
  7220. }
  7221. }
  7222. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7223. }
  7224. }
  7225. function move_selected_ilm (ilmid) {
  7226. var param = getCheckbox();
  7227. if (param.join() != '')
  7228. 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();
  7229. else
  7230. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7231. }
  7232. function recover_files_ilm () {
  7233. var msgAnswer;
  7234. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7235. if (msgAnswer) {
  7236. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7237. }
  7238. }
  7239. window.onload = function() {
  7240. var xPosition = 0;
  7241. var yPosition = 0;
  7242. element=document.getElementById('new_file');
  7243. while(element) {
  7244. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7245. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7246. element = element.offsetParent;
  7247. }
  7248. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7249. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7250. location.hash = '#new_file';
  7251. };
  7252. //]]>
  7253. </script>\n";
  7254. $output = "";
  7255. $select_all = "";
  7256. $count_files = 0;
  7257. $extensions_allow = array();
  7258. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7259. foreach ($iassign_ilm as $item_iassign_ilm)
  7260. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7261. foreach ($files_course as $value) {
  7262. $filename = $value->get_filename();
  7263. $filepath = $value->get_filepath();
  7264. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7265. $pathname = $pathname[count($pathname) - 1];
  7266. $fileid = $value->get_id();
  7267. $tmp = explode(".", $filename);
  7268. if (count($tmp)>1) // avoid error if the file has no extension
  7269. $filetype = $tmp[1];
  7270. else // probably error...
  7271. $filetype = '';
  7272. $author = $value->get_author();
  7273. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7274. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7275. $extensions = explode(",", $extension);
  7276. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7277. $count_files++;
  7278. // buscar fileid nas tabelas do iassign
  7279. $list_filein_use = "";
  7280. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7281. if ($iassign_statement_activity_list) {
  7282. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7283. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7284. }
  7285. }
  7286. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7287. if (!$iassign_ilm) {
  7288. $iassign_ilm = new stdClass();
  7289. $iassign_ilm->id = $ilmid;
  7290. }
  7291. // Do not use $var inside "..." - problem with some "unusual" operational system
  7292. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7293. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7294. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7295. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7296. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7297. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7298. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7299. $check_select = "";
  7300. $link_rename = "";
  7301. $link_delete = "";
  7302. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7303. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7304. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7305. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7306. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7307. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7308. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7309. if ($value->get_userid() == $USER->id) {
  7310. if ($iassign_statement_activity_list) {
  7311. $check_select = "";
  7312. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7313. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7314. $link_rename = "";
  7315. } else {
  7316. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7317. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7318. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7319. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7320. }
  7321. }
  7322. if (!in_array($filetype, $extensions_allow)) {
  7323. $link_edit = "";
  7324. $link_add_ilm_iassign = "";
  7325. $link_add_ilm_tinymce = "";
  7326. $link_add_ilm_atto = "";
  7327. $link_filter = "";
  7328. }
  7329. if ($value->is_directory()) {
  7330. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7331. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7332. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7333. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7334. <td><center>$author</center></td>
  7335. <td><center>$timecreated</center></td>
  7336. <td><center>$timemodified</center></td></tr>\n";
  7337. }
  7338. else if ($this->from == 'iassign') {
  7339. $new_id = "";
  7340. $new_class = "";
  7341. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7342. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7343. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7344. }
  7345. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7346. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7347. <td><center>$author</center></td>
  7348. <td><center>$timecreated</center></td>
  7349. <td><center>$timemodified</center></td></tr>\n";
  7350. }
  7351. else if ($this->from == 'block') {
  7352. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7353. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7354. <td><center>$author</center></td>
  7355. <td><center>$timecreated</center></td>
  7356. <td><center>$timemodified</center></td></tr>\n";
  7357. }
  7358. else if ($this->from == 'tinymce') {
  7359. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7360. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7361. <td><center>$author</center></td>
  7362. <td><center>$timecreated</center></td>
  7363. <td><center>$timemodified</center></td></tr>\n";
  7364. }
  7365. else if ($this->from == 'atto') {
  7366. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7367. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7368. <td><center>$author</center></td>
  7369. <td><center>$timecreated</center></td>
  7370. <td><center>$timemodified</center></td></tr>\n";
  7371. }
  7372. }
  7373. }
  7374. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7375. $dir_base = "";
  7376. $header = "";
  7377. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7378. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7379. foreach ($basename as $value) {
  7380. $dir_base .= $value . "/";
  7381. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7382. if ($dir_id) {
  7383. if ($value == "") {
  7384. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7385. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7386. } else {
  7387. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7388. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7389. }
  7390. }
  7391. } // foreach ($basename as $value)
  7392. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7393. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7394. $html .= "
  7395. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7396. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7397. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7398. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7399. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7400. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7401. </table>\n";
  7402. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7403. $html .= "<table width='100%'><tr>\n";
  7404. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7405. if ($count_files != 0) {
  7406. $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";
  7407. $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";
  7408. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7409. }
  7410. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7411. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7412. $html .= "</form>\n";
  7413. print $code_javascript_ilm;
  7414. print $html;
  7415. } // function view_files_ilm($extension)
  7416. } // class ilm_manager
  7417. /// Class to insert of icons
  7418. class iassign_icons {
  7419. static function insert ($icon) {
  7420. global $CFG;
  7421. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7422. return $string;
  7423. }
  7424. }
  7425. /// Class with util functions for plugin manage
  7426. class iassign_utils {
  7427. /// Function to return the filename extension
  7428. // @param string The $filename as an string
  7429. // @return string Return an string (last group after '.')
  7430. static function filename_extension ($filename) {
  7431. if ($filename == null || $filename == '') {
  7432. return null;
  7433. }
  7434. $itens = explode('.', $filename);
  7435. $num = count($itens);
  7436. if ($num < 2) {
  7437. return null;
  7438. }
  7439. return $itens[$num - 1];
  7440. }
  7441. /// Use the PHP class/package ZipArchive to create a Zip file
  7442. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7443. // 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
  7444. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7445. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7446. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7447. $zip = new zip_archive(); //2
  7448. $res = $zip->open($full_path_zip_filename);
  7449. $total_vet = count($vet_student_filename);
  7450. for ($ii=0; $ii<$total_vet; $ii++) {
  7451. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7452. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7453. }
  7454. $ret = $zip->close();
  7455. iassign_utils::download_file($full_path_zip_filename);
  7456. $filenameZip = $zip->filename;
  7457. return array($ret, $zip);
  7458. }
  7459. static function download_file ($zip_filename) {
  7460. header("Pragma: public");
  7461. header("Expires: 0");
  7462. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7463. header("Cache-Control: private", false);
  7464. header("Content-Type: application/zip");
  7465. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7466. header("Content-Transfer-Encoding: binary");
  7467. header("Content-Length: " . @filesize($zip_filename));
  7468. set_time_limit(0);
  7469. @readfile("$zip_filename") || die("File not found.");
  7470. unlink($zip_filename);
  7471. }
  7472. /// Function for format filename remove special caracters
  7473. // @param string $text String for clean
  7474. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7475. // @return string Return an string in clean format
  7476. static function format_filename ($text) {
  7477. if ($text != '.') {
  7478. //D $text = htmlspecialchars(urldecode($text));
  7479. //D echo "locallib.php: format_filename: $text<br/>";
  7480. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7481. $text = json_decode($text)->{current_language()};
  7482. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7483. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7484. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7485. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7486. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7487. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7488. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7489. // E.g. text = "exerc_midpoint.course.geo"
  7490. // 0123456789012345678901234
  7491. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7492. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7493. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7494. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7495. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7496. //$ext = strrpos($text, ".");
  7497. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7498. //$text = str_replace($array1, $array2, $text);
  7499. }
  7500. return $text;
  7501. }
  7502. /// Function to filter characters to the file name to iLM content
  7503. // @param string $text String for clean
  7504. // @param string $ext String ot the extension of the iLM
  7505. // @return string Return an string in clean format
  7506. static function filter_filename_extension ($filename, $ext) {
  7507. if ($filename != '.') {
  7508. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7509. $arrTo = array("_","","","","","","","","","","","","");
  7510. $filename = str_replace($arrFrom, $arrTo, $filename);
  7511. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7512. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7513. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7514. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7515. $index_lastposition = strlen($filenameF);
  7516. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7517. $text = str_replace(".", "_", $text); // erase all other "."
  7518. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7519. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7520. }
  7521. else
  7522. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7523. return $filenameF;
  7524. }
  7525. /// Function for format pathname remove special caracters
  7526. // @param string $text String for clean
  7527. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7528. // @return string Return an string in clean format
  7529. static function format_pathname ($text, $is_lowercase = true) {
  7530. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7531. $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", "-", "_", "", "", "");
  7532. $text = str_replace($array1, $array2, $text);
  7533. if ($is_lowercase)
  7534. $text = strtolower($text);
  7535. return $text;
  7536. }
  7537. /// Function for format file name from iLM original name
  7538. // @param string $text String to build the file neam
  7539. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7540. // @return string Return an string in clean format
  7541. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7542. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7543. $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", "-", "_", "", "", "");
  7544. $index_firstposition_blank = strpos($ilm_name, " ");
  7545. if ($index_firstposition_blank) { // truncate the name!
  7546. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7547. }
  7548. $index_firstposition_dots = strpos($ilm_name, ":");
  7549. if ($index_firstposition_dots) { // truncate the name!
  7550. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7551. }
  7552. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7553. if ($is_lowercase)
  7554. $namefiltered = strtolower($namefiltered);
  7555. return $namefiltered;
  7556. }
  7557. /// Function for insert version in the filename
  7558. // @param string $filename Name of file
  7559. // @return string Return the filename with version
  7560. static function version_filename ($filename) {
  7561. $array_filename = explode('.', $filename);
  7562. if (count($array_filename) > 1)
  7563. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7564. else
  7565. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7566. return $filename;
  7567. }
  7568. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7569. static function remove_code_message ($string) {
  7570. $array = explode("&lt;ia_uc&gt;", $string);
  7571. return $array[0];
  7572. }
  7573. }
  7574. // class iassign_utils
  7575. /// Class with language functions for plugin manage
  7576. class iassign_language {
  7577. /// Function for return text in language or get default language (en)
  7578. // @param string $lang Code of language
  7579. // @param string $description JSON text content all languages
  7580. // @return string Return an string in the language selected
  7581. static function get_description_lang ($lang, $descriptions) {
  7582. $description_lang = "";
  7583. $description = json_decode($descriptions);
  7584. if ($description == null) {
  7585. $description_lang = $descriptions;
  7586. }
  7587. else {
  7588. if (isset($description->{$lang}))
  7589. $description_lang = $description->{$lang};
  7590. else
  7591. if (isset($description->en)) //MOOC2014
  7592. $description_lang = $description->en;
  7593. else //MOOC2014
  7594. $description_lang = "en"; //MOOC2014
  7595. }
  7596. return $description_lang;
  7597. }
  7598. /// Function for return all language supported by iLM
  7599. // @param string $descriptions JSON text content all languages
  7600. // @return string Return as string with all languages
  7601. static function get_all_lang ($descriptions) {
  7602. $langs = "";
  7603. $description = json_decode($descriptions);
  7604. if ($description) {
  7605. foreach ($description as $key => $value) {
  7606. $langs .= $key . " ; ";
  7607. }
  7608. $langs = substr($langs, 0, strlen($langs) - 3);
  7609. }
  7610. return $langs;
  7611. }
  7612. /// Function for convert json in xml //MOOC2014
  7613. // @param string $json JSON text
  7614. // @return string Return as string with xml tags
  7615. static function json_to_xml ($json) {
  7616. $xml = "";
  7617. $json = json_decode($json);
  7618. foreach ($json as $key => $value) {
  7619. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7620. }
  7621. return $xml;
  7622. }
  7623. }
  7624. // class iassign_language
  7625. /// Class with log functions for plugin manage.
  7626. class iassign_log {
  7627. /// Function for insert log event
  7628. // @param string $action Code action of event
  7629. // @param string $information Text for describe action of event
  7630. // @param int $cmid Id of context module
  7631. // @param int $ilmid Id of iLM
  7632. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7633. global $COURSE, $CFG, $USER, $DB;
  7634. $newentry = new stdClass();
  7635. $newentry->time = time();
  7636. $newentry->userid = $USER->id;
  7637. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7638. $newentry->course = $COURSE->id;
  7639. $newentry->cmid = $cmid;
  7640. $newentry->ilmid = $ilmid;
  7641. $newentry->action = $action;
  7642. $newentry->info = $information;
  7643. $newentry->language = current_language();
  7644. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7645. if (ini_get("browscap") && function_exists('get_browse')) {
  7646. $browser = get_browse(null, true);
  7647. $newentry->javascript = $browser['javascript'];
  7648. $newentry->java = $browser['javaapplets'];
  7649. }
  7650. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7651. print_error('error_add_log', 'iassign');
  7652. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7653. } // class iassign_log