1
0

locallib.php 426 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.6 2022/01/21
  7. * + Try to fix view activity not sent through report ("view_iassign_current()": else if (!$student_answer) $loadTeacherActivity=true;)
  8. *
  9. * - v 4.9.5 2021/12/28
  10. * + Detail to fix order o activities inside a block ('iassign_statement.position' - old instalation could generate order error)
  11. *
  12. * - v 4.9.4 2020/05/28
  13. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  14. *
  15. * - v 4.9.3 2020/01/16
  16. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  17. *
  18. * - v 4.9.2 2019/03/13
  19. * + Several fixes to allow iLM under HTML stack
  20. *
  21. * - v 4.9.1 2017/11/02
  22. * + 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")
  23. * + 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)'
  24. *
  25. * - v 4.9 2017/03/13
  26. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  27. *
  28. * - v 4.8 2016/05/12
  29. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  30. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  31. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  32. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  33. * replaced by
  34. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  35. * - v 4.7 2016/02/17
  36. * + 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(...)')
  37. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  38. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  39. * + 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)
  40. * + 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'
  41. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  42. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  43. *
  44. * --------------- (code bellow was used at our MOOC 2014)
  45. * - v 4.6 2014/02/25
  46. * + Fix bugs in filter function for open applets.
  47. * - v 4.5 2014/02/24
  48. * + Fix bugs in params.
  49. * + Insert new param type.
  50. * - v 4.4 2014/01/24
  51. * + Allow select type of params.
  52. * + Insert the use of applet params specific for activities.
  53. * - v 4.3 2014/01/23
  54. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  55. * - v 4.2 2016/02/13
  56. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  57. * --------------- (above code used at our MOOC 2014)
  58. *
  59. * - v 4.1 2013/12/13
  60. * + Insert log in iAssign actions.
  61. * + 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).
  62. * + Insert class for Log actions in system.
  63. * - v 4.0 2013/10/31
  64. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  65. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  66. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  67. * - v 3.9 2013/10/25
  68. * + Insert support of upgrade iLM.
  69. * + Insert support for more than one extension in iLM.
  70. * + Fix bugs in verion control.
  71. * - v 3.8 2013/09/19
  72. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  73. * - v 3.7 2013/09/12
  74. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  75. * + 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).
  76. * - v 3.6 2013/09/05
  77. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  78. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  79. * + Change tag APPLET in function ilm_settings::view_ilm.
  80. * - v 3.5 2013/08/26
  81. * + Fix bug in download package iassign without answers (iassign::report).
  82. * - v 3.4 2013/08/23
  83. * + Fix bug in export package iassign.
  84. * - v 3.3 2013/08/22
  85. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  86. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  87. * - v 3.2 2013/08/21
  88. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  89. * + Change functions for import files for ilm_manager.php.
  90. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  91. * - v 3.1 2013/08/15
  92. * + Change return file selected (ilm_manager::add_ilm).
  93. * + 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).
  94. * - v 3.0 2013/08/02
  95. * + 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).
  96. * - v 2.9 2013/08/01
  97. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  98. * - v 2.8 2013/07/25
  99. * + Insert the activity name in header of view (activity::view_dates).
  100. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  101. * - v 2.7 2013/07/24
  102. * + Create link previous and next for student view in one activity (activity::view_dates).
  103. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  104. * - v 2.6 2013/07/23
  105. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  106. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  107. * - v 2.5 2013/07/12
  108. * + 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).
  109. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  110. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  111. *
  112. * @author Patricia Alves Rodrigues
  113. * @author Leônidas O. Brandão
  114. * @contributor Igor Moreira Félix (2018-)
  115. * @contributor Márcio de Lima Passos (2014)
  116. * @version v 4.9.2 2019/03/13
  117. * @version v 4.8 2016/05/12
  118. * @package mod_iassign_lib
  119. * @since 2010/09/27
  120. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  121. *
  122. * <b>License</b>
  123. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  124. */
  125. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  126. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  127. //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"'
  128. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  129. /**
  130. * Standard base class for all iAssign
  131. */
  132. class iassign {
  133. var $cm;
  134. var $course;
  135. var $iassign;
  136. var $striassign;
  137. var $striassigns;
  138. var $context;
  139. var $activity;
  140. var $iassign_up;
  141. var $iassign_down;
  142. var $action;
  143. var $iassign_submission_current;
  144. var $userid_iassign;
  145. var $bottonPost;
  146. var $write_solution;
  147. var $view_iassign;
  148. // 3.1 update PHP 7.0 compatibility for all moodle versions
  149. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  150. /// Constructor for the base iassign class
  151. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  152. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  153. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  154. function __construct ($iassign, $cm, $course) {
  155. global $COURSE, $CFG, $USER, $DB;
  156. $botton = optional_param('botton', NULL, PARAM_TEXT);
  157. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  158. if (!is_null($botton))
  159. $USER->iassignEdit = $botton;
  160. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  161. // 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'
  162. $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"
  163. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  164. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  165. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  166. $this->action = optional_param('action', NULL, PARAM_TEXT);
  167. $this->cm = $cm;
  168. $this->context = context_module::instance($this->cm->id);
  169. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  170. $this->userid_iassign = $USER->id;
  171. if ($course) {
  172. $this->course = $course;
  173. }
  174. else if ($this->cm->course == $COURSE->id) {
  175. $this->course = $COURSE;
  176. }
  177. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  178. print_error('invalidid', 'iassign');
  179. }
  180. $this->coursecontext = context_course::instance($this->course->id);
  181. if ($iassign) {
  182. $this->iassign = $iassign;
  183. }
  184. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  185. print_error('invalidid', 'iassign');
  186. }
  187. $USER->context = context_module::instance($this->cm->id);
  188. $USER->cm = $this->cm->id;
  189. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  190. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  191. $this->context = context_module::instance($this->cm->id);
  192. $this->striassign = get_string('modulename', 'iassign');
  193. $this->striassigns = get_string('modulenameplural', 'iassign');
  194. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  195. $this->bottonPost = 0;
  196. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  197. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  198. $this->view();
  199. } // function __construct($iassign, $cm, $course)
  200. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  201. // This method provides the page to view each iLM with any interactive activity
  202. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  203. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  204. global $USER, $DB, $OUTPUT;
  205. // $iassign_statementid = $this->iassign->iassign_statementid;
  206. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  207. $iassign_statementid = $this->activity->get_activity()->id;
  208. else
  209. $iassign_statementid = "";
  210. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  211. // If this user has no capability to View 'iassign': stop here
  212. require_capability('mod/iassign:view', $this->context);
  213. // Trigger module view event
  214. $event = \mod_iassign\event\course_module_viewed::create(array(
  215. 'objectid' => $this->iassign->id,
  216. 'context' => $this->context
  217. ));
  218. $event->add_record_snapshot('course', $this->course);
  219. $event->trigger();
  220. if ($this->action) { // when student do/redo activity or teacher see student solution
  221. $this->action(); // calls '$this->view_iLM();'
  222. }
  223. else {
  224. print $OUTPUT->header();
  225. $this->view_iassigns(); // show the iLM with the content
  226. print $OUTPUT->footer();
  227. }
  228. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  229. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  230. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  231. //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" }
  232. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  233. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  234. //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" }
  235. //D else echo "Apagou!<br/>";
  236. die();
  237. } // function view()
  238. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  239. function action () {
  240. global $USER;
  241. // action:
  242. // up - move up activity (mover atividade para cima)
  243. // down - move down activity (mover atividade para baixo)
  244. // visible - view/hide activity (exibir/ocultar atividade)
  245. // delete - delete activity (excluir atividade)
  246. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  247. // deleteno - does not erase activity (não apaga atividade)
  248. // add - add activity (adicionar atividade)
  249. // edit - edit activity (modificar atividade)
  250. $action_iassign = array(
  251. 'newcomment' => '$this->add_comment();',
  252. 'view' => '$this->view_iassign_current();',
  253. 'get_answer' => '$this->get_answer();',
  254. 'repeat' => '$this->view_iassign_current();',
  255. 'overwrite' => '$this->get_answer();',
  256. 'stats_student' => '$this->stats_students();',
  257. 'download_answer' => '$this->export_file_answer();',
  258. 'download_all_answer' => '$this->export_package_answer();',
  259. 'notifications' => '$this->view_notifications();');
  260. $action_iassign_limit = array(
  261. 'view' => '$this->view_iassign_current();',
  262. //'newcomment' => '$this->get_answer();',
  263. 'viewsubmission' => '$this->view_iassign_current();',
  264. 'edit_status' => '$this->edit_status();',
  265. 'edit_grade' => '$this->edit_grade();',
  266. 'export_csv' => '$this->export_csv();',
  267. 'report' => '$this->report();',
  268. 'print' => '$this->report();',
  269. 'stats' => '$this->stats();',
  270. 'printstats' => '$this->stats();');
  271. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  272. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  273. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  274. 'visible' => '$this->activity->visible_iassign($this->return);',
  275. 'delete' => '$this->activity->delete($this->return);',
  276. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  277. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  278. 'add' => '$this->add_edit_iassign();',
  279. 'edit' => '$this->add_edit_iassign();',
  280. 'get_answer' => '$this->get_answer();',
  281. 'duplicate_activity' => '$this->duplicate_activity();',
  282. 'move_activity' => '$this->move_activity();',
  283. 'auto_evaluate' => '$this->auto_evaluate();',
  284. 'all_submissions' => '$this->all_submissions();',
  285. 'delete_submissions' => '$this->delete_submissions();',
  286. 'download_submissions' => '$this->download_submissions();',
  287. 'open_individual_submission' => '$this->open_individual_submission();',
  288. 'get_individual_submission' => '$this->get_individual_submission();',
  289. 'get_student_submission' => '$this->get_student_submission();',
  290. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  291. 'post_auto_eval_result' => '$this->post_auto_eval_result();',
  292. 'import_activity' => '$this->import_activity();',
  293. 'import_activity_confirm' => '$this->import_activity_confirm();'
  294. );
  295. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  296. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  297. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  298. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  299. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  300. }
  301. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  302. eval($action_iassign_limit[$this->action]);
  303. }
  304. else { // Student reaches this point
  305. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  306. // Arrive here with: "get_answer"; "view"
  307. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  308. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  309. }
  310. } // function action()
  311. /// This method prints the student submission to a specific exercise
  312. function get_student_submission () {
  313. global $DB;
  314. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  315. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  316. if (!$student || !$exercise) exit;
  317. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  318. if ($iassign_submission)
  319. print($iassign_submission->answer);
  320. die();
  321. }
  322. /// This method prints the teacher exercise
  323. function get_teacher_exercise () {
  324. global $DB, $COURSE;
  325. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  326. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  327. $fs = get_file_storage(); // Get reference to all files in Moodle data
  328. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  329. //2021/12: $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  330. foreach ($files as $file) {
  331. if ($file->get_filename() != ".") {
  332. print($file->get_content());
  333. }
  334. }
  335. die();
  336. }
  337. /// This method receives the data from auto_eval event
  338. /// @see auto_evaluate()
  339. function post_auto_eval_result () {
  340. global $COURSE, $CFG, $USER, $DB;
  341. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  342. exit;
  343. //$exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  344. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  345. $student = optional_param('student', -1, PARAM_INT);
  346. $grade = optional_param('grade', 0, PARAM_FLOAT);
  347. // 1: Recuperar a nota atual:
  348. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  349. // 2: Atualizar a tabela:
  350. $update_entry = new stdClass();
  351. $update_entry->id = $actual->id;
  352. $update_entry->previous_grade = $actual->grade;
  353. $update_entry->grade = $grade;
  354. // Update the iassign_submission
  355. $DB->update_record("iassign_submission", $update_entry);
  356. }
  357. /// Function to help download all_submissions files
  358. function download_submissions_help ($list) {
  359. global $DB, $CFG, $OUTPUT;
  360. // Get list of iLMs
  361. $ilm_list = $DB->get_records("iassign_ilm");
  362. // Get list of enrolled students:
  363. $params_temp = array('shortname' => 'student');
  364. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  365. $context = context_course::instance($this->course->id);
  366. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  367. $students_list = $DB->get_records_sql(
  368. "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);
  369. $json_obj = new stdclass();
  370. $json_obj->submissions = [];
  371. $csvfields = [];
  372. $csvfields[] = 'submissionid';
  373. $csvfields[] = 'file';
  374. $csvfields[] = 'filesize';
  375. $csvfields[] = 'timestamp';
  376. $csvfields[] = 'humandate';
  377. $csvfields[] = 'grade';
  378. $csvfields[] = 'userid';
  379. $csvfields[] = 'exerciseid';
  380. $json_obj->submissions[] = $csvfields;
  381. $exercise_dir = [];
  382. $exercises_list = [];
  383. foreach ($list as $item) {
  384. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  385. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  386. $exercises_list[] = $temp;
  387. $exercise_dir[] = $temp->id;
  388. }
  389. }
  390. $student_dir = [];
  391. $students_list = [];
  392. foreach ($list as $item) {
  393. if (!in_array($item->userid, $student_dir)) {
  394. $temp = $DB->get_record("user", array("id" => $item->userid));
  395. $students_list[] = $temp;
  396. $student_dir[] = $temp->id;
  397. }
  398. }
  399. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  400. //TODO: tem que criar moodledata/temp/iassign_files
  401. // Create $CFG->dataroot/temp/iassign_files
  402. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  403. if (!file_exists($tempfilespath)) {
  404. mkdir($tempfilespath, 0777, true);
  405. }
  406. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  407. if (!file_exists($iassignfilespath)) {
  408. mkdir($iassignfilespath, 0777, true);
  409. }
  410. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  411. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  412. if (!file_exists($diretorio)) {
  413. 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.';
  414. exit;
  415. }
  416. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  417. $zip = new zip_archive(); // create ZIP
  418. if (!$zip->open($zip_filename)) {
  419. 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;
  420. exit;
  421. }
  422. ;
  423. foreach ($exercises_list as $exercise) {
  424. $dir_ex = iassign_utils::format_filename($exercise->name);
  425. $zip->add_directory($dir_ex);
  426. $extension_ilm = '';
  427. foreach ($ilm_list as $ilm) {
  428. if ($exercise->iassign_ilmid == $ilm->id) {
  429. $extension_ilm = $ilm->extension;
  430. break;
  431. }
  432. }
  433. foreach ($students_list as $student) {
  434. $individual_dir =
  435. $dir_ex . DIRECTORY_SEPARATOR .
  436. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  437. $zip->add_directory($individual_dir);
  438. $i = 1;
  439. foreach($list as $item) {
  440. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  441. $date = new DateTime();
  442. $date->setTimestamp($item->timecreated);
  443. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  444. $zip->add_file_from_string($new_file, $item->answer);
  445. $temp_json = [];
  446. $temp_json[] = intval($item->id);
  447. $temp_json[] = $new_file;
  448. $temp_json[] = strlen($new_file);
  449. $temp_json[] = intval($item->timecreated);
  450. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  451. $temp_json[] = doubleval($item->grade);
  452. $temp_json[] = intval($item->userid);
  453. $temp_json[] = intval($exercise->id);
  454. $json_obj->submissions[] = $temp_json;
  455. }
  456. }
  457. }
  458. }
  459. $csv_str = "";
  460. foreach($json_obj->submissions as $sub) {
  461. $csv_str .= $this->csvstr($sub) . "\n";
  462. }
  463. $zip->add_file_from_string('index.csv', $csv_str);
  464. $zip->close();
  465. iassign_utils::download_file($zip_filename);
  466. exit;
  467. }
  468. function csvstr(array $fields) : string {
  469. $f = fopen('php://memory', 'r+');
  470. if (fputcsv($f, $fields) === false) {
  471. return false;
  472. }
  473. rewind($f);
  474. $csv_line = stream_get_contents($f);
  475. return rtrim($csv_line);
  476. }
  477. /// Download submissions from table iassign_allsubmissions
  478. function download_submissions () {
  479. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  480. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  481. exit;
  482. $type = optional_param('type', NULL, PARAM_TEXT);
  483. $item = optional_param('item', NULL, PARAM_TEXT);
  484. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  485. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  486. $sub_list = [];
  487. if ($type == 'individual') {
  488. $sub_list[] = $DB->get_record(
  489. 'iassign_allsubmissions', array('id' => $item));
  490. } elseif ($type == 'student') {
  491. $sub_list = $DB->get_records(
  492. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  493. } elseif ($type == 'exercise') {
  494. $sub_list = $DB->get_records(
  495. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  496. } elseif ($type == 'block') {
  497. $exercises_in_block = $DB->get_records(
  498. 'iassign_statement', array('iassignid' => $iassign_id));
  499. foreach ($exercises_in_block as $exercise) {
  500. $temp = $DB->get_records(
  501. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  502. $sub_list = array_merge($sub_list, $temp);
  503. }
  504. }
  505. $this->download_submissions_help($sub_list);
  506. }
  507. /// Delete submissions in table iassign_allsubmissions
  508. function delete_submissions () {
  509. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  510. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  511. exit;
  512. $type = optional_param('type', NULL, PARAM_TEXT);
  513. $item = optional_param('item', NULL, PARAM_TEXT);
  514. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  515. if ($type == 'individual') {
  516. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  517. } elseif ($type == 'student') {
  518. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  519. } elseif ($type == 'exercise') {
  520. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  521. }
  522. }
  523. function get_individual_submission () {
  524. global $DB, $USER;
  525. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  526. exit;
  527. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  528. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  529. print $submission->answer;
  530. }
  531. /// Open individual submission
  532. function open_individual_submission () {
  533. global $DB, $USER, $CFG;
  534. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  535. exit;
  536. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  537. $id = $this->cm->id;
  538. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  539. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  540. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  541. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  542. $all_submissions = $DB->get_records('iassign_allsubmissions',
  543. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  544. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  545. $previous = null;
  546. $next = null;
  547. $i = 0;
  548. $found = false;
  549. foreach($all_submissions as $individual) {
  550. if (!$found && $individual->id != $submissionid) {
  551. $previous = $individual;
  552. }
  553. if ($found) {
  554. $next = $individual;
  555. break;
  556. }
  557. if ($individual->id === $submissionid) {
  558. $found = true;
  559. }
  560. $i++;
  561. }
  562. print '<center>' . "\n";
  563. 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";
  564. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>' . "\n";
  565. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>' . "\n";
  566. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>' . "\n";
  567. print '</table>' . "\n";
  568. if ($previous) {
  569. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  570. print '<a href="' . $url_prev . '" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  571. } else {
  572. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> ' . get_string('all_submissions_manager_previous', 'iassign') . '</a> ';
  573. }
  574. print ' (' . $i . '/' . count($all_submissions) . ')';
  575. if ($next) {
  576. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  577. 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";
  578. } else {
  579. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">' . get_string('all_submissions_manager_next', 'iassign') . ' <span>&#9654;</span></a>' . "\n";
  580. }
  581. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  582. //array("type" => "editor_new", "notSEND" => "true")
  583. print ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  584. print '</center>' . "\n";
  585. } // function open_individual_submission()
  586. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - inicio 1
  587. function import_activity_confirm () {
  588. global $USER, $DB;
  589. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  590. exit;
  591. if (!isset($_REQUEST['statements'])) exit;
  592. $iassign_destiny = $this->iassign->id;
  593. $activities_list = $_REQUEST['statements'];
  594. foreach($activities_list as $activity) {
  595. $activity_source = $DB->get_record('iassign_statement', array('id' => $activity));
  596. $activity_source->id = 0;
  597. $iassign_id_from = $activity_source->iassignid;
  598. $filesid_from = $activity_source->filesid;
  599. $activity_source->iassignid = $iassign_destiny;
  600. $author = $DB->get_record("user", array('id' => $USER->id));
  601. $activity_source->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  602. $activity_source->author_modified = $activity_source->author_modified_name;
  603. if ($id_ = $DB->insert_record("iassign_statement", $activity_source)) {
  604. $fs = get_file_storage();
  605. // Duplicate activity file
  606. $files_ids = $DB->get_records_sql('SELECT id FROM {files} WHERE component="mod_iassign" AND itemid=' . $filesid_from);
  607. print 'Arquivos a serem copiados: ';
  608. print_r($files_ids);
  609. foreach ($files_ids as $fileid) {
  610. $source_file = $fs->get_file_by_id($fileid->id);
  611. $newfile = $fs->create_file_from_storedfile(array('contextid' => $this->context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $source_file);
  612. $updateentry = new stdClass();
  613. $updateentry->id = $id_;
  614. $updateentry->filesid = $id_;
  615. // Update the duplicated iLM iAssign with new file id
  616. $DB->update_record("iassign_statement", $updateentry);
  617. }
  618. }
  619. }
  620. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->context->id));
  621. $str_index = count($activities_list) > 1 ? 'import_activities_success' : 'import_activity_success';
  622. redirect($this->return, get_string($str_index, 'iassign'), null, \core\output\notification::NOTIFY_SUCCESS);
  623. exit;
  624. }
  625. function import_activity () {
  626. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  627. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  628. exit;
  629. print '<script>
  630. function verify_selection () {
  631. document.getElementById("msg-error").classList.add("d-none");
  632. var checkboxes = document.getElementsByName("statements[]");
  633. for (var i = 0; i < checkboxes.length; i++)
  634. if (checkboxes[i].checked) return true;
  635. document.getElementById("msg-error").classList.remove("d-none");
  636. return false;
  637. }
  638. </script>'; // "
  639. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id, 'action' => 'import_activity_confirm'));
  640. print $OUTPUT->header();
  641. $this->print_main_menu();
  642. print '<h2 class="m-b-2 mt-4">' . get_string('import_activity', 'iassign') . '</h2>' . "\n";
  643. print '<form action="' . $destiny_url . '" method="post" onsubmit="return verify_selection()">' . "\n";
  644. $courses_as_teacher = $this->get_courses_enroled_as_teacher($USER->id);
  645. foreach ($courses_as_teacher as $course) {
  646. 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";
  647. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '">' . "\n";
  648. $iassigns = $this->get_iassign_items_by_course($course->id);
  649. if ($iassigns) {
  650. foreach ($iassigns as $iassign) {
  651. 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";
  652. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-' . $course->id . '-' . $iassign->id . '">' . "\n";
  653. $statements = $this->get_iassign_statement_by_iassign($iassign->id);
  654. print '<table class="table table-hover">' . "\n";
  655. if ($statements) {
  656. foreach ($statements as $statement) {
  657. print '<tr><td> <div class="form-check"> <input class="form-check-input" name="statements[]" type="checkbox" value="' . $statement->id . '" id="statement-' . $statement->id . '">' . "\n";
  658. print '<label class="form-check-label w-100" for="statement-' . $statement->id . '">' . $statement->name;
  659. print '</label></div></td></tr>' . "\n";
  660. }
  661. }
  662. else {
  663. print '<tr><td>' . get_string('no_activity', 'iassign') . '</td></tr>' . "\n";
  664. }
  665. print '</table></div>' . "\n";
  666. }
  667. }
  668. else {
  669. print '<div class="p-2">' . get_string('import_statement_empty', 'iassign') . '</div>' . "\n";
  670. }
  671. print '</div>' . "\n";
  672. }
  673. print '<div class="text-center"><button type="submit" class="btn btn-primary mt-2">Confirmar</button></div>' . "\n";
  674. print '<div class="text-center text-danger d-none" id="msg-error">' . get_string('import_statement_no_exercise', 'iassign') . '</div>' . "\n";
  675. print "</form>\n";
  676. print $OUTPUT->footer();
  677. } // function post_auto_eval_result()
  678. function get_iassign_items_by_course ($courseid) {
  679. global $DB;
  680. return $DB->get_records("iassign", array("course" => $courseid));
  681. }
  682. function get_iassign_statement_by_iassign ($iassignid) {
  683. global $DB;
  684. return $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  685. }
  686. function get_courses_enroled_as_teacher($userid) {
  687. $all_enroled = enrol_get_users_courses($userid);
  688. $return = array();
  689. foreach ($all_enroled as $enroled) {
  690. $context_course = context_course::instance($enroled->id);
  691. if (has_capability('mod/iassign:runautoevaluate', $context_course, $userid, false) ) {
  692. array_push($return, $enroled);
  693. }
  694. }
  695. return $return;
  696. }
  697. //2021/12 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx - final 1
  698. /// Manage all submissions in exercises to table iassign_allsubmissions
  699. function all_submissions () {
  700. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  701. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  702. exit;
  703. print $OUTPUT->header();
  704. $this->print_main_menu();
  705. $id = $this->cm->id;
  706. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  707. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  708. print '
  709. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  710. <div class="modal-dialog modal-dialog-centered" role="document">
  711. <div class="modal-content">
  712. <div class="modal-header">
  713. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('delete', 'iassign') . '</h5>
  714. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  715. <span aria-hidden="true">&times;</span>
  716. </button>
  717. </div>
  718. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  719. <div class="modal-footer">
  720. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  721. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  722. </div>
  723. </div>
  724. </div>
  725. </div>'; // "
  726. print '
  727. <script>
  728. var sub_type;
  729. var sub_item;
  730. var sub_el;
  731. var sub_exercise;
  732. function delete_submission (type, item, el, exercise = 0) {
  733. sub_type = type;
  734. sub_item = item;
  735. sub_exercise = exercise;
  736. sub_el = el.closest("tr");
  737. if (!sub_el) sub_el = el.closest("a");
  738. $("#modalConfirm").modal();
  739. }
  740. function confirm_delete () {
  741. var url = "'.$enderecoPOST.'&action=delete_submissions";
  742. var xhttp = new XMLHttpRequest();
  743. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  744. xhttp.send();
  745. $("#modalConfirm").modal("hide");
  746. if ($(sub_el).attr("href"))
  747. $($(sub_el).attr("href")).remove();
  748. if (sub_el) sub_el.remove();
  749. }
  750. function download_submission(type, item, exercise = 0, iassign = 0) {
  751. var url = "'.$enderecoPOST.'&action=download_submissions";
  752. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  753. document.location = url;
  754. }
  755. function open_submission(item) {
  756. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  757. var poupup = window.open(url, "popup", "width=900,height=900");
  758. }
  759. </script>' . chr(13); // '
  760. // Get list of exercises in the instance:
  761. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  762. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  763. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  764. 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>';
  765. // Get list of enrolled students:
  766. $params_temp = array('shortname' => 'student');
  767. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  768. $context = context_course::instance($this->course->id);
  769. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  770. $students_list = $DB->get_records_sql(
  771. "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);
  772. print '<div>';
  773. foreach ($exercises_list as $exercise) {
  774. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  775. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  776. print '
  777. <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> '
  778. . $exercise->name
  779. . ' - ' . $iassign_ilm->name
  780. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  781. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  782. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  783. . $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> '
  784. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  785. . '</a>';
  786. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  787. foreach ($students_list as $student) {
  788. $total = 0;
  789. $student_submissions = [];
  790. foreach ($submissions_list as $submission) {
  791. if ($submission->userid == $student->userid) {
  792. $student_submissions[] = $submission;
  793. $total++;
  794. }
  795. }
  796. 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");\'>
  797. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  798. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  799. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  800. . '<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> '
  801. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  802. . ' </a>';
  803. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  804. print '<table class="table table-striped table-hover"><thead>
  805. <tr>
  806. <th scope="col">#</th>
  807. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  808. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  809. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  810. </tr>
  811. </thead><tbody>'; // "
  812. $i = 1;
  813. foreach ($student_submissions as $individual) {
  814. $date = new DateTime();
  815. $date->setTimestamp($individual->timecreated);
  816. print '<tr>';
  817. print '<td>' . ($i++) . '</td>';
  818. print '<td>' . date_format($date, 'd/m/Y H:i:s') . '</td>';
  819. print '<td>' . $individual->grade . '</td>';
  820. print '<td>
  821. <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>
  822. <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>
  823. <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>';
  824. print " </tr>\n";
  825. }
  826. print '</tbody></table>';
  827. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  828. print '</div>';
  829. }
  830. print '</div>';
  831. }
  832. print '</div>';
  833. print $OUTPUT->footer();
  834. } // function all_submissions()
  835. /// This method runs activities auto evaluation in teacher area
  836. function auto_evaluate () {
  837. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  838. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  839. exit;
  840. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  841. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  842. // Get list of exercises in the instance:
  843. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  844. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  845. // Get list of enrolled students:
  846. $params_temp = array('shortname' => 'student');
  847. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  848. $context = context_course::instance($this->course->id);
  849. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  850. $students_list = $DB->get_records_sql(
  851. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  852. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  853. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  854. print $OUTPUT->header();
  855. $this->print_main_menu();
  856. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  857. print '<ul style="list-style-type: none; margin: 1em;">';
  858. foreach ($exercises_list as $exercise) {
  859. $matches = [];
  860. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  861. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  862. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  863. if ($matches[0][0]) {
  864. 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>';
  865. } else {
  866. 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>';
  867. }
  868. } else {
  869. if ($matches[0][0]) {
  870. 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>';
  871. } else {
  872. 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>';
  873. }
  874. }
  875. }
  876. print '</ul>
  877. <center>
  878. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  879. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  880. <div id="evaluate_message" style="color: red"></div>
  881. <div id="evaluate_alerts"></div>
  882. <div>
  883. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  884. <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>
  885. </div>
  886. </center>'; // close "
  887. print ' </div>' . "\n";
  888. print ' <script>' . "\n";
  889. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  890. print ' var submissions = [';
  891. // Get list of student id have submit for each exercise:
  892. foreach ($exercises_list as $exercise) {
  893. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  894. print '
  895. {
  896. "exerciseid": "' . $exercise->id . '",
  897. "grade": ' . $exercise->grade . ',
  898. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  899. "submited": ['; // "
  900. $params_temp = array('iassign_statementid' => $exercise->id);
  901. $submited = $DB->get_records_sql( // Get userid and his grade
  902. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  903. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  904. foreach ($submited as $ss) {
  905. print($ss->userid . ',');
  906. }
  907. print '],';
  908. print '"allgrades": [';
  909. foreach ($submited as $ss) {
  910. print( $ss->grade . ',');
  911. }
  912. print ']
  913. },'; // close "
  914. } // foreach ($exercises_list as $exercise)
  915. print " ];\n";
  916. print '
  917. var total_submissions = 0;
  918. var selected_exercises;
  919. var count_steps;
  920. var value_by_step;
  921. var stoped = false;
  922. var time_interval = 5000;
  923. var var_interval;
  924. function add_hover_th (id_th, id_li) { //AJAX
  925. $("#" + id_th).hover(function() {
  926. $("#" + id_li).css("background-color", "#d9d8d8");
  927. $(this).css("background-color", "#d9d8d8");
  928. }, function() {
  929. $("#" + id_li).css("background-color", "");
  930. $(this).css("background-color", "");
  931. });
  932. }
  933. function start_evaluation () {
  934. stoped = false;
  935. //AJAX
  936. $("#progress_bar").css("display", "none");
  937. $("#evaluate_message").text("");
  938. $("#evaluate_alerts").text("");
  939. $(".added-col").remove();
  940. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  941. selected_exercises = [];
  942. var c = 0;
  943. for (var i = 0; i < exercises.length; i++) {
  944. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  945. selected_exercises[c++] = exercises[i];
  946. }
  947. }
  948. if (selected_exercises.length == 0) {
  949. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  950. return;
  951. } else {
  952. $("input:checkbox").attr("disabled", true); //AJAX
  953. for (var i = 0; i < selected_exercises.length; i++) {
  954. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  955. //AJAX
  956. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  957. $("#table-results tbody tr").each(function(e) {
  958. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  959. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  960. });
  961. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  962. }
  963. //AJAX
  964. $("#button_start").prop("disabled", true);
  965. $("#button_stop").prop("disabled", false);
  966. $("#progress_bar").css("display", "block");
  967. }
  968. total_submissions = selected_exercises.length * students.length;
  969. count_steps = 0;
  970. value_by_step = 100/total_submissions;
  971. actual_exercise = 0;
  972. actual_student = 0;
  973. actual_submission = 0;
  974. get_original_propositions();
  975. var_interval = setInterval(verifyBreak, time_interval);
  976. } // function start_evaluation()
  977. var actual_exercise;
  978. var actual_student;
  979. var actual_submission;
  980. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  981. function run_individual_evaluation () {
  982. if (stoped) return;
  983. // Verify if student really sent his answer
  984. var found = false;
  985. for (var j = 0; j < submissions.length; j++) {
  986. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  987. for (var k = 0; k < submissions[j].submited.length; k++) {
  988. if (students[actual_student] == submissions[j].submited[k]) {
  989. found = true;
  990. break;
  991. }
  992. }
  993. break;
  994. }
  995. }
  996. if (found == false) {
  997. postResultAutoEval();
  998. } else {
  999. // If it was sent, search it...
  1000. var final_url = "";
  1001. 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];
  1002. for (var j = 0; j < submissions.length; j++) {
  1003. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  1004. final_url = submissions[j].ilm;
  1005. break;
  1006. }
  1007. }
  1008. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  1009. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1010. window.frames["ifrm"].location=final_url;
  1011. }
  1012. } // function run_individual_evaluation()
  1013. var break_student = -1;
  1014. var break_exercise = -1;
  1015. function verifyBreak () {
  1016. if (actual_student == break_student && actual_exercise == break_exercise) {
  1017. postResultAutoEval(-6);
  1018. break_student = -1;
  1019. break_exercise = -1;
  1020. return;
  1021. } else {
  1022. break_student = actual_student;
  1023. break_exercise = actual_exercise;
  1024. }
  1025. }
  1026. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  1027. function getStudentAnswerURL () {
  1028. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  1029. }
  1030. // This function is called by the iLM!!!
  1031. function getAutoEvalOriginalData () {
  1032. return original_propositions[actual_exercise];
  1033. }
  1034. function updateProgressBar () {
  1035. if (stoped) return;
  1036. var temp = (count_steps * value_by_step)|0;
  1037. count_steps++;
  1038. temp = temp > 100 ? 100 : temp;
  1039. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  1040. if (temp >= 100) {
  1041. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1042. $("#button_start").prop("disabled", false);
  1043. $("#button_stop").prop("disabled", true);
  1044. $("input:checkbox").attr("disabled", false);
  1045. clearInterval(var_interval);
  1046. }
  1047. }
  1048. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  1049. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  1050. function postResultAutoEval (grade = null) {
  1051. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  1052. if (grade == null) {
  1053. $("#"+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>\');
  1054. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1055. } else {
  1056. // Verify if the re-evaluation grade is the of that one registered:
  1057. var actual_value = 0;
  1058. var actual_student_grade = 0;
  1059. for (var k = 0; k < submissions.length; k++) {
  1060. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  1061. actual_value = submissions[k].grade;
  1062. for (var h = 0; h < submissions[k].submited.length; h++) {
  1063. if (submissions[k].submited[h] == students[actual_student]) {
  1064. actual_student_grade = submissions[k].allgrades[h];
  1065. break;
  1066. }
  1067. }
  1068. break;
  1069. }
  1070. }
  1071. // @FeedbackConvention
  1072. if (grade < 0) {
  1073. switch (grade) {
  1074. case -1:
  1075. // Test-cases are empty:
  1076. $("#"+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>\');
  1077. var mm = actual_exercise;
  1078. $("#"+id_t).find(".details-button").click(function(e) {
  1079. $(".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>\');
  1080. });
  1081. break;
  1082. case -2:
  1083. // Test-cases were manually altered by the student (fraud!):
  1084. $("#"+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>\');
  1085. var mm = actual_exercise;
  1086. $("#"+id_t).find(".details-button").click(function(e) {
  1087. $(".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>");
  1088. });
  1089. //AJAX
  1090. $.ajax({
  1091. dataType: "html",
  1092. 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",
  1093. success: function(d) {} });
  1094. break;
  1095. case -5:
  1096. // Execution failed:
  1097. $("#"+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>\');
  1098. var mm = actual_exercise;
  1099. //AJAX
  1100. $("#"+id_t).find(".details-button").click(function(e) {
  1101. $(".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>\');
  1102. });
  1103. break;
  1104. case -6: // iLM not answering was detected in "verifyBreak()"
  1105. // The iLM are not answering:
  1106. //AJAX
  1107. $("#"+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>\');
  1108. $("#"+id_t).find(".details-button").click(function(e) {
  1109. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  1110. });
  1111. break;
  1112. }
  1113. //AJAX
  1114. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1115. } else {
  1116. console.log((grade), (actual_student_grade));
  1117. if ((grade) == (actual_student_grade)) {
  1118. $("#"+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>\');
  1119. } else { // Notas diferem:
  1120. $("#"+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>\');
  1121. var mm = actual_exercise;
  1122. //AJAX
  1123. $("#"+id_t).find(".details-button").click(function(e) {
  1124. $(".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>\');
  1125. });
  1126. //AJAX
  1127. // Send to the endpoint the post_auto_eval_result to verify:
  1128. $.ajax({
  1129. dataType: "html",
  1130. 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),
  1131. success: function(d) {}
  1132. });
  1133. }
  1134. //AJAX
  1135. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1136. }
  1137. }
  1138. updateProgressBar();
  1139. // Does it must continue in the same exercise or stop?
  1140. if (actual_student < students.length) {
  1141. actual_student++;
  1142. run_individual_evaluation();
  1143. } else {
  1144. actual_student = 0;
  1145. // Does it go to next exercise or is it finished?
  1146. if (actual_exercise < selected_exercises.length) {
  1147. actual_exercise++;
  1148. run_individual_evaluation();
  1149. } else {
  1150. //AJAX
  1151. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1152. }
  1153. }
  1154. }
  1155. var original_propositions;
  1156. function get_original_propositions () {
  1157. original_propositions = [];
  1158. var count = 0;
  1159. for (var i = 0; i < exercises.length; i++) {
  1160. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1161. //AJAX
  1162. $.ajax({
  1163. dataType: "html",
  1164. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1165. success: function(d) { // variable "d" has the iLM content
  1166. original_propositions[count] = d; // exercise original content
  1167. count++;
  1168. if (count == selected_exercises.length) {
  1169. run_individual_evaluation();
  1170. }
  1171. }
  1172. });
  1173. }
  1174. }
  1175. }
  1176. function stop_evaluation () {
  1177. stoped = true;
  1178. //AJAX
  1179. $("#button_start").prop("disabled", false);
  1180. $("#button_stop").prop("disabled", true);
  1181. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1182. $("input:checkbox").attr("disabled", false);
  1183. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1184. clearInterval(var_interval);
  1185. }
  1186. var exercises = [ '; // '
  1187. foreach ($exercises_list as $exercise) {
  1188. print $exercise->id . ',';
  1189. }
  1190. print ' ];';
  1191. print ' var students = [ ';
  1192. foreach ($students_list as $student) {
  1193. print $student->userid . ',';
  1194. }
  1195. print '];';
  1196. print ' var ilms = [';
  1197. foreach ($exercises_list as $exercise) {
  1198. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1199. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1200. }
  1201. print ']';
  1202. print '</script>';
  1203. print '
  1204. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1205. <div class="modal-dialog modal-dialog-centered" role="document">
  1206. <div class="modal-content">
  1207. <div class="modal-header">
  1208. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1209. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1210. <span aria-hidden="true">&times;</span>
  1211. </button>
  1212. </div>
  1213. <div class="modal-body">
  1214. ...
  1215. </div>
  1216. <div class="modal-footer">
  1217. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1218. </div>
  1219. </div>
  1220. </div>
  1221. </div>'; //
  1222. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1223. print '<table id="table-results" class="table table-hover m-t-1">
  1224. <thead>
  1225. <tr id="cols-exercises">
  1226. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1227. </tr>
  1228. </thead>
  1229. <tbody>'; // "
  1230. foreach ($students_list as $student) {
  1231. $user = $DB->get_record('user', array('id' => $student->userid));
  1232. $avatar = new user_picture($user);
  1233. $avatar->courseid = $COURSE->id;
  1234. $avatar->link = true;
  1235. print ' <tr data-student="' . $student->userid . '">
  1236. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1237. </tr>' . "\n"; // "
  1238. }
  1239. print " </tbody>
  1240. </table>\n";
  1241. print $OUTPUT->footer();
  1242. } // function auto_evaluate()
  1243. /// This method moves an iAssign activity
  1244. function move_activity () {
  1245. global $USER, $CFG, $DB, $COURSE;
  1246. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1247. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1248. $update_entry_new_iassign = new stdClass();
  1249. $update_entry_new_iassign->id = $iassign_id;
  1250. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1251. // Update the iassign_statement
  1252. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1253. // Update file context
  1254. $c_i = context_module::instance($this->cm->id);
  1255. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1256. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1257. $path_module = context_course::instance($COURSE->id);
  1258. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1259. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny); //2021/12
  1260. if ($context_file) {
  1261. $id_context = $context_file->id;
  1262. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1263. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1264. $context = context_module::instance($USER->cm); //2021/12
  1265. //2021/12 $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1266. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1267. foreach ($files as $value) {
  1268. if ($value->get_filename() != ".") {
  1269. //2021/12 $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1270. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1271. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1272. $destiny_context = context_module::instance($course_module->id);
  1273. $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());
  1274. $updateentry = new stdClass();
  1275. $updateentry->id = $iassign_id;
  1276. $updateentry->filesid = $iassign_id; //2021/12 $newfile->get_itemid(); //TODO: esta' correto? $newfile definido 3 linhas acima NAO mais usado?
  1277. $DB->update_record("iassign_statement", $updateentry);
  1278. //2021/12 $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1279. break;
  1280. }
  1281. }
  1282. }
  1283. //2021/12 $this->return_home_course('moved_activity');
  1284. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1285. 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);
  1286. exit;
  1287. } // function move_activity()
  1288. /// This method duplicates an iAssign activity
  1289. function duplicate_activity () {
  1290. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1291. $id = $this->cm->id;
  1292. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1293. $context = context_module::instance($this->cm->id);
  1294. $contextuser = context_user::instance($USER->id);
  1295. // Get the the iAssign acitivity to be duplicated
  1296. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1297. // Remove the current id of activity
  1298. $id_source_copy = $iassign_statement->id;
  1299. $iassign_statement->id=0;
  1300. // Include prefix (Copy of ...)
  1301. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1302. // Get the information about current author, and add this information in author_modified field
  1303. $author = $DB->get_record("user", array('id' => $USER->id));
  1304. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1305. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1306. // Store the activity in the table
  1307. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1308. // Duplicate activity file
  1309. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1310. //2021/12 $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->filesid);
  1311. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1312. foreach ($files as $value) {
  1313. if ($value->get_filename() != ".") {
  1314. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1315. //2021/12 $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1316. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1317. $updateentry = new stdClass();
  1318. $updateentry->id = $id_;
  1319. //2021/12 $updateentry->filesid = $newfile->get_itemid();
  1320. $updateentry->filesid = $id_;
  1321. // Update the duplicated iLM iAssign with new file id
  1322. $DB->update_record("iassign_statement", $updateentry);
  1323. }
  1324. }
  1325. }
  1326. // log event --------------------------------------------------------------------------------------
  1327. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1328. $this->return_home_course('duplicated_activity');
  1329. exit;
  1330. }
  1331. // / This method gets the content from comment and register it
  1332. function add_comment () {
  1333. global $USER, $DB;
  1334. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1335. $comment = false;
  1336. if ($submission_comment)
  1337. $comment = $this->write_comment_submission();
  1338. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1339. if (!$id_submission) {
  1340. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  1341. if ($iassign_submission) {
  1342. $id_submission = $iassign_submission->id;
  1343. }
  1344. }
  1345. $content = $this->search_comment_submission($id_submission);
  1346. ob_end_clean();
  1347. header("Connection: close\r\n");
  1348. header("Content-Encoding: none\r\n");
  1349. header('Content-Type: text/html');
  1350. ob_start();
  1351. print $this->search_comment_submission($id_submission);
  1352. $size = ob_get_length();
  1353. header("Content-Length: $size");
  1354. ob_end_flush();
  1355. flush();
  1356. ob_end_clean();
  1357. // Send email to users:
  1358. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $id_submission));
  1359. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1360. }
  1361. /// This method alerts envolved to new comment sent
  1362. function send_alert_new_comment ($comment, $student_id = -1) {
  1363. global $USER, $DB, $COURSE, $SITE;
  1364. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign') . " ";
  1365. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); //leo 2021/12
  1366. $subject .= $iassign_ilm->name . ' ' . get_string('new_comment_mail_at', 'iassign') . ' ' . get_string("iassign", "iassign") . '/Moodle'; //leo 2021/12
  1367. // $url_curso; $url_submissao;
  1368. $text = "<p style='margin-top: 1rem;'>\n";
  1369. $text .= "<a href=\"" . new moodle_url('/course/view.php', array('id' => $COURSE->id)) . "\">" . $COURSE->shortname . "</a> " . " &#8811; \n";
  1370. $modinfo = get_fast_modinfo($COURSE);
  1371. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1372. if ($modinfo->get_section_info($i) && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1373. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1374. $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";
  1375. break;
  1376. }
  1377. }
  1378. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1379. $text .= "<a href=\"" . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id)) . "\">" . $iassign->name . "</a> &#8811; \n";
  1380. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1381. array(
  1382. 'id' => $this->cm->id,
  1383. 'action' => 'viewsubmission',
  1384. 'iassign_current' => $this->activity->get_activity()->id,
  1385. 'userid_iassign' => $USER->id));
  1386. $text .= "<a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a></p>\n";
  1387. $text .= "<div style='margin-left: .5rem;'>\n";
  1388. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>\n";
  1389. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1390. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>\n";
  1391. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>\n";
  1392. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': ' . "<a href=\"" .
  1393. new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">" . $USER->firstname . " " . $USER->lastname . "</a>\n";
  1394. $text .= " - " . userdate(time());
  1395. $text .= "</div><div style='margin: 2rem;'>\n";
  1396. $text .= $comment;
  1397. $text .= "</div><div>\n";
  1398. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | \n";
  1399. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>\n";
  1400. $text .= "</div>\n";
  1401. // Who has to receive?
  1402. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1403. $userfrom = \core_user::get_noreply_user();
  1404. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1405. // other teachers receive also: (excepts the sender)
  1406. foreach ($teachers as $teacher) {
  1407. if ($teacher->id != $USER->id) {
  1408. email_to_user(
  1409. $teacher,
  1410. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1411. $subject,
  1412. "",
  1413. $text,
  1414. '',
  1415. '',
  1416. false,
  1417. $userfrom->email,
  1418. 'Não responda a esta mensagem' //TODO: internacionalizar
  1419. );
  1420. $message = new \core\message\message();
  1421. $message->component = 'mod_iassign';
  1422. $message->name = 'message';
  1423. $message->userfrom = core_user::get_noreply_user();
  1424. $message->userto = $teacher;
  1425. $message->subject = $subject;
  1426. $message->fullmessage = $text;
  1427. $message->fullmessageformat = FORMAT_MARKDOWN;
  1428. $message->fullmessagehtml = $text;
  1429. $message->smallmessage = $subject;
  1430. $message->notification = 1;
  1431. $message->contexturl = $url_submissao . '#comments';
  1432. $message->contexturlname = $this->activity->get_activity()->name;
  1433. $messageid = message_send($message);
  1434. }
  1435. } // foreach ($teachers as $teacher)
  1436. // and student:
  1437. $student = $DB->get_record('user', array('id' => $student_id));
  1438. $formated_text = str_replace("viewsubmission", "view", $text);
  1439. email_to_user(
  1440. $student,
  1441. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1442. $subject,
  1443. "",
  1444. $formated_text,
  1445. '',
  1446. '',
  1447. false,
  1448. $userfrom->email,
  1449. 'Não responda a esta mensagem' //TODO: internacionalizar
  1450. );
  1451. $url_student = new moodle_url('/mod/iassign/view.php',
  1452. array(
  1453. 'id' => $this->cm->id,
  1454. 'action' => 'view',
  1455. 'iassign_current' => $this->activity->get_activity()->id));
  1456. $message = new \core\message\message();
  1457. $message->component = 'mod_iassign';
  1458. $message->name = 'message';
  1459. $message->userfrom = core_user::get_noreply_user();
  1460. $message->userto = $student;
  1461. $message->subject = $subject;
  1462. $message->fullmessage = $formated_text;
  1463. $message->fullmessageformat = FORMAT_MARKDOWN;
  1464. $message->fullmessagehtml = $formated_text;
  1465. $message->smallmessage = $subject;
  1466. $message->notification = 1;
  1467. $message->contexturl = $url_student . '#comments';
  1468. $message->contexturlname = $this->activity->get_activity()->name;
  1469. $messageid = message_send($message);
  1470. } // if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  1471. else { // a student has sent the comment:
  1472. foreach ($teachers as $teacher) {
  1473. email_to_user(
  1474. $teacher,
  1475. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1476. $subject,
  1477. "",
  1478. $text,
  1479. '',
  1480. '',
  1481. false,
  1482. $userfrom->email,
  1483. 'Não responda a esta mensagem' //TODO: internacionalizar
  1484. );
  1485. $message = new \core\message\message();
  1486. $message->component = 'mod_iassign';
  1487. $message->name = 'message';
  1488. $message->userfrom = core_user::get_noreply_user();
  1489. $message->userto = $teacher;
  1490. $message->subject = $subject;
  1491. $message->fullmessage = $text;
  1492. $message->fullmessageformat = FORMAT_MARKDOWN;
  1493. $message->fullmessagehtml = $text;
  1494. $message->smallmessage = $subject;
  1495. $message->notification = 1;
  1496. $message->contexturl = $url_submissao . '#comments';
  1497. $message->contexturlname = $this->activity->get_activity()->name;
  1498. $messageid = message_send($message);
  1499. } // foreach ($teachers as $teacher)
  1500. }
  1501. } // function send_alert_new_comment($comment, $student_id = -1)
  1502. /// This method gets the content from the iLM and register it
  1503. // It could be the "exercise template" (teacher) or an answer (student)
  1504. function get_answer () {
  1505. global $USER, $CFG, $DB, $OUTPUT;
  1506. $id = $this->cm->id;
  1507. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1508. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1509. if ($submission_ajax == 1) ob_start();
  1510. $comment = false;
  1511. if ($submission_comment)
  1512. $comment = $this->write_comment_submission();
  1513. // receives data of iLM using the current activity
  1514. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1515. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1516. // receives data of submission of current activity
  1517. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1518. // receives post and get
  1519. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1520. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1521. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1522. $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)
  1523. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1524. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1525. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1526. $msg = '';
  1527. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1528. $newentry = new stdClass();
  1529. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1530. $newentry->userid = $this->userid_iassign;
  1531. $newentry->timecreated = time();
  1532. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1533. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1534. $DB->insert_record("iassign_allsubmissions", $newentry);
  1535. }
  1536. // Feedback
  1537. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1538. $str_action = "view"; // repeat
  1539. if (strtolower($iassign_ilm->name) == "igeom") {
  1540. }
  1541. $title = get_string('evaluate_iassign', 'iassign');
  1542. print $OUTPUT->header();
  1543. print $OUTPUT->box_start();
  1544. // Action = { view ; repeat ; viewsubmission }
  1545. // * '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")
  1546. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1547. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1548. $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;
  1549. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1550. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1551. print '<table width=100% >';
  1552. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1553. //TODO alterar aqui???
  1554. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1555. // empty_answer_post = No solution was posted.
  1556. if ($comment)
  1557. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1558. else
  1559. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1560. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1561. } else {
  1562. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1563. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1564. // Correct answer!!
  1565. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1566. $this->write_solution = 1; //
  1567. $status = 3;
  1568. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1569. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1570. // log record
  1571. $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;
  1572. // Trigger module viewed event.
  1573. $event = \mod_iassign\event\submission_created::create(array(
  1574. 'objectid' => $this->iassign->id,
  1575. 'context' => $this->context,
  1576. 'other' => $info
  1577. ));
  1578. $event->add_record_snapshot('course', $this->course);
  1579. $event->trigger();
  1580. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1581. // Wrong answer...: get_answer_incorrect
  1582. $status = 2;
  1583. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1584. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1585. // log record
  1586. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1587. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1588. // Trigger module viewed event.
  1589. $event = \mod_iassign\event\submission_created::create(array(
  1590. 'objectid' => $this->iassign->id,
  1591. 'context' => $this->context,
  1592. 'other' => $info
  1593. ));
  1594. $event->add_record_snapshot('course', $this->course);
  1595. $event->trigger();
  1596. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1597. // Presents to the learner the result of the automatic evaluate?
  1598. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1599. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1600. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1601. print '<tr>';
  1602. // log record
  1603. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1604. // Trigger module viewed event.
  1605. $event = \mod_iassign\event\submission_created::create(array(
  1606. 'objectid' => $this->iassign->id,
  1607. 'context' => $this->context,
  1608. 'other' => $info
  1609. ));
  1610. $event->add_record_snapshot('course', $this->course);
  1611. $event->trigger();
  1612. } else { // yes!!!
  1613. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1614. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1615. print '<tr>';
  1616. print $msg;
  1617. }
  1618. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1619. $status = 1;
  1620. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1621. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1622. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1623. print '<tr>';
  1624. // log record
  1625. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1626. $event = \mod_iassign\event\submission_created::create(array(
  1627. 'objectid' => $this->iassign->id,
  1628. 'context' => $this->context,
  1629. 'other' => $info
  1630. ));
  1631. $event->add_record_snapshot('course', $this->course);
  1632. $event->trigger();
  1633. } // if ($iassign_ilm->evaluate == 1)
  1634. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1635. print '</tr></table>';
  1636. print $OUTPUT->box_end();
  1637. // add or update evaluate
  1638. if ($this->write_solution == 1) {
  1639. $timenow = time();
  1640. // new record
  1641. if (!$iassign_submission) {
  1642. $newentry = new stdClass();
  1643. $newentry->userid = $this->userid_iassign;
  1644. // $newentry->userid = $USER->id;
  1645. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1646. $newentry->timecreated = $timenow;
  1647. $newentry->timemodified = $timenow;
  1648. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1649. $newentry->grade = round($grade_student, 2);
  1650. $newentry->status = $status;
  1651. $newentry->experiment = 1;
  1652. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1653. print_error('error_insert', 'iassign');
  1654. } else {
  1655. // Trigger module viewed event.
  1656. $event = \mod_iassign\event\submission_created::create(array(
  1657. 'objectid' => $this->iassign->id,
  1658. 'context' => $this->context
  1659. ));
  1660. $event->add_record_snapshot('course', $this->course);
  1661. $event->trigger();
  1662. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1663. }
  1664. } elseif ($iassign_submission->status != 3) {
  1665. $newentry = new stdClass();
  1666. $newentry->id = $iassign_submission->id;
  1667. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1668. $newentry->userid = $iassign_submission->userid;
  1669. $newentry->timecreated = $iassign_submission->timecreated;
  1670. $newentry->timemodified = $timenow;
  1671. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1672. $newentry->grade = round($grade_student, 2);
  1673. $newentry->status = $status;
  1674. $newentry->experiment = $iassign_submission->experiment + 1;
  1675. if (!$DB->update_record("iassign_submission", $newentry)) {
  1676. print_error('error_update', 'iassign');
  1677. //D depurar...
  1678. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1679. //D $fp = fopen("teste1.txt","w");
  1680. //D fwrite($fp,$stringAux);
  1681. } else {
  1682. // Trigger module viewed event.
  1683. $event = \mod_iassign\event\submission_updated::create(array(
  1684. 'objectid' => $this->iassign->id,
  1685. 'context' => $this->context
  1686. ));
  1687. $event->add_record_snapshot('course', $this->course);
  1688. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1689. }
  1690. } else {
  1691. if ($return_get_answer == 1) {
  1692. $newentry = new stdClass();
  1693. $newentry->id = $iassign_submission->id;
  1694. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1695. $newentry->userid = $iassign_submission->userid;
  1696. $newentry->timecreated = $iassign_submission->timecreated;
  1697. $newentry->timemodified = $timenow;
  1698. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1699. $newentry->grade = round($grade_student, 2);
  1700. $newentry->status = $status;
  1701. $newentry->experiment = $iassign_submission->experiment + 1;
  1702. if (!$DB->update_record("iassign_submission", $newentry))
  1703. print_error('error_update', 'iassign');
  1704. else {
  1705. $event = \mod_iassign\event\submission_updated::create(array(
  1706. 'objectid' => $this->iassign->id,
  1707. 'context' => $this->context
  1708. ));
  1709. $event->add_record_snapshot('course', $this->course);
  1710. $event->trigger();
  1711. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1712. print $OUTPUT->box_start();
  1713. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1714. print $OUTPUT->box_end();
  1715. }
  1716. } elseif ($return_get_answer == 2) {
  1717. print $OUTPUT->box_start();
  1718. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1719. print $OUTPUT->box_end();
  1720. } else {
  1721. print $OUTPUT->box_start();
  1722. print "
  1723. <script type='text/javascript'>
  1724. //<![CDATA[
  1725. function overwrite () {
  1726. document.formEnvio.return_get_answer.value = 1;
  1727. document.formEnvio.submit();
  1728. }
  1729. function nooverwrite () {
  1730. document.formEnvio.return_get_answer.value = 2;
  1731. document.formEnvio.submit();
  1732. }
  1733. //]]>
  1734. </script>";
  1735. $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;
  1736. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1737. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1738. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1739. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1740. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1741. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1742. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1743. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1744. <input type='hidden' name='return_get_answer'/> ";
  1745. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1746. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1747. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1748. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1749. print " </form>";
  1750. print $OUTPUT->box_end();
  1751. }
  1752. }
  1753. } // if ($this->write_solution == 1)
  1754. print $OUTPUT->footer();
  1755. if ($submission_ajax == 1) {
  1756. ob_end_clean();
  1757. print 'OK';
  1758. }
  1759. die();
  1760. } // function get_answer()
  1761. /// Export in file the answer of student.
  1762. function export_file_answer () {
  1763. global $DB;
  1764. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1765. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1766. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1767. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1768. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1769. $extensions = explode(",", $iassign_ilm->extension);
  1770. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1771. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1772. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1773. header("Pragma: public");
  1774. header("Expires: 0");
  1775. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1776. header("Cache-Control: private", false);
  1777. header("Content-Type: document/unknown");
  1778. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1779. set_time_limit(0);
  1780. print($iassign_submission->answer);
  1781. exit;
  1782. } // function export_file_answer()
  1783. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1784. // @calledby $this->export_package_answer()
  1785. //TODO Precisa terminar! //TODO_HTML
  1786. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1787. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1788. <head>
  1789. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1790. $str_html .= " </head>
  1791. <body>\n";
  1792. $tam = sizeof($array_iassign_name);
  1793. for ($ii=0; $ii<$tam; $ii++) {
  1794. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1795. }
  1796. $str_html .= "
  1797. </body>\n</html>";
  1798. return $str_html;
  1799. }
  1800. /// Export an package (zip) with all answer of students
  1801. // @calledby $this->action()
  1802. function export_package_answer () {
  1803. global $DB, $CFG, $OUTPUT;
  1804. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1805. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1806. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1807. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1808. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1809. $userid = optional_param('userid', NULL, PARAM_INT);
  1810. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1811. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1812. //TODO_HTML echo "username=$username<br/>"; exit;
  1813. $current_date = date('Y_m_d_H');
  1814. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1815. // If temporary directory under Moodle data does not exists => create it
  1816. if (!is_dir($diretorio)) {
  1817. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1818. // created directory with permissions to be seen by everyone
  1819. }
  1820. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1821. if (!is_writable($diretorio)) { // send a highlighted message!
  1822. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1823. exit; // just in case
  1824. }
  1825. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1826. $zip = new zip_archive(); // create ZIP
  1827. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1828. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1829. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1830. $vet_student_filename = array();
  1831. $vet_student_content = array();
  1832. foreach ($iassign_statements as $iassign_statement) {
  1833. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1834. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1835. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1836. $extensions = explode(",", $iassign_ilm->extension);
  1837. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1838. if ($iassign_submission) {
  1839. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1840. $student_content = $iassign_submission->answer;
  1841. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1842. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1843. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1844. if ($resp) {
  1845. $vet_student_filename[] = $student_filename;
  1846. $vet_student_content[] = $student_content;
  1847. }
  1848. else { // send a highlighted message!
  1849. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1850. exit; // just in case
  1851. }
  1852. }
  1853. } // foreach ($iassign_statements as $iassign_statement)
  1854. $zip->close(); // close the ZIP file
  1855. if (count($vet_student_filename)>0) {
  1856. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1857. $result_tf = $vet_result[0];
  1858. $filenameZip = $vet_result[1]->filename;
  1859. }
  1860. iassign_utils::download_file($zip_filename); // download the ZIP file
  1861. exit;
  1862. } // function export_package_answer()
  1863. /// Editing status of interactive activities
  1864. function edit_status () {
  1865. global $USER, $DB, $OUTPUT;
  1866. $newentry = new stdClass();
  1867. $newentry->id = $this->iassign_submission_current;
  1868. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1869. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1870. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1871. $newentry->status = $iassign_submission->status;
  1872. $newentry->teacher = $USER->id;
  1873. if (!$DB->update_record('iassign_submission', $newentry))
  1874. print_error('error_update', 'iassign');
  1875. else {
  1876. // Trigger module viewed event.
  1877. $event = \mod_iassign\event\submission_updated::create(array(
  1878. 'objectid' => $this->iassign->id,
  1879. 'context' => $this->context
  1880. ));
  1881. $event->add_record_snapshot('course', $this->course);
  1882. $event->trigger();
  1883. $this->action = 'viewsubmission';
  1884. $this->view_iassign_current();
  1885. } // if (!$DB->update_record('iassign_submission', $newentry))
  1886. } // function edit_status()
  1887. /// Editing grade of interactive activities
  1888. function edit_grade () {
  1889. global $USER, $DB, $OUTPUT;
  1890. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1891. if ($newgrade && $newgrade >= 0) {
  1892. $newentry = new stdClass();
  1893. $newentry->id = $this->iassign_submission_current;
  1894. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1895. $newentry->teacher = $USER->id;
  1896. if (!$DB->update_record('iassign_submission', $newentry))
  1897. print_error('error_update', 'iassign');
  1898. else {
  1899. // Trigger module viewed event.
  1900. $event = \mod_iassign\event\submission_updated::create(array(
  1901. 'objectid' => $this->iassign->id,
  1902. 'context' => $this->context
  1903. ));
  1904. $event->add_record_snapshot('course', $this->course);
  1905. $event->trigger();
  1906. }
  1907. } // if ($newgrade >= 0)
  1908. $this->action = 'viewsubmission';
  1909. $this->view_iassign_current();
  1910. }
  1911. /// Add or Edit interactive activities
  1912. // Get here when editing form and and submitted form data
  1913. // @calledby $this->action()
  1914. function add_edit_iassign () {
  1915. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1916. require_once('iassign_form.php');
  1917. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1918. $iassignid = $this->iassign->id;
  1919. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1920. $param->action = $this->action; // hidden
  1921. $param->id = $id; // hidden
  1922. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1923. $COURSE->cm = $id;
  1924. $COURSE->iassignid = $iassignid;
  1925. $COURSE->iassign_file_id = NULL;
  1926. $context = context_module::instance($this->cm->id);
  1927. $contextuser = context_user::instance($USER->id);
  1928. $component = 'mod_iassign';
  1929. $filearea = 'exercise';
  1930. if (!empty($this->iassign_current))
  1931. $COURSE->iassign_id = $this->iassign_current;
  1932. else
  1933. $COURSE->iassign_id = 0;
  1934. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1935. if ($this->action == 'add') {
  1936. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1937. $params_temp = array('iassignid' => $iassignid);
  1938. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1939. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1940. $total_of_activities = count($iassign_statement);
  1941. $param->iassignid = $iassignid;
  1942. $param->name = "";
  1943. $param->oldname = "";
  1944. $param->type_iassign = 3;
  1945. $param->proposition = "";
  1946. $author = $DB->get_record("user", array("id" => $USER->id));
  1947. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1948. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1949. $param->author = $param->author_name;
  1950. $param->author_modified = $param->author_modified_name;
  1951. $COURSE->iassign_list = array();
  1952. $param->iassign_list = array();
  1953. if ($iassign_statement) {
  1954. foreach ($iassign_statement as $iassign) {
  1955. $iassignid = $iassign->id;
  1956. $param->iassign_list[$iassignid] = 0;
  1957. $COURSE->iassign_list[$iassignid] = new stdClass();
  1958. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1959. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1960. $COURSE->iassign_list[$iassignid]->enable = 1;
  1961. } // foreach ($iassign_statement as $iassign)
  1962. }
  1963. $param->iassign_ilmid = 0;
  1964. $param->file = 0;
  1965. $param->fileold = 0;
  1966. $param->filename = "";
  1967. $param->grade = $iassign_data->grade;
  1968. $param->timemodified = time();
  1969. $param->timecreated = time();
  1970. $param->timeavailable = $iassign_data->timeavailable;
  1971. $param->timedue = $iassign_data->timedue;
  1972. $param->preventlate = $iassign_data->preventlate;
  1973. $param->test = $iassign_data->test;
  1974. $param->special_param1 = 0;
  1975. $param->visible = 1;
  1976. $param->max_experiment = $iassign_data->max_experiment;
  1977. $param->dependency = 0;
  1978. $param->automatic_evaluate = 1;
  1979. $param->show_answer = 1;
  1980. } // if ($this->action == 'add')
  1981. elseif ($this->action == 'edit') {
  1982. $COURSE->iassign_list = array();
  1983. $this_activity = $this->activity->get_activity();
  1984. if ($this_activity != null) { // first enter here: fill form data
  1985. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1986. $param->iassign_id = $iassign_statement_current->id; // oculto
  1987. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1988. $param->name = $iassign_statement_current->name;
  1989. $param->oldname = $iassign_statement_current->name;
  1990. $param->type_iassign = $iassign_statement_current->type_iassign;
  1991. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1992. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1993. $param->author_name = $iassign_statement_current->author_name; // oculto
  1994. $param->author = $iassign_statement_current->author_name;
  1995. $author = $DB->get_record("user", array('id' => $USER->id));
  1996. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1997. $param->author_modified = $param->author_modified_name;
  1998. $dependency = explode(';', $iassign_statement_current->dependency);
  1999. $param->iassign_list = array();
  2000. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  2001. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  2002. $array_dependency = array();
  2003. $subdependency = "";
  2004. $sub_subdependency = "";
  2005. // Dependents on this exercise
  2006. if ($iassign_statement_dependency) {
  2007. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  2008. // to whom this exercise depends
  2009. foreach ($inter as $tmp)
  2010. $sub_subdependency .= $this->search_sub_dependency($tmp);
  2011. $list_dependency = $subdependency . $sub_subdependency;
  2012. $array_dependency = explode(";", $list_dependency);
  2013. }
  2014. // Get all activities in the same iAssigment block:
  2015. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  2016. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  2017. $total_of_activities = count($all_others_iassign_statement) + 1;
  2018. $inter = array();
  2019. if ($all_others_iassign_statement) {
  2020. foreach ($all_others_iassign_statement as $iassign)
  2021. if (in_array($iassign->id, $dependency))
  2022. $inter[] = $iassign->id;
  2023. }
  2024. if ($all_others_iassign_statement) {
  2025. foreach ($all_others_iassign_statement as $iassign) {
  2026. $iassignid = $iassign->id;
  2027. $COURSE->iassign_list[$iassignid] = new stdClass();
  2028. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  2029. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  2030. if (in_array($iassignid, $dependency))
  2031. $param->iassign_list[$iassignid] = 1;
  2032. else
  2033. $param->iassign_list[$iassignid] = 0;
  2034. if (in_array($iassignid, $array_dependency))
  2035. $COURSE->iassign_list[$iassignid]->enable = 0;
  2036. else
  2037. $COURSE->iassign_list[$iassignid]->enable = 1;
  2038. } // foreach ($all_others_iassign_statement as $iassign)
  2039. } // if ($all_others_iassign_statement)
  2040. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  2041. $param->fileold = 0;
  2042. $param->filesid = 0;
  2043. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  2044. $param->filename = '';
  2045. $param->grade = $iassign_statement_current->grade;
  2046. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  2047. $param->timeavailable = $iassign_statement_current->timeavailable;
  2048. $param->timedue = $iassign_statement_current->timedue;
  2049. $param->preventlate = $iassign_statement_current->preventlate;
  2050. $param->test = $iassign_statement_current->test;
  2051. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  2052. $param->position = $iassign_statement_current->position; // hidden
  2053. $param->visible = $iassign_statement_current->visible;
  2054. $param->max_experiment = $iassign_statement_current->max_experiment;
  2055. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  2056. $param->show_answer = $iassign_statement_current->show_answer;
  2057. $fs = get_file_storage(); // Get reference to all files in Moodle data
  2058. //2021/12 $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->filesid);
  2059. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
  2060. if ($files) {
  2061. foreach ($files as $file) {
  2062. if ($file->get_filename() != '.') {
  2063. $param->filename = $file->get_filename();
  2064. $param->file = $file->get_id();
  2065. $param->fileold = $file->get_id();
  2066. $COURSE->iassign_file_id = $file->get_id();
  2067. }
  2068. }
  2069. }
  2070. //TODO //MOOC2014 -- inicio
  2071. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  2072. //D if ($iassign_ilm_configs) {
  2073. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  2074. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  2075. //D } //MOOC2014 -- fim
  2076. } // if ($this_activity != null)
  2077. } // elseif ($this->action == 'edit')
  2078. // Get all iActivity in the iAssign block with id = $this->iassign->id
  2079. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  2080. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  2081. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  2082. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  2083. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  2084. $param->position = $total_of_activities;
  2085. // Create form and associate its data
  2086. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  2087. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  2088. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  2089. if (isset($param->iassign_ilmid)) {
  2090. // array is additional atributes to 'form'
  2091. // '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)"
  2092. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  2093. }
  2094. else {
  2095. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  2096. }
  2097. $mform->set_data($param); // define data in the form
  2098. if ($mform->is_cancelled()) {
  2099. $this->return_home_course('iassign_cancel');
  2100. exit;
  2101. }
  2102. else { // else if ($mform->is_cancelled())
  2103. $result = $mform->get_data();
  2104. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2105. if ($result) {
  2106. $result->context = $context;
  2107. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2108. $result->grade = 0;
  2109. if ($result->type_iassign == 1) {
  2110. $result->automatic_evaluate = 0;
  2111. $result->show_answer = 0;
  2112. }
  2113. elseif ($result->automatic_evaluate == 0)
  2114. $result->show_answer = 0;
  2115. // $_POST['iassign_list']
  2116. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2117. if ($result->iassign_list) {
  2118. foreach ($result->iassign_list as $key => $value)
  2119. $result->dependency .= $key . ';';
  2120. }
  2121. else
  2122. $result->dependency = 0;
  2123. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2124. //TODO Then get it directly from the form data $_POST!
  2125. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2126. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2127. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2128. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2129. if ($this->action == 'add') {
  2130. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2131. if ($iassign_statement_name) {
  2132. $this->return_home_course('error_iassign_name');
  2133. die();
  2134. }
  2135. // Really insert the new iActivity in table '*_iassign_statement'
  2136. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2137. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2138. // Trigger module viewed event.
  2139. $event = \mod_iassign\event\iassign_created::create(array(
  2140. 'objectid' => $iassignid,
  2141. 'context' => $context
  2142. ));
  2143. $event->add_record_snapshot('course', $this->course);
  2144. $event->trigger();
  2145. $this->return_home_course('iassign_add');
  2146. } // if ($this->action == 'add')
  2147. elseif ($this->action == 'edit') {
  2148. $iassignid = $this->activity->update_iassign($result);
  2149. $this->activity->update_calendar($iassignid, $result->oldname);
  2150. // Trigger module viewed event.
  2151. $event = \mod_iassign\event\iassign_updated::create(array(
  2152. 'objectid' => $iassignid,
  2153. 'context' => $context
  2154. ));
  2155. $event->add_record_snapshot('course', $this->course);
  2156. $event->trigger();
  2157. $this->return_home_course('iassign_update');
  2158. } // elseif ($this->action == 'edit')
  2159. die();
  2160. } // if ($result)
  2161. } // else if ($mform->is_cancelled())
  2162. print $OUTPUT->header();
  2163. $mform->display();
  2164. print $OUTPUT->footer();
  2165. die();
  2166. } // function add_edit_iassign()
  2167. /// Search for dependencies
  2168. function search_dependency ($search_iassing_id, $iassign_statement) {
  2169. global $DB, $OUTPUT;
  2170. $dependency = "";
  2171. if ($iassign_statement)
  2172. foreach ($iassign_statement as $iassign) {
  2173. $inter_dependency = explode(';', $iassign->dependency);
  2174. if (in_array($search_iassing_id, $inter_dependency)) {
  2175. $dependency .= $iassign->id . ";";
  2176. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2177. } // if (in_array($search_iassing_id, $inter_dependency))
  2178. } // foreach ($iassign_statement as $iassign)
  2179. return $dependency;
  2180. }
  2181. /// Search for "sub"dependency
  2182. function search_sub_dependency ($search_iassing_id) {
  2183. global $DB, $OUTPUT;
  2184. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2185. $dependency = "";
  2186. if ($iassign_statement) {
  2187. $inter_dependency = explode(';', $iassign_statement->dependency);
  2188. foreach ($inter_dependency as $tmp) {
  2189. if ($tmp != 0)
  2190. $dependency .= $tmp . ";";
  2191. $dependency .= $this->search_sub_dependency($tmp);
  2192. } // foreach ($inter_dependency as $tmp)
  2193. } // if ($iassign_statement)
  2194. return $dependency;
  2195. }
  2196. // Warning message
  2197. static function warning_message_iassign ($strcode) {
  2198. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2199. }
  2200. /// Update grade of iAssign
  2201. // Called always any iAssign activity is created
  2202. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2203. static function update_grade_iassign ($iassignid) {
  2204. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2205. require_once($CFG->libdir . '/gradelib.php');
  2206. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2207. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2208. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2209. // Each iAssign item is associated with one item on the "gradebook"
  2210. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2211. //$sum_grade = 0;
  2212. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2213. //foreach($grade as $tmp) {
  2214. // $sum_grade += $tmp->grade;
  2215. // }
  2216. //1 Solution 1
  2217. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2218. //1 $sum_grade = 0; //1
  2219. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2220. //2 Solution 2
  2221. $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
  2222. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2223. if (key($array_sum_grade))
  2224. $sum_grade = key($array_sum_grade); //2
  2225. else
  2226. $sum_grade = 0; //2
  2227. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2228. $grades = NULL;
  2229. $params_temp = array('itemname' => $grade_iassign->name);
  2230. $params_temp['iteminstance'] = $iassignid;
  2231. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2232. //2016 if ($sum_grade != 0) {
  2233. $params_temp['grademax'] = $sum_grade;
  2234. $params_temp['rawgrademax'] = $sum_grade;
  2235. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2236. $params_temp['grademin'] = 0;
  2237. // @calls /lib/gradelib.php: call to grade_item->insert()
  2238. //TODO: is there any error here in Moodle version 3.0?
  2239. //TODO: Incorrect property 'grademax' found when inserting grade object
  2240. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2241. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2242. }
  2243. /// Update grade of student
  2244. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2245. global $CFG, $DB, $OUTPUT;
  2246. require_once($CFG->libdir . '/gradelib.php');
  2247. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2248. // Review all the student submission for this iAssign activity
  2249. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2250. $total_grade = 0;
  2251. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2252. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2253. if ($iassign_submission)
  2254. $total_grade += $iassign_submission->grade;
  2255. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2256. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2257. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2258. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2259. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2260. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2261. $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
  2262. if (key($array_sum_grade))
  2263. $sum_grade = key($array_sum_grade); //2
  2264. else
  2265. $sum_grade = 0; //2
  2266. $grades['userid'] = $userid;
  2267. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2268. $params_temp = array('itemname' => $grade_iassign->name);
  2269. $params_temp['iteminstance'] = $iassignid;
  2270. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2271. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2272. $params_temp['grademax'] = $sum_grade;
  2273. $params_temp['rawgrademax'] = $sum_grade;
  2274. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2275. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2276. }
  2277. /// Display caption of icons - to the bottom page of teacher's report
  2278. function view_legend_icons () {
  2279. global $USER, $CFG, $DB, $OUTPUT;
  2280. $id = $this->cm->id;
  2281. if ($this->action == 'print')
  2282. print '<table border=1 width=100%><tr>';
  2283. else
  2284. print '<table width=100%><tr>';
  2285. print '<td >';
  2286. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2287. if ($this->action != 'print') {
  2288. $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";
  2289. $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";
  2290. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2291. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2292. } // if ($this->action != 'print')
  2293. print '</tr></table>' . "\n";
  2294. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2295. print '</td></tr></table>' . "\n";
  2296. } // function view_legend_icons()
  2297. /// Display activity current
  2298. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2299. function view_iassign_current () {
  2300. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2301. $id = $this->cm->id;
  2302. $iassignid = $this->iassign->id;
  2303. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2304. $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
  2305. // 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 ...
  2306. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2307. if (!$iassign_statement_activity_item) {
  2308. print $OUTPUT->header();
  2309. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2310. print $OUTPUT->footer();
  2311. exit;
  2312. }
  2313. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2314. $ilm_name = '';
  2315. if ($ilm->ilm)
  2316. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2317. // 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
  2318. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2319. // log record
  2320. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2321. //Trigger module viewed event.
  2322. $event = \mod_iassign\event\submission_viewed::create(array(
  2323. 'objectid' => $iassign->id,
  2324. 'context' => $this->context,
  2325. 'other' => $info
  2326. ));
  2327. $event->add_record_snapshot('course', $this->course);
  2328. $event->trigger();
  2329. // Search of iLM data used in the current activity
  2330. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2331. // Add actual activity to navbar:
  2332. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2333. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2334. print $OUTPUT->header();
  2335. if ($this->action == 'viewsubmission') {
  2336. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2337. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2338. else
  2339. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2340. } else {
  2341. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2342. }
  2343. if ($iassign_submission)
  2344. $this->update_comment($iassign_submission->id);
  2345. //2021/12 $file = $iassign_statement_activity_item->filesid;
  2346. $file = $iassign_statement_activity_item->id;
  2347. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2348. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2349. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2350. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2351. $this->bottonPost = 0; // hide submit button
  2352. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2353. $this->view_iassign = false; // disable visualization of activity
  2354. $repeat = "";
  2355. $last_iassign = "";
  2356. $student_answer = "";
  2357. $comment = "";
  2358. // *** Teacher access (view learner's submission)
  2359. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2360. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2361. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2362. // ---> access teacher for test
  2363. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2364. $this->bottonPost = 1;
  2365. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2366. $this->activity->view_dates();
  2367. $USER->iassignEdit = $this->bottonPost;
  2368. $this->activity->show_info_iassign();
  2369. if ($iassign_submission) {
  2370. //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;
  2371. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2372. } else {
  2373. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2374. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2375. }
  2376. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2377. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2378. // Prepare tags to present the iLM
  2379. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2380. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2381. // *** (end) Teacher access (view the activity)
  2382. // *** Teacher access (view learner's submission to the activity)
  2383. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2384. // It is teacher or 'nonediting teacher' that can evaluate
  2385. // ----> area teacher evaluate
  2386. $row = optional_param('row', 0, PARAM_INT);
  2387. $column = optional_param('column', 0, PARAM_INT);
  2388. $link_next = iassign_icons::insert('right_disable');
  2389. $link_previous = iassign_icons::insert('left_disable');
  2390. $link_up = iassign_icons::insert('up_disable');
  2391. $link_down = iassign_icons::insert('down_disable');
  2392. if (isset($USER->matrix_iassign[$row][$column])) {
  2393. $has_row_column = True;
  2394. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2395. }
  2396. else {
  2397. $has_row_column = False;
  2398. $element_matrix_iassign = $USER->matrix_iassign[$row][$column];
  2399. }
  2400. $msgViewAction = "view.php?action=viewsubmission&id=$id&iassign_submission_current=";
  2401. $msgUserId_current = "&userid_iassign=" . $this->userid_iassign . "&iassign_current=";
  2402. // next_activity
  2403. if ($has_row_column && $element_matrix_iassign->iassign_next != - 1) {
  2404. $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);
  2405. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2406. }
  2407. // previous_activity
  2408. if ($has_row_column && $element_matrix_iassign->iassign_previous != - 1) {
  2409. $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);
  2410. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2411. }
  2412. // previous_student
  2413. if ($has_row_column && $element_matrix_iassign->user_next != - 1) {
  2414. $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);
  2415. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2416. }
  2417. // next_student
  2418. if ($has_row_column && $element_matrix_iassign->user_previous != - 1) {
  2419. $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);
  2420. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2421. }
  2422. if ($iassign_submission) {
  2423. $student_answer = $iassign_submission->answer;
  2424. }
  2425. $last_iassign = get_string('last_iassign', 'iassign');
  2426. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2427. // Messages related to due date (and user role)
  2428. $this->activity->view_dates();
  2429. print $OUTPUT->box_start();
  2430. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2431. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2432. if ($user_data) // additional security (if occurs programming errors in $$url_next, $url_previous...)
  2433. print $OUTPUT->user_picture($user_data);
  2434. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2435. print '</td>' . "\n";
  2436. print '<td width=20% align=right>' . "\n";
  2437. print '<table width=50 cellpadding="0">';
  2438. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2439. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2440. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2441. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2442. print '</table>' . "\n";
  2443. print '</td></tr></table>' . "\n";
  2444. print $OUTPUT->box_end();
  2445. print $OUTPUT->box_start();
  2446. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2447. print '<td width=60% valign="top">' . "\n";
  2448. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2449. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2450. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2451. $resp = get_string('yes');
  2452. else
  2453. $resp = get_string('no');
  2454. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2455. if ($iassign_statement_activity_item->show_answer == 1)
  2456. $resp = get_string('yes');
  2457. else
  2458. $resp = get_string('no');
  2459. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2460. print '</td>';
  2461. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2462. print '<td width=40% valign="top" align="left">';
  2463. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2464. // check status of solution sent by the student
  2465. if ($iassign_submission) {
  2466. switch ($iassign_submission->status) {
  2467. case 3 :
  2468. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2469. break;
  2470. case 2 :
  2471. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2472. break;
  2473. case 1 :
  2474. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2475. break;
  2476. default :
  2477. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2478. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2479. } // switch ($iassign_submission->status)
  2480. }
  2481. else { // if ($iassign_submission)
  2482. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2483. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2484. }
  2485. // update_status
  2486. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2487. $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);
  2488. print " <script type='text/javascript'>
  2489. //<![CDATA[
  2490. function overwriteStatus (newstatus) {
  2491. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2492. document.formEditStatus.return_status.value=newstatus;
  2493. document.formEditStatus.submit();
  2494. }
  2495. else
  2496. document.formEditStatus.return_status.value=-1;
  2497. }
  2498. //]]>
  2499. </script>";
  2500. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2501. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2502. 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";
  2503. print " <input type='hidden' name='return_status'>\n";
  2504. print "</form>\n";
  2505. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2506. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2507. $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);
  2508. print "
  2509. <script type='text/javascript'>
  2510. //<![CDATA[
  2511. function overwriteGrade (newgrade,maxgrade) {
  2512. if (newgrade<0 || newgrade>maxgrade) {
  2513. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2514. document.formEditGrade.return_grade.value=-1;
  2515. document.formEditGrade.submit();
  2516. }
  2517. else {
  2518. document.formEditGrade.return_grade.value=newgrade;
  2519. document.formEditGrade.submit();
  2520. }
  2521. }
  2522. //]]>
  2523. </script>";
  2524. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2525. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2526. print " <input type='text' name='grade' size='6'>";
  2527. print " <input type='hidden' name='return_grade'> ";
  2528. 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";
  2529. print "</form>";
  2530. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2531. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2532. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2533. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2534. if ($teacher)
  2535. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2536. } // if ($iassign_submission->experiment > 0)
  2537. print '</td>';
  2538. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2539. print '</tr></table>';
  2540. print $OUTPUT->box_end();
  2541. $USER->iassignEdit = $this->bottonPost;
  2542. print activity::toggle_columns_script();
  2543. if ($iassign_submission && $allow_resubmission) {
  2544. // Put the iLM to
  2545. print $OUTPUT->box_start();
  2546. print '<p><strong>' . $last_iassign . '</strong></p>';
  2547. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2548. $enderecoPOST = "";
  2549. // Prepare tags to present the iLM
  2550. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2551. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2552. print $OUTPUT->box_end();
  2553. } // if ($iassign_submission && $allow_resubmission)
  2554. else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2555. // If '$student_answer' is empty, then the student does not submit any solution to the exercice
  2556. // ATTENTION: exception used by iGeom (exercise with "script")
  2557. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2558. if (substr($ilm_name, 0, 5)=="igeom") {
  2559. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2560. $loadTeacherActivity = true;
  2561. }
  2562. else
  2563. if (!$student_answer) { //2022/01 this student does not submit any soluction => load the teacher content
  2564. $loadTeacherActivity = true;
  2565. }
  2566. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2567. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2568. print activity::toggle_columns_script();
  2569. // Prepare tags to present the iLM
  2570. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2571. }
  2572. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2573. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2574. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2575. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2576. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2577. // *** (end) Teacher access (view learner's submission to the activity)
  2578. // *** Student access (view the activity)
  2579. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2580. // It could be the learner (he could send or resend the activity)
  2581. // ---> access student
  2582. $time_now = time();
  2583. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2584. // activity of type example - not submit button for submission
  2585. $this->view_iassign = true;
  2586. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2587. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2588. // activity of type test - iLM automatic evaluator - submit button for submission
  2589. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2590. $this->bottonPost = 1;
  2591. $this->view_iassign = true;
  2592. } else
  2593. $this->view_iassign = false;
  2594. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2595. // activity of type exercise (learner can send his answer, if yet open...)
  2596. $this->view_iassign = true;
  2597. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2598. $this->view_iassign = false;
  2599. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2600. $this->bottonPost = 1; // allow the submit button
  2601. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2602. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2603. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2604. if (!$iassign_submission) {
  2605. $str_iassign_submission_id = '';
  2606. $str_iassign_submission_answer = '';
  2607. }
  2608. else {
  2609. $str_iassign_submission_id = $iassign_submission->id;
  2610. $str_iassign_submission_answer = $iassign_submission->answer;
  2611. }
  2612. if ($this->action != 'repeat') {
  2613. $repeat = "<a href='view.php?action=repeat&id="
  2614. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2615. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2616. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2617. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2618. }
  2619. $this->bottonPost = 1;
  2620. $this->write_solution = 1; // can register his submission
  2621. $student_answer = $str_iassign_submission_answer;
  2622. }
  2623. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2624. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2625. $last_iassign = get_string('last_iassign', 'iassign');
  2626. if ($iassign_submission) {
  2627. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2628. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2629. $student_answer = $iassign_submission->answer;
  2630. } else {
  2631. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2632. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2633. }
  2634. }
  2635. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2636. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2637. $this->bottonPost = 1;
  2638. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2639. } else {
  2640. $last_iassign = get_string('last_iassign', 'iassign');
  2641. if ($iassign_submission) {
  2642. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2643. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2644. $student_answer = $iassign_submission->answer;
  2645. } else {
  2646. // Symbol of "redo activity"
  2647. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2648. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2649. }
  2650. }
  2651. } // elseif ($iassign_statement_activity_item->test == 1)
  2652. elseif ($iassign_statement_activity_item->test == 0)
  2653. $this->view_iassign = false;
  2654. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2655. if ($iassign_submission)
  2656. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2657. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2658. else
  2659. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2660. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2661. $this->activity->view_dates();
  2662. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2663. print $OUTPUT->box_start();
  2664. print '<table width=100% border=0 valign="top">' . "\n";
  2665. print '<tr><td width=60% valign="top">' . "\n";
  2666. $flag_dependency = true;
  2667. if ($iassign_statement_activity_item->type_iassign == 3) {
  2668. if ($iassign_statement_activity_item->dependency == 0) {
  2669. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2670. } else {
  2671. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2672. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2673. foreach ($dependencys as $dependency) {
  2674. if ($dependency) {
  2675. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2676. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2677. if ($dependencysubmissions) {
  2678. if ($dependencysubmissions->status == 3)
  2679. $icon = iassign_icons::insert('correct');
  2680. elseif ($dependencysubmissions->status == 2) {
  2681. $icon = iassign_icons::insert('incorrect');
  2682. $flag_dependency = false;
  2683. } elseif ($dependencysubmissions->status == 1) {
  2684. $icon = iassign_icons::insert('post');
  2685. $flag_dependency = false;
  2686. } elseif ($dependencysubmissions->status == 0) {
  2687. $icon = iassign_icons::insert('not_post');
  2688. $flag_dependency = false;
  2689. }
  2690. } else {
  2691. $icon = iassign_icons::insert('not_post');
  2692. $flag_dependency = false;
  2693. } // if ($dependencysubmissions)
  2694. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2695. } // if ($dependency)
  2696. } // foreach ($dependencys as $dependency)
  2697. } // if ($iassign_statement_activity_item->dependency == 0)
  2698. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2699. if ($flag_dependency == false) {
  2700. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2701. $this->view_iassign = false;
  2702. print '</tr></table>' . "\n";
  2703. }
  2704. else {
  2705. $this->view_iassign = true;
  2706. print '</td>' . "\n";
  2707. } // if ($flag_dependency == false)
  2708. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2709. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2710. // receiver=1 - message to teacher
  2711. // receiver=2 - message to student
  2712. if ($iassign_submission) {
  2713. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2714. if ($verify_message)
  2715. $comment = iassign_icons::insert('comment_unread');
  2716. }
  2717. print '<td width=40% valign="top" align="left">';
  2718. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2719. if ($iassign_statement_activity_item->show_answer == 1) {
  2720. // check status of solution sent by the student
  2721. if ($iassign_submission) {
  2722. switch ($iassign_submission->status) {
  2723. case 3 :
  2724. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2725. break;
  2726. case 2 :
  2727. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2728. break;
  2729. case 1 :
  2730. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2731. break;
  2732. default :
  2733. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2734. $repeat = "";
  2735. $last_iassign = "";
  2736. } // switch ($iassign_submission->status)
  2737. } else {
  2738. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2739. $repeat = "";
  2740. $last_iassign = "";
  2741. }
  2742. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2743. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2744. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2745. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2746. if ($iassign_statement_activity_item->max_experiment == 0)
  2747. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2748. else {
  2749. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2750. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2751. $repeat = "";
  2752. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2753. $this->bottonPost = 0;
  2754. $this->write_solution = 0;
  2755. }
  2756. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2757. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2758. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2759. if ($teacher)
  2760. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2761. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2762. } // if ($iassign_statement_activity_item->show_answer==1)
  2763. else {
  2764. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2765. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2766. $repeat = "";
  2767. $last_iassign = "";
  2768. } elseif ($iassign_submission->status == 1) {
  2769. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2770. }
  2771. }
  2772. print '</td>';
  2773. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2774. print '</tr></table>' . "\n";
  2775. // Presents the iLM
  2776. print '<table width=100% border=0 valign="top">' . "\n";
  2777. print '<td width=80% align="left">';
  2778. 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\".
  2779. print '<td width=20% align="rigth">';
  2780. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2781. print $repeat; // symbol of "redo activity"
  2782. print '</td></tr></table>' . "\n";
  2783. //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)'
  2784. print activity::toggle_columns_script();
  2785. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2786. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2787. $output = '';
  2788. if (!$iassign_ilm) {
  2789. $iassign_ilm = new stdClass();
  2790. $iassign_ilm->file_jar = "";
  2791. }
  2792. $output .= $OUTPUT->box_start();
  2793. $USER->iassignEdit = $this->bottonPost;
  2794. // ---
  2795. // Presents the iLM
  2796. // Prepare tags to present the iLM
  2797. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2798. $student_answer = ""; //?
  2799. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2800. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2801. $student_answer = "";
  2802. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2803. } else {
  2804. // When student is redoing his activity
  2805. // ATTENTION: exception used by iGeom (exercise with "script")
  2806. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2807. if (substr($ilm_name, 0, 5)=="igeom") {
  2808. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2809. $loadTeacherActivity = true;
  2810. }
  2811. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2812. }
  2813. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2814. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2815. //1 $history_comment = '';
  2816. //1 if ($iassign_submission) {
  2817. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2818. //1 }
  2819. //1 if (!empty($history_comment)) {
  2820. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2821. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2822. //1 $output .= $history_comment;
  2823. //1 $output .= "</table>\n";
  2824. //1 }
  2825. //1 $output .= "</form></center>\n";
  2826. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2827. //1 }
  2828. $output .= $OUTPUT->box_end();
  2829. print $output;
  2830. } // if ($this->view_iassign)
  2831. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2832. } // if ($this->view_iassign)
  2833. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2834. else
  2835. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2836. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2837. print '<table width=100% border=0 valign="top">' . "\n";
  2838. print '<tr><td width=60% valign="top">' . "\n";
  2839. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2840. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2841. print '</tr></table>' . "\n";
  2842. $student_answer = "";
  2843. $enderecoPOST = "";
  2844. // Prepare tags to present the iLM
  2845. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2846. print $output;
  2847. }
  2848. //2020 Frame with area to send and read comments (in this point to allow everyone read)
  2849. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2850. 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
  2851. // Put a block with area to sent/answer comments
  2852. $output = '';
  2853. $history_comment = '';
  2854. $row = optional_param('row', 0, PARAM_INT);
  2855. $column = optional_param('column', 0, PARAM_INT);
  2856. if ($iassign_submission) {
  2857. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2858. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2859. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2860. }
  2861. else {
  2862. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2863. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2864. }
  2865. $output .= $OUTPUT->box_start();
  2866. //if (!empty($history_comment)) {
  2867. $output .= "<a id='comments'></a>";
  2868. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2869. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2870. $output .= "</table>";
  2871. print " <script type='text/javascript'>
  2872. //<![CDATA[
  2873. function submit_comment(url) {
  2874. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2875. var formData = new FormData();
  2876. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2877. var request = new XMLHttpRequest();
  2878. request.open('POST', url);
  2879. document.getElementById('comments_history').innerHTML = '';
  2880. request.onload = function (e) {
  2881. if (request.readyState === 4) {
  2882. if (request.status === 200) {
  2883. document.getElementById('comments_history').innerHTML = request.responseText;
  2884. document.getElementById('check-message-success').style.visibility = 'visible';
  2885. setTimeout(function(){
  2886. document.getElementById('check-message-success').style.visibility = 'hidden';
  2887. }, 3000);
  2888. }
  2889. }
  2890. };
  2891. document.formEnvioComment.submission_comment.value = '';
  2892. request.send(formData);
  2893. }
  2894. function event_text_area (event) {
  2895. if (event.ctrlKey && event.keyCode == 13)
  2896. submit_comment('" . $enderecoPOSTcomment . "');
  2897. }
  2898. //]]>
  2899. </script>";
  2900. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2901. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2902. $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";
  2903. $output .= "</form> </center>\n";
  2904. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2905. // }
  2906. $output .= $OUTPUT->box_end();
  2907. print $output;
  2908. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2909. // final block 'studant'
  2910. print $OUTPUT->footer();
  2911. die();
  2912. } // function view_iassign_current()
  2913. /// Export the data from performance report into CSV file format
  2914. function export_csv () {
  2915. global $USER, $CFG, $DB, $OUTPUT;
  2916. $str = "";
  2917. $fields = "student_id, student_name";
  2918. // Finding all iassign activities for the iassign:
  2919. $id = $this->cm->id;
  2920. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2921. $c = 1;
  2922. foreach ($iassign_list as $iassign) {
  2923. $fields .= ", activity_id_" . $c . ", activity_name_" . $c . ", total_submissions_activity_" . $c . ", grade_activity_" . $c . ""
  2924. . ", status_activity_" . $c . ", ilm_id_activity_" . $c . ", ilm_name_activity_" . $c;
  2925. $c++;
  2926. }
  2927. // Finding enrolled students:
  2928. $params_temp = array('shortname' => 'student');
  2929. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2930. $context = context_course::instance($this->course->id);
  2931. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2932. $students = $DB->get_records_sql(
  2933. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2934. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2935. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2936. foreach ($students as $student) {
  2937. $str .= $student->userid . ',';
  2938. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2939. foreach ($iassign_list as $iassign) {
  2940. $str .= ',' . $iassign->id . ',';
  2941. $str .= '"' . $iassign->name . '",';
  2942. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2943. if ($student_submissions) {
  2944. $str .= $student_submissions->experiment . ',';
  2945. $str .= $student_submissions->grade . ',';
  2946. switch ($student_submissions->status) {
  2947. case 3:
  2948. $str .= '"correct",';
  2949. break;
  2950. case 2:
  2951. $str .= '"incorrect",';
  2952. break;
  2953. case 1:
  2954. $str .= '"post",';
  2955. break;
  2956. case 0:
  2957. $str .= '"not_post",';
  2958. break;
  2959. }
  2960. }
  2961. else {
  2962. $str .= ',,"not_post",';
  2963. }
  2964. $str .= $iassign->iassign_ilmid . ',';
  2965. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2966. $str .= '"' . $ilm_activity->name . '"';
  2967. }
  2968. $str .= "\n";
  2969. }
  2970. $str = $fields . "\n" . $str;
  2971. header("Content-type: text/csv");
  2972. header("Content-disposition: attachment; filename=report.csv");
  2973. header("Pragma: no-cache");
  2974. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2975. header('Content-Length: ' . strlen($str));
  2976. header('Connection: close');
  2977. print $str;
  2978. flush();
  2979. } // function export_csv()
  2980. /// Display report of performance
  2981. function report () {
  2982. global $USER, $CFG, $DB, $OUTPUT;
  2983. $id = $this->cm->id;
  2984. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2985. if ($this->action != 'print') {
  2986. $title = get_string('report', 'iassign');
  2987. print $OUTPUT->header();
  2988. } // if ($this->action != 'print')
  2989. $this->print_main_menu();
  2990. print $OUTPUT->box_start();
  2991. $this->view_legend_icons();
  2992. print $OUTPUT->box_end();
  2993. if ($this->action == 'print')
  2994. print '<table border=1 width="100%">' . "\n";
  2995. else
  2996. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  2997. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2998. // $num = array();
  2999. $i = 1;
  3000. $num = array();
  3001. $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;";
  3002. foreach ($iassign_list as $iassign) { // for all exercise in this block
  3003. $test_exercise = "";
  3004. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3005. if (($iassign_submission) && $iassign->type_iassign < 3) {
  3006. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  3007. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  3008. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  3009. $num[$i] = new stdClass();
  3010. $num[$i]->name = $iassign->name;
  3011. $num[$i]->id = $i;
  3012. $num[$i]->iassignid = $iassign->id;
  3013. print ' <tr >' . "\n";
  3014. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  3015. print "<td class=\"cell c0 actvity\">";
  3016. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  3017. print ' </tr>' . "\n";
  3018. $i++;
  3019. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  3020. } // foreach ($iassign_list as $iassign)
  3021. $num_exerc = $i; // total of exercises
  3022. print "</table>";
  3023. print "<p></p>";
  3024. if ($this->action == 'print')
  3025. print '<table border=1 width="100%">' . "\n";
  3026. else // ./theme/boost/style/moodle.css: .generaltable
  3027. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  3028. $context = context_course::instance($this->course->id);
  3029. if ($num_exerc > 1) {
  3030. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3031. $params_temp = array('shortname' => 'student');
  3032. $role = $DB->get_record_sql(
  3033. "SELECT s.id, s.shortname FROM {role} s " .
  3034. " WHERE s.shortname = :shortname", $params_temp);
  3035. // $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");
  3036. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3037. $students = $DB->get_records_sql(
  3038. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3039. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3040. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3041. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  3042. $width = 90/$num_exerc;
  3043. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  3044. $sum_iassign_correct[$j] = 0;
  3045. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  3046. }
  3047. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  3048. $sum_iassign = $j - 1;
  3049. print '</tr>' . "\n";
  3050. $total = 0;
  3051. $sum_student = 0;
  3052. $comment = iassign_icons::insert('comment_read');
  3053. $sum_comment = 0;
  3054. $sum_correct_iassign = array();
  3055. $sum_correct_student = array();
  3056. $USER->matrix_iassign = array();
  3057. if ($students) {
  3058. $w = 0;
  3059. foreach ($students as $tmp) { // count students
  3060. $users_array[$w] = $tmp;
  3061. $w++;
  3062. }
  3063. for ($x=0; $x<$w; $x++) { // for all students
  3064. print '<tr>' . "\n";
  3065. $sum_student++;
  3066. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  3067. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  3068. $total_student = 0;
  3069. $tentativas = 0;
  3070. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  3071. $sum_comment = $sum_verify_message = 0;
  3072. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  3073. if ($student_submissions) {
  3074. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  3075. $tentativas = $student_submissions->experiment;
  3076. // Get student comments
  3077. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  3078. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  3079. $student_submissions_comment = $DB->get_record_sql(
  3080. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3081. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  3082. if ($student_submissions_comment) // student has comment
  3083. foreach ($student_submissions_comment as $tmp)
  3084. $sum_comment = $tmp;
  3085. // informations to previous activities
  3086. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  3087. else $iassign_previous = $num[$j - 1]->iassignid;
  3088. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3089. else $user_previous = $users_array[$x - 1]->userid;
  3090. // next
  3091. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3092. else $iassign_next = "-1";
  3093. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3094. else $user_next = "-1";
  3095. $position = "&row= $x&column=$j";
  3096. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  3097. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3098. $url .= $position;
  3099. // receiver=1 - message to teacher
  3100. // receiver=2 - message to student
  3101. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  3102. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  3103. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  3104. $verify_message = $DB->get_record_sql(
  3105. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3106. "WHERE iassign_submissionid = :iassign_submissionid " .
  3107. " AND return_status= :return_status " .
  3108. " AND receiver= :receiver", $params_temp);
  3109. if ($verify_message)
  3110. foreach ($verify_message as $tmp)
  3111. $sum_verify_message = $tmp;
  3112. if ($sum_verify_message > 0)
  3113. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  3114. else
  3115. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  3116. if ($student_submissions->status == 3) {
  3117. $sum_iassign_correct[$j]++;
  3118. $total_student++;
  3119. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3120. }
  3121. elseif ($student_submissions->status == 2) {
  3122. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3123. }
  3124. elseif ($student_submissions->status == 1) {
  3125. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3126. }
  3127. elseif ($student_submissions->status == 0) {
  3128. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3129. }
  3130. if ($this->action != 'print') {
  3131. if ($tentativas > 0)
  3132. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3133. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3134. . $feedback
  3135. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3136. . $tentativas
  3137. . '</span> </button>'
  3138. . '</a>' . "\n";
  3139. else
  3140. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3141. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3142. . $feedback
  3143. .'</button>'
  3144. . '</a>' . "\n";
  3145. if ($sum_comment > 0 && $sum_verify_message > 0)
  3146. print '<a href="' . $url . '"> '
  3147. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3148. . $comment
  3149. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3150. . $sum_verify_message . '/' . $sum_comment
  3151. . '</span> </button>'
  3152. . '</a>';
  3153. else if ($sum_comment > 0)
  3154. print '<a href="' . $url . '"> '
  3155. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3156. . $comment
  3157. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3158. . $sum_comment
  3159. . '</span> </button>'
  3160. . '</a>';
  3161. print '</td>' . "\n";
  3162. }
  3163. if ($this->action == 'print')
  3164. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3165. } // if ($student_submissions)
  3166. else { // if ($student_submissions)
  3167. // Student does not have any submission
  3168. // informations to browse previous activities
  3169. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3170. else $iassign_previous = $num[$j - 1]->iassignid;
  3171. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3172. else $user_previous = $users_array[$x - 1]->userid;
  3173. // next
  3174. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3175. else $iassign_next = "-1";
  3176. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3177. else $user_next = "-1";
  3178. $position = "&row= $x&column=$j";
  3179. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3180. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3181. $url .= $position;
  3182. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3183. if ($this->action == 'print')
  3184. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3185. else {
  3186. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3187. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3188. . $feedback
  3189. .'</button>'
  3190. . '</a>' . "\n";
  3191. // print '<td> &nbsp;</td>';
  3192. if ($sum_comment > 0)
  3193. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3194. // else print '<td> &nbsp;</td>';
  3195. print '</td>';
  3196. }
  3197. } // else if ($student_submissions)
  3198. $USER->matrix_iassign[$x][$j] = new stdClass();
  3199. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3200. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3201. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3202. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3203. if ($student_submissions)
  3204. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3205. else
  3206. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3207. //print '</td>' . "\n";
  3208. } // for ($j=1; $j<$num_exerc; $j++)
  3209. $total = $total + $total_student;
  3210. $porcentagem = ($total_student / ($j - 1)) * 100;
  3211. if ($tentativas != 0 && $tentativas != null) {
  3212. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3213. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3214. }
  3215. else {
  3216. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3217. }
  3218. print '</tr>' . "\n";
  3219. $sum_correct_student[$sum_student] = new stdClass();
  3220. $sum_correct_student[$sum_student]->name = $name;
  3221. $sum_correct_student[$sum_student]->sum = $total_student;
  3222. } // for ($x = 0; $x < $w; $x++)
  3223. for ($i = 1; $i < $j; $i++) {
  3224. if (is_null($sum_iassign_correct[$i]))
  3225. $sum_iassign_correct[$i] = 0;
  3226. $sum_correct_iassign[$i] = new stdClass();
  3227. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3228. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3229. }
  3230. // print '</tr></table>' . "\n";
  3231. }
  3232. } // if ($i>1)
  3233. else {
  3234. print_string('no_activity', 'iassign');
  3235. }
  3236. print "</table>\n";
  3237. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . "</p>\n"; // the number of atemps is...
  3238. print '<p>' . get_string('ps_comment', 'iassign') . "</p>\n"; // the total number of messages is...
  3239. if ($this->action != 'print')
  3240. print $OUTPUT->footer();
  3241. die();
  3242. } // function report()
  3243. /// Display graphics of performance
  3244. function stats () {
  3245. global $USER, $CFG, $DB, $OUTPUT;
  3246. $id = $this->cm->id;
  3247. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3248. if ($this->action != 'printstats')
  3249. $title = get_string('graphic', 'iassign');
  3250. $num = array();
  3251. $sum_correct_iassign = array();
  3252. $sum_correct_student = array();
  3253. $sum_student = 0;
  3254. $i = 1;
  3255. foreach ($iassign_list as $iassign) {
  3256. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3257. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3258. $sum_iassign_correct[$i] = 0;
  3259. $num[$i] = new stdClass();
  3260. $num[$i]->name = $iassign->name;
  3261. $num[$i]->id = $i;
  3262. $num[$i]->iassignid = $iassign->id;
  3263. $i++;
  3264. } // if ($iassign->type_iassign == 3)
  3265. } // foreach ($iassign_list as $iassign)
  3266. $sum_iassign = $i - 1;
  3267. $context = context_course::instance($this->course->id);
  3268. if ($i > 1) {
  3269. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3270. $params_temp = array('shortname' => 'student');
  3271. $role = $DB->get_record_sql(
  3272. "SELECT s.id, s.shortname FROM {role} s " .
  3273. " WHERE s.shortname = :shortname", $params_temp);
  3274. // $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");
  3275. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3276. $students = $DB->get_records_sql(
  3277. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3278. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3279. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3280. $total = 0;
  3281. $sum_student = 0;
  3282. $j = 0;
  3283. $sum_correct_iassign = array();
  3284. $sum_correct_student = array();
  3285. $sum_experiment = array();
  3286. if ($students) {
  3287. foreach ($students as $users) {
  3288. $sum_student++;
  3289. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3290. // rows
  3291. $total_student = 0;
  3292. for ($j = 1; $j < $i; $j++) {
  3293. $total_experiment = 0;
  3294. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3295. if ($student_submissions) {
  3296. if ($student_submissions->status == 3) {
  3297. $sum_iassign_correct[$j]++;
  3298. $total_student++;
  3299. } // if ($student_submissions->status == 3)
  3300. $total_experiment += $student_submissions->experiment;
  3301. }
  3302. $sum_experiment[$j] = $total_experiment;
  3303. } // for ($j=1; $j<$i; $j++)
  3304. $total = $total + $total_student;
  3305. $sum_correct_student[$sum_student] = new stdClass();
  3306. $sum_correct_student[$sum_student]->name = $name;
  3307. $sum_correct_student[$sum_student]->sum = $total_student;
  3308. } // foreach ($students as $users)
  3309. }
  3310. for ($i = 1; $i < $j; $i++) {
  3311. if (is_null($sum_iassign_correct[$i]))
  3312. $sum_iassign_correct[$i] = 0;
  3313. $sum_correct_iassign[$i] = new stdClass();
  3314. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3315. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3316. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3317. } // for ($i = 1; $i < $j; $i++)
  3318. } // if ($i > 1)
  3319. print $OUTPUT->header();
  3320. $this->print_main_menu();
  3321. if ($this->action != 'printstats') {
  3322. $title = get_string('graphic', 'iassign');
  3323. $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>";
  3324. $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>";
  3325. print '<table width=100%><tr>';
  3326. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3327. print '<td width=15% align="right">' . $link_report . '</td>';
  3328. print '</td></tr></table>' . "\n";
  3329. print "<br><br>";
  3330. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3331. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3332. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3333. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3334. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3335. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3336. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3337. print '</tr>' . "\n";
  3338. $sum_correct = 0;
  3339. if ($sum_correct_iassign) {
  3340. foreach ($sum_correct_iassign as $iassign) {
  3341. if (is_null($iassign->experiment))
  3342. $iassign->experiment = 0;
  3343. $bar = "";
  3344. $sum = $iassign->sum;
  3345. $percent = ($sum / $sum_student) * 100;
  3346. $text = number_format($percent, 1) . '%';
  3347. $sum_correct += $sum;
  3348. if ($sum > 0) {
  3349. for ($i = 1; $i < $percent * 2; $i++)
  3350. $bar .= iassign_icons::insert('hbar_blue');
  3351. $bar .= iassign_icons::insert('hbar_blue_r');
  3352. } // if ($sum > 0)
  3353. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3354. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3355. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3356. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3357. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3358. print '</tr>' . "\n";
  3359. } // foreach ($sum_correct_iassign as $iassign)
  3360. }
  3361. print "</table>";
  3362. print "<br><br>";
  3363. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3364. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3365. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3366. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3367. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3368. print '</tr>' . "\n";
  3369. $sum_correct = 0;
  3370. foreach ($sum_correct_student as $student) {
  3371. $bar = "";
  3372. $sum = $student->sum;
  3373. $percent = ($sum / $sum_iassign) * 100;
  3374. $text = number_format($percent, 1) . '%';
  3375. $sum_correct += $sum;
  3376. if ($sum > 0) {
  3377. for ($i = 1; $i < $percent * 2; $i++)
  3378. $bar .= iassign_icons::insert('hbar_blue');
  3379. $bar .= iassign_icons::insert('hbar_blue_r');
  3380. } // if ($sum > 0)
  3381. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3382. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3383. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3384. print '</tr>' . "\n";
  3385. } // foreach ($sum_correct_student as $student)
  3386. print "</table>\n";
  3387. print "<br><br>\n";
  3388. $var = 0;
  3389. $cv = 0;
  3390. $dv = 0;
  3391. $avg = 0;
  3392. if ($sum_correct_student) {
  3393. $avg = $sum_correct / $sum_student;
  3394. if ($avg > 0) {
  3395. foreach ($sum_correct_student as $student)
  3396. $var += pow($student->sum - $avg, 2);
  3397. $var = $var / $sum_student;
  3398. $dv = sqrt($var);
  3399. $cv = ($dv / $avg) * 100;
  3400. }
  3401. }
  3402. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3403. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3404. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3405. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3406. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3407. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3408. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3409. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3410. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3411. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3412. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3413. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3414. print "</table>\n";
  3415. print $OUTPUT->footer();
  3416. } else {
  3417. print "<STYLE TYPE='text/css'>
  3418. <!--
  3419. .boldtable {
  3420. font-family:sans-serif;
  3421. font-size:10pt;
  3422. }
  3423. -->
  3424. </STYLE>\n";
  3425. print '<table border=1 width=100%>' . "\n";
  3426. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3427. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3428. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3429. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3430. print '</tr>' . "\n";
  3431. $sum_correct = 0;
  3432. foreach ($sum_correct_iassign as $iassign) {
  3433. $bar = "";
  3434. $sum = $iassign->sum;
  3435. $percent = ($sum / $sum_student) * 100;
  3436. $text = number_format($percent, 1) . '%';
  3437. $sum_correct += $sum;
  3438. if ($sum > 0) {
  3439. for ($i = 1; $i < $percent * 2; $i++)
  3440. $bar .= iassign_icons::insert('hbar_blue');
  3441. $bar .= iassign_icons::insert('hbar_blue_r');
  3442. } // if ($sum > 0)
  3443. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3444. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3445. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3446. print '</tr>' . "\n";
  3447. } // foreach ($sum_correct_iassign as $iassign)
  3448. print "</table>";
  3449. print "<br><br>";
  3450. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3451. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3452. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3453. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3454. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3455. print '</tr>' . "\n";
  3456. $sum_correct = 0;
  3457. foreach ($sum_correct_student as $student) {
  3458. $bar = "";
  3459. $sum = $student->sum;
  3460. $percent = ($sum / $sum_iassign) * 100;
  3461. $text = number_format($percent, 1) . '%';
  3462. $sum_correct += $sum;
  3463. if ($sum > 0) {
  3464. for ($i = 1; $i < $percent * 2; $i++)
  3465. $bar .= iassign_icons::insert('hbar_blue');
  3466. $bar .= iassign_icons::insert('hbar_blue_r');
  3467. } // if ($sum > 0)
  3468. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3469. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3470. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3471. print '</tr>' . "\n";
  3472. } // foreach ($sum_correct_student as $student)
  3473. print "</table>\n";
  3474. print "<br/><br/>\n";
  3475. $var = 0;
  3476. $cv = 0;
  3477. $dv = 0;
  3478. $avg = 0;
  3479. if ($sum_correct_student) {
  3480. $avg = $sum_correct / $sum_student;
  3481. if ($avg > 0) {
  3482. foreach ($sum_correct_student as $student)
  3483. $var += pow($student->sum - $avg, 2);
  3484. $var = $var / $sum_student;
  3485. $dv = sqrt($var);
  3486. $cv = ($dv / $avg) * 100;
  3487. }
  3488. }
  3489. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3490. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3491. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3492. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3493. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3494. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3495. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3496. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3497. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3498. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3499. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3500. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3501. print "</table>\n";
  3502. } // if ($this->action != 'printstats')
  3503. die();
  3504. }
  3505. /// Display graphics of performance for students
  3506. function stats_students () {
  3507. global $USER, $CFG, $DB, $OUTPUT;
  3508. $id = $this->cm->id;
  3509. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3510. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3511. $title = get_string('results', 'iassign');
  3512. $sum_correct = 0;
  3513. $sum_incorrect = 0;
  3514. $sum_post = 0;
  3515. $sum_nopost = 0;
  3516. $sum_iassign = count($iassign_statement_list);
  3517. $bar_nopost = "";
  3518. $bar_correct = "";
  3519. $bar_incorrect = "";
  3520. $bar_post = "";
  3521. $text_nopost = "";
  3522. $text_correct = "";
  3523. $text_incorrect = "";
  3524. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3525. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3526. if ($iassign_submission) {
  3527. if ($iassign_submission->status == 3)
  3528. $sum_correct++;
  3529. elseif ($iassign_submission->status == 2)
  3530. $sum_incorrect++;
  3531. elseif ($iassign_submission->status == 1)
  3532. $sum_post++;
  3533. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3534. $sum_nopost++;
  3535. } // if ($iassign_submission)
  3536. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3537. if ($sum_iassign > 0) {
  3538. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3539. $text_correct = number_format($percent_correct, 1) . '%';
  3540. }
  3541. if ($sum_correct > 0) {
  3542. for ($i = 1; $i < $percent_correct * 2; $i++)
  3543. $bar_correct .= iassign_icons::insert('hbar_green');
  3544. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3545. } // if ($sum_correct > 0)
  3546. if ($sum_iassign > 0) {
  3547. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3548. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3549. }
  3550. if ($sum_incorrect > 0) {
  3551. for ($i = 1; $i < $percent_incorrect * 2; $i++)
  3552. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3553. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3554. } // if ($sum_incorrect > 0)
  3555. if ($sum_iassign > 0) {
  3556. $percent_post = ($sum_post / $sum_iassign) * 100;
  3557. $text_post = number_format($percent_post, 1) . '%';
  3558. }
  3559. if ($sum_post > 0) {
  3560. for ($i = 1; $i < $percent_post * 2; $i++)
  3561. $bar_post .= iassign_icons::insert('hbar_blue');
  3562. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3563. } // if ($sum_post > 0)
  3564. if ($sum_iassign > 0) {
  3565. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3566. $text_nopost = number_format($percent_nopost, 1) . '%';
  3567. }
  3568. if ($sum_nopost > 0) {
  3569. for ($i = 1; $i < $percent_nopost * 2; $i++)
  3570. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3571. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3572. } // if ($sum_nopost > 0)
  3573. print $OUTPUT->header();
  3574. $this->print_main_menu();
  3575. //2021/12 $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3576. //2021/12 print '<table width=100%><tr>';
  3577. //2021/12 print '<td align="right">' . $link_return . '</td>' . "\n";
  3578. //2021/12 print '</td></tr></table>' . "\n";
  3579. print "<br/><br/>\n";
  3580. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3581. print '<tr><th colspan=3 class="header c1">' . "\n";
  3582. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3583. // $imagetext = '');
  3584. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3585. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3586. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3587. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3588. print '</tr>' . "\n";
  3589. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3590. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3591. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3592. print '</tr>' . "\n";
  3593. if ($sum_post) {
  3594. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3595. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3596. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3597. print '</tr>' . "\n";
  3598. } // if ($sum_post)
  3599. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3600. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3601. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3602. print '</tr>' . "\n";
  3603. print "</table>";
  3604. print "<br><br>";
  3605. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3606. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3607. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3608. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3609. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3610. $sum_grade = 0;
  3611. $sum_grade_student = 0;
  3612. $avg = 0;
  3613. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3614. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3615. if (!$iassign_submission) {
  3616. $iassign_submission = new stdClass();
  3617. $iassign_submission->grade = 0;
  3618. }
  3619. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3620. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3621. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3622. print '</tr>' . "\n";
  3623. $sum_grade += $iassign_statement_activity_item->grade;
  3624. $sum_grade_student += $iassign_submission->grade;
  3625. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3626. if ($sum_grade > 0)
  3627. $avg = $sum_grade_student / $sum_grade * 100;
  3628. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3629. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3630. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3631. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3632. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3633. print "</table>";
  3634. print $OUTPUT->footer();
  3635. die();
  3636. } // function stats_students()
  3637. function get_total_notifications () {
  3638. global $DB, $USER, $COURSE;
  3639. $total_messages = 0;
  3640. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3641. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3642. $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 "
  3643. . " 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);
  3644. }
  3645. else {
  3646. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3647. $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 "
  3648. . " 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);
  3649. }
  3650. return $total_messages->total;
  3651. }
  3652. function get_iassign_statement_messages () {
  3653. global $DB, $USER, $COURSE;
  3654. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3655. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3656. $totais = array();
  3657. $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 "
  3658. . " 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);
  3659. foreach($messages as $item) {
  3660. if (isset($totais[$item->subid])) {
  3661. $totais[$item->subid]->total++;
  3662. }
  3663. else {
  3664. $totais[$item->subid] = new stdclass();
  3665. $item->total = 1;
  3666. $totais[$item->subid] = $item;
  3667. }
  3668. }
  3669. return $totais;
  3670. }
  3671. else {
  3672. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3673. $totais = array();
  3674. $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 "
  3675. . " 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);
  3676. foreach($messages as $item) {
  3677. if (isset($totais[$item->subid])) {
  3678. $totais[$item->subid]->total++;
  3679. }
  3680. else {
  3681. $totais[$item->subid] = new stdclass();
  3682. $item->total = 1;
  3683. $totais[$item->subid] = $item;
  3684. }
  3685. }
  3686. return $totais;
  3687. }
  3688. }
  3689. function view_notifications_teachers () {
  3690. global $OUTPUT, $USER, $DB;
  3691. $messages = $this->get_iassign_statement_messages();
  3692. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3693. // 1º. listar as mensagens recebidas no bloco atual:
  3694. $actual_block = $this->iassign->id;
  3695. $id = $this->cm->id;
  3696. $total_include = 0;
  3697. $activities_actual_block = array();
  3698. if ($messages)
  3699. foreach ($messages as $item)
  3700. if ($item->iasid == $actual_block)
  3701. if (!in_array($item->stid, $activities_actual_block))
  3702. array_push($activities_actual_block, $item->stid);
  3703. if ($activities_actual_block)
  3704. foreach ($activities_actual_block as $activity_id) {
  3705. $printed = false;
  3706. foreach ($messages as $item) {
  3707. if ($item->stid == $activity_id) {
  3708. if (!$printed) {
  3709. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3710. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3711. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3712. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3713. $printed = true;
  3714. }
  3715. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3716. $user = $DB->get_record('user', array('id' => $item->user));
  3717. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3718. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3719. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3720. '<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>'
  3721. .'</tr>';
  3722. $total_include++;
  3723. }
  3724. }
  3725. print '</td></tr></table>';
  3726. }
  3727. print '</table>';
  3728. if (count($activities_actual_block) == 0) {
  3729. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3730. print '<hr class="my-4">';
  3731. }
  3732. if ($messages && $total_include == count($messages)) {
  3733. print $OUTPUT->footer();
  3734. return;
  3735. }
  3736. 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>';
  3737. $iassign_ids = array();
  3738. if ($messages)
  3739. foreach ($messages as $item)
  3740. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3741. array_push($iassign_ids, $item->iasid);
  3742. foreach ($iassign_ids as $id_iassign) {
  3743. $printed = false;
  3744. $activities_in_block = array();
  3745. foreach ($messages as $subitem)
  3746. if ($subitem->iasid == $id_iassign)
  3747. if (!in_array($item->stid, $activities_in_block))
  3748. array_push($activities_in_block, $item->stid);
  3749. foreach ($messages as $item) {
  3750. if ($item->iasid == $id_iassign) {
  3751. if (!$printed) {
  3752. $printed = true;
  3753. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3754. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3755. }
  3756. foreach ($activities_in_block as $id_activity) {
  3757. $print = false;
  3758. foreach ($messages as $subitem) {
  3759. if ($subitem->stid == $id_activity) {
  3760. if (!$print) {
  3761. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3762. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3763. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3764. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3765. $print = true;
  3766. }
  3767. foreach ($messages as $comment_student) {
  3768. if ($comment_student->stid == $id_activity) {
  3769. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3770. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3771. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3772. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3773. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3774. '<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>'
  3775. .'</tr>';
  3776. }
  3777. }
  3778. break;
  3779. }
  3780. }
  3781. }
  3782. print '</table></td></tr></table>';
  3783. break;
  3784. }
  3785. }
  3786. }
  3787. print $OUTPUT->footer();
  3788. }
  3789. function view_notifications () {
  3790. global $OUTPUT, $USER;
  3791. print $OUTPUT->header();
  3792. $this->print_main_menu();
  3793. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3794. if ($this->get_total_notifications() == 0) {
  3795. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3796. print '<hr class="my-4">';
  3797. print $OUTPUT->footer();
  3798. return;
  3799. }
  3800. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3801. $this->view_notifications_teachers();
  3802. return;
  3803. }
  3804. $messages = $this->get_iassign_statement_messages();
  3805. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3806. // 1º. listar as mensagens recebidas no bloco atual:
  3807. $actual_block = $this->iassign->id;
  3808. $id = $this->cm->id;
  3809. $total_include = 0;
  3810. if ($messages)
  3811. foreach ($messages as $item) {
  3812. if ($item->iasid == $actual_block) {
  3813. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3814. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3815. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3816. 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>';
  3817. $total_include++;
  3818. }
  3819. }
  3820. print '</table>';
  3821. if ($total_include == 0) {
  3822. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3823. print '<hr class="my-4">';
  3824. }
  3825. if ($messages && $total_include == count($messages)) {
  3826. print $OUTPUT->footer();
  3827. return;
  3828. }
  3829. 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>';
  3830. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3831. $iassign_ids = array();
  3832. if ($messages)
  3833. foreach ($messages as $item)
  3834. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3835. array_push($iassign_ids, $item->iasid);
  3836. foreach ($iassign_ids as $id_iassign) {
  3837. $printed = false;
  3838. foreach ($messages as $item) {
  3839. if ($item->iasid == $id_iassign) {
  3840. if (!$printed) {
  3841. $printed = true;
  3842. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3843. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3844. }
  3845. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3846. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3847. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3848. 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>';
  3849. }
  3850. }
  3851. print '</table>';
  3852. }
  3853. print $OUTPUT->footer();
  3854. }
  3855. function print_main_menu () {
  3856. global $USER;
  3857. $id = $this->cm->id;
  3858. $actual_action = optional_param('action', '', PARAM_TEXT);
  3859. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3860. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3861. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3862. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3863. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3864. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3865. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3866. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3867. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3868. $url_import_activity = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'import_activity', 'iassignid' => $this->iassign->id));
  3869. print '<div class="btn-group" role="group" aria-label="">';
  3870. print '<a href="' . $url_home . '" class="btn btn-outline-primary ' . ($actual_action == '' ? 'active' : '') . '">' . "\n";
  3871. print ' <i class="fa fa-home" aria-hidden="true"></i> ' . get_string('activities_page', 'iassign') . "</a>\n";
  3872. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3873. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3874. // Has capability to see "report": teacher or up
  3875. 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>';
  3876. print '<div class="btn-group"><div class="btn-group">
  3877. <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">
  3878. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3879. <div class="dropdown-menu">
  3880. <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>
  3881. <div class="dropdown-divider"></div>
  3882. <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>
  3883. <div class="dropdown-divider"></div>
  3884. <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>
  3885. </div>
  3886. </div>
  3887. '; // "
  3888. 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>';
  3889. 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>';
  3890. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3891. $notifications = $this->get_total_notifications();
  3892. print '<a href="' . $url_notifications . '" class="btn btn-outline-primary ' . ($actual_action == 'notifications' ? 'active' : '') . '">' . "\n"; // '
  3893. print ' <i class="fa fa-bell" aria-hidden="true"></i> ' . get_string('notifications', 'iassign');
  3894. if ($notifications > 0)
  3895. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3896. print '</a></div><div class="btn-group">';
  3897. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3898. 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";
  3899. print '
  3900. <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  3901. </button>
  3902. <div class="dropdown-menu">
  3903. <a class="dropdown-item" href="' . $url_import_activity . '">' . get_string('import_activity', 'iassign') . '</a>
  3904. </div>'; // "
  3905. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3906. print '</div></div>' . "\n";
  3907. }
  3908. /// Display page of iAssign's block of activities
  3909. function view_iassigns () {
  3910. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3911. $id = $this->cm->id;
  3912. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3913. $notice = optional_param('notice', '', PARAM_TEXT);
  3914. if (strpos($notice, 'error'))
  3915. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3916. else if ($notice != '')
  3917. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3918. $this->print_main_menu(); // teachers' menu: Page of activities; About iLM; Report; Results; Reevaluation; Notifications
  3919. print $OUTPUT->box_start();
  3920. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3921. print '<div class="border float-right">' . "\n";
  3922. if ($iassign_list) {
  3923. // $USER->iassignEdit == 0 view 'Turn editing off'
  3924. // $USER->iassignEdit == 1 view 'Turn editing on'
  3925. if (!isset($USER->iassignEdit))
  3926. $USER->iassignEdit = 0;
  3927. if ($USER->iassignEdit == 0) {
  3928. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3929. $botton = 1;
  3930. }
  3931. elseif ($USER->iassignEdit == 1) {
  3932. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3933. $botton = 0;
  3934. }
  3935. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3936. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3937. print " <input class='btn btn-primary' type=submit value='" . $bottonEdit_message . "'/>\n";
  3938. print "</form>\n";
  3939. } // if ($iassign_list)
  3940. print "</div>\n";
  3941. }
  3942. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3943. // $this->view_legend_icons();
  3944. print $OUTPUT->box_end();
  3945. $iassign_array_exercise = array();
  3946. $i_exercise = 0; // count total number of activities of type 'exercise' inside the block
  3947. $iassign_array_test = array();
  3948. $i_test = 0; // count total number of activities of type 'test' inside the block
  3949. $iassign_array_example = array();
  3950. $i_example = 0; // count total number of activities of type 'example' inside the block
  3951. $iassign_array_general = array();
  3952. $i_general = 0;
  3953. if ($iassign_list) {
  3954. if ($this->iassign->activity_group == 0) {
  3955. foreach ($iassign_list as $iassign) {
  3956. $iassign_array_general[$i_general] = $iassign;
  3957. $i_general++;
  3958. }
  3959. } // if ($this->iassign->activity_group == 0)
  3960. else {
  3961. foreach ($iassign_list as $iassign) {
  3962. if ($iassign->type_iassign == 3) {
  3963. $iassign_array_exercise[$i_exercise] = $iassign;
  3964. $i_exercise++;
  3965. } // if ($iassign->type_iassign == 3)
  3966. if ($iassign->type_iassign == 2) {
  3967. $iassign_array_test[$i_test] = $iassign;
  3968. $i_test++;
  3969. } // if ($iassign->type_iassign == 2)
  3970. if ($iassign->type_iassign == 1) {
  3971. $iassign_array_example[$i_example] = $iassign;
  3972. $i_example++;
  3973. } // if ($iassign->type_iassign == 1)
  3974. }
  3975. }
  3976. if ($iassign_array_exercise) {
  3977. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3978. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3979. }
  3980. if ($iassign_array_test) {
  3981. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3982. $this->show_iassign($title, $iassign_array_test, $i_test);
  3983. }
  3984. if ($iassign_array_example) {
  3985. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3986. $this->show_iassign($title, $iassign_array_example, $i_example);
  3987. }
  3988. if ($iassign_array_general) {
  3989. $title = "";
  3990. $this->show_iassign($title, $iassign_array_general, $i_general);
  3991. }
  3992. } else { // if ($iassign_list)
  3993. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3994. }
  3995. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3996. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3997. print $OUTPUT->box_start();
  3998. print '<table width=100% border=0><tr>' . "\n";
  3999. print '<td width=10% align="left">' . "\n";
  4000. print $link_report;
  4001. print '</td>' . "\n";
  4002. print '</tr></table>' . "\n";
  4003. print $OUTPUT->box_end();
  4004. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4005. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  4006. print $OUTPUT->box_start();
  4007. print '<table width=100% border=0><tr>' . "\n";
  4008. print '<td align="left">' . "\n";
  4009. print $link_add;
  4010. print '</td>' . "\n";
  4011. print '</tr></table>' . "\n";
  4012. print $OUTPUT->box_end();
  4013. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4014. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  4015. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4016. // $this->view_legend_icons();
  4017. } // function view_iassigns()
  4018. /// Display all iAssigns: the list of activities inside the iAssign block
  4019. // HTTP: ./mod/iassign/view.php?id= <$id>
  4020. function show_iassign ($title, $iassign_array, $total_of_activities) {
  4021. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  4022. $id = $this->cm->id; // ID of iAssign block (accessed throgh table "couse_module")
  4023. print $OUTPUT->box_start();
  4024. print " <script type='text/javascript'>
  4025. //<![CDATA[
  4026. function validate_move () {
  4027. var radios = document.getElementsByName('iassign_destiny');
  4028. var formValid = false;
  4029. //alert('aqui validate_move()');
  4030. var i = 0;
  4031. while (!formValid && i < radios.length) {
  4032. if (radios[i].checked) formValid = true;
  4033. i++;
  4034. }
  4035. if (!formValid) {
  4036. document.getElementById('move_dest').classList.add('alert-danger');
  4037. }
  4038. return formValid;
  4039. }
  4040. var modal;
  4041. function load_move(id_ias) {
  4042. document.form_move_activity.iassign_current.value = id_ias;
  4043. modal.style.display = 'block';
  4044. var radios = document.getElementsByName('iassign_destiny');
  4045. var i = 0;
  4046. while (i < radios.length) {
  4047. radios[i].checked = false;
  4048. i++;
  4049. }
  4050. document.getElementById('move_dest').classList.remove('alert-danger');
  4051. }
  4052. function closeModal () {
  4053. modal.style.display = 'none';
  4054. }
  4055. function load_modal_elements () {
  4056. modal = document.getElementById('myModal');
  4057. var span = document.getElementById('close_modal');
  4058. span.onclick = function() {
  4059. modal.style.display = 'none';
  4060. }
  4061. window.onclick = function(event) {
  4062. if (event.target == modal) {
  4063. modal.style.display = 'none';
  4064. }
  4065. }
  4066. }
  4067. window.onload = load_modal_elements;
  4068. //]]>
  4069. </script>\n";
  4070. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  4071. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  4072. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  4073. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  4074. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  4075. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  4076. <input type='hidden' name='iassign_current' value='' />";
  4077. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  4078. $section = $course_sections[0];
  4079. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  4080. for ($k = 0; $k < count($ids_sections); $k++) {
  4081. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  4082. for ($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  4083. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  4084. if ($c_cm) {
  4085. if ($ccm->instance == $c_cm->instance) {
  4086. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4087. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4088. }
  4089. else {
  4090. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  4091. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  4092. }
  4093. }
  4094. }
  4095. $radio_buttons .= "</ul>";
  4096. }
  4097. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  4098. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  4099. </form>
  4100. </div></div> </div></div>\n";
  4101. print " <style>.modal {
  4102. display: none;
  4103. position: fixed;
  4104. z-index: 1;
  4105. left: 0;
  4106. top: 0;
  4107. width: 100%;
  4108. height: 100%;
  4109. overflow: scroll;
  4110. background-color: rgb(0,0,0);
  4111. background-color: rgba(0,0,0,0.4);
  4112. }
  4113. .modal-content {
  4114. background-color: #fefefe;
  4115. margin: 15% auto;
  4116. padding: 10px 10px;
  4117. border: 1px solid #888;
  4118. width: 50%;
  4119. }
  4120. #close_modal {
  4121. color: #aaa;
  4122. float: right;
  4123. font-size: 28px;
  4124. font-weight: bold;
  4125. margin-top: -15px;
  4126. margin-right: -3px;
  4127. }
  4128. #close_modal:hover,
  4129. #close_modal:focus {
  4130. color: black;
  4131. text-decoration: none;
  4132. cursor: pointer;
  4133. }
  4134. #modal_title {
  4135. min-height: 3rem;
  4136. color: initial;
  4137. background: initial;
  4138. font-size: 1.5rem;
  4139. line-height: 1.5;
  4140. padding: 15px;
  4141. border-bottom: 1px solid #e5e5e5;
  4142. }
  4143. .input_move {
  4144. width: 90%;
  4145. padding: 2px;
  4146. }
  4147. .input_move:hover {
  4148. background: #eff0ef;
  4149. }
  4150. </style>";
  4151. $action_links = "";
  4152. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4153. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4154. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4155. for ($j=0; $j<$total_of_activities; $j++) {
  4156. $iassign_current = $iassign_array[$j]->id;
  4157. // receiver=1 - message to teacher
  4158. // receiver=2 - message to student
  4159. $sum_comment = 0;
  4160. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4161. foreach ($iassign_submissions as $iassign_submission) {
  4162. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4163. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4164. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4165. if ($verify_message)
  4166. foreach ($verify_message as $tmp)
  4167. $sum_comment += $tmp;
  4168. } // foreach ($iassign_submissions as $iassign_submission)
  4169. if ($sum_comment == 0)
  4170. $comment_unread = "";
  4171. else {
  4172. $comment_unread_message = get_string('comment_unread', 'iassign');
  4173. if ($sum_comment == 1)
  4174. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4175. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '">' .
  4176. ' <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 .
  4177. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . '</span> </span></a>' . "\n";
  4178. }
  4179. if ($j == $total_of_activities - 1)
  4180. $iassign_down = $iassign_array[$j]->id;
  4181. else
  4182. $iassign_down = $iassign_array[$j + 1]->id;
  4183. if ($j > 0)
  4184. $iassign_up = $iassign_array[$j - 1]->id;
  4185. else
  4186. $iassign_up = $iassign_array[$j]->id;
  4187. if ($iassign_array[$j]->visible == 0)
  4188. $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";
  4189. else
  4190. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4191. $links .= $comment_unread;
  4192. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4193. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>\n";
  4194. $str_aux = "&id=" . $id . "&iassign_current=" . $iassign_current . "&iassign_up=" . $iassign_up . "&iassign_down=" . $iassign_down;
  4195. $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";
  4196. if ($j==0) // first activity
  4197. $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";
  4198. else
  4199. $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";
  4200. $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";
  4201. $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";
  4202. $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";
  4203. $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";
  4204. $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";
  4205. $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";
  4206. if (count($iassign_array) > 1) {
  4207. if ($j == 0)
  4208. $action_links .= $link_down;
  4209. elseif ($j == $total_of_activities - 1)
  4210. $action_links .= $link_up;
  4211. else
  4212. $action_links .= $link_up . $link_down;
  4213. } // if (count($iassign_array) > 1)
  4214. $action_links .= $link_edit . $link_delete;
  4215. if ($iassign_array[$j]->visible == 0)
  4216. $action_links .= $link_visible_show;
  4217. else
  4218. $action_links .= $link_visible_hide;
  4219. $action_links .= $link_duplicate_activity . $link_move_activity;
  4220. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4221. $action_links .= "</ul></nav>\n";
  4222. 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";
  4223. } // for ($j=0; $j<$total_of_activities; $j++)
  4224. print "</tbody></table>\n";
  4225. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4226. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4227. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>\n";
  4228. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">' . "\n";
  4229. $corect_position = 1; //EXTRA: to detect (and fix it) 'iassign_statement.position' errors
  4230. for ($j=0; $j<$total_of_activities; $j++) {
  4231. if ($iassign_array[$j]->position!=$corect_position) { // ops, the current 'position' is wrong, fix it!
  4232. activity::move_change_activity_position($DB, $iassign_array[$j]->id, $iassign_array[$j]->id, $corect_position, $corect_position);
  4233. }
  4234. $corect_position++;
  4235. }
  4236. for ($j=0; $j<$total_of_activities; $j++) {
  4237. $icon_status = "";
  4238. $icon_comment = "";
  4239. if ($iassign_array[$j]->visible == 1) {
  4240. $iassign_current = $iassign_array[$j]->id;
  4241. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4242. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4243. $icon_status = "";
  4244. $icon_comment = "";
  4245. if ($iassign_submission) {
  4246. // receiver=1 - message to teacher
  4247. // receiver=2 - message to student
  4248. // $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");
  4249. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4250. $verify_message = $DB->get_record_sql(
  4251. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4252. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4253. if ($verify_message)
  4254. foreach ($verify_message as $tmp)
  4255. $sum_comment = $tmp;
  4256. if ($sum_comment > 0) {
  4257. $comment_unread_message = get_string('comment_unread', 'iassign');
  4258. if ($sum_comment == 1)
  4259. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4260. $icon_comment = "<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "#comments'>\n" .
  4261. ' <span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . "\n" .
  4262. ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">' . $sum_comment . "</span> </span></a>\n";
  4263. }
  4264. // $icon_comment = iassign_icons::insert('comment_unread');
  4265. if ($iassign_array[$j]->type_iassign == 3) {
  4266. if ($iassign_array[$j]->show_answer == 1) {
  4267. if ($iassign_submission->status == 3)
  4268. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('correct', 'iassign') . '"></i>' . "\n";
  4269. elseif ($iassign_submission->status == 2)
  4270. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('incorrect', 'iassign') . '"></i>' . "\n";
  4271. elseif ($iassign_submission->status == 1)
  4272. $icon_status = '<i class="fa fa-question" style="color: #77229; font-size: 1.2rem;" aria-hidden="true" title="' . get_string('post', 'iassign') . '"></i>' . "\n";
  4273. //2021/12 $icon_status = iassign_icons::insert('post');
  4274. elseif ($iassign_submission->status == 0)
  4275. $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";
  4276. } // if ($iassign_array[$j]->show_answer==1)
  4277. else {
  4278. if ($iassign_submission->status == 0) {
  4279. //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";
  4280. $icon_status = iassign_icons::insert('not_post');
  4281. }
  4282. else {
  4283. //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";
  4284. $icon_status = iassign_icons::insert('post');
  4285. }
  4286. }
  4287. } // if ($iassign_array[$j]->type_iassign == 3)
  4288. } // if ($iassign_submission)
  4289. elseif ($iassign_array[$j]->type_iassign == 3) {
  4290. $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";
  4291. //2021/12 $icon_status = iassign_icons::insert('not_post');
  4292. } // if ($iassign_array[$j]->type_iassign == 3)
  4293. 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;">'
  4294. . $links . '</td><td>' . $icon_comment . '</td></tr>' . "\n";
  4295. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4296. } // if ($iassign_array[$j]->visible == 1)
  4297. } // for ($j=0; $j<$total_of_activities; $j++)
  4298. print "</table>\n";
  4299. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  4300. else if (isguestuser()) {
  4301. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4302. print '<table width=100% ><tr>' . "\n";
  4303. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4304. print '</tr></table>' . "\n";
  4305. for ($j=0; $j<$total_of_activities; $j++) {
  4306. $icon_status = "";
  4307. $icon_comment = "";
  4308. if ($iassign_array[$j]->visible == 1) {
  4309. $iassign_current = $iassign_array[$j]->id;
  4310. $links = "&nbsp;<a href='view.php?id=" . $id . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_current . "'>" . $iassign_array[$j]->name . "</a>\n";
  4311. print '<p>' . $links . '</p>' . "\n";
  4312. } // if ($iassign_array[$j]->visible == 1)
  4313. }
  4314. }
  4315. print $OUTPUT->box_end();
  4316. } // function show_iassign($title, $iassign_array, $total_of_activities)
  4317. /// Show message of return
  4318. function return_home_course ($message) {
  4319. //D global $DB, $OUTPUT;
  4320. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4321. //D echo $OUTPUT->box_start();
  4322. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4323. //D echo '<tr><td align="left"><strong>' . "\n";
  4324. //D print_string($message, 'iassign');
  4325. //D echo '</strong></td>' . "\n";
  4326. //D echo '<td width=20% align="right">' . "\n";
  4327. //D echo $link_return;
  4328. //D echo '</td></tr></table>' . "\n";
  4329. //D echo $OUTPUT->box_end();
  4330. //D // echo $OUTPUT->footer();
  4331. redirect(new moodle_url($this->return . '&notice=' . $message));
  4332. exit;
  4333. }
  4334. /// Search comment of activity
  4335. function search_comment_submission ($iassign_submissionid) {
  4336. global $USER, $DB, $OUTPUT, $COURSE;
  4337. // $context = context_course::instance($COURSE->id);
  4338. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4339. $colorEdit2 = "#d2e5fc";
  4340. $has_capability = 0;
  4341. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4342. $text = "";
  4343. if ($comments) {
  4344. $even = 1;
  4345. foreach ($comments as $tmp) {
  4346. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4347. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4348. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4349. // $text .= $tmp->comment . "</td></tr>";
  4350. //} else {
  4351. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4352. $avatar = new user_picture($user_data);
  4353. $avatar->courseid = $COURSE->id;
  4354. $avatar->link = true;
  4355. $user_picture = $OUTPUT->render($avatar);
  4356. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4357. if ($even) {
  4358. $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";
  4359. $even = 0;
  4360. } else {
  4361. $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";
  4362. $even = 1;
  4363. }
  4364. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4365. } // foreach ($comments as $tmp)
  4366. }
  4367. return $text;
  4368. }
  4369. /// Update comment of activity
  4370. function update_comment ($iassign_submissionid) {
  4371. global $USER, $DB, $OUTPUT;
  4372. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4373. $receiver = 1; // student message to teacher
  4374. else
  4375. $receiver = 2; // teacher message to student
  4376. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4377. if ($verify_message) {
  4378. foreach ($verify_message as $message) {
  4379. if ($message->receiver == $receiver) {
  4380. $newentry = new stdClass();
  4381. $newentry->id = $message->id;
  4382. $newentry->return_status = 1;
  4383. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4384. print_error('error_update', 'iassign');
  4385. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4386. } // if ($message->receiver == $receiver)
  4387. // Trigger module viewed event.
  4388. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4389. 'objectid' => $this->iassign->id,
  4390. 'context' => $this->context
  4391. ));
  4392. $event->add_record_snapshot('course', $this->course);
  4393. $event->trigger();
  4394. } // foreach ($verify_message as $message)
  4395. }
  4396. }
  4397. /// Record comment of activity
  4398. function write_comment_submission () {
  4399. global $USER, $CFG, $DB;
  4400. $id = $this->cm->id;
  4401. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4402. $row = optional_param('row', 0, PARAM_INT);
  4403. $column = optional_param('column', 0, PARAM_INT);
  4404. $sum_comment = 0;
  4405. $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);
  4406. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4407. $str1 = trim($submission_comment);
  4408. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4409. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4410. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4411. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4412. $receiver = 1; // student message to teacher
  4413. $this->action = 'view';
  4414. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4415. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4416. } else {
  4417. $receiver = 2; // teacher message to student
  4418. $this->action = 'viewsubmission';
  4419. //D $tousers = array(); //MOOC 2016
  4420. //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
  4421. }
  4422. //MOOC 2016: foi p/ 15 linhas acima:
  4423. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4424. // verificar se existe uma submissão para o exercício e aluno informados
  4425. if (!$iassign_submission) {
  4426. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4427. }
  4428. if (!$iassign_submission) {
  4429. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4430. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4431. $this->iassign_submission_current = $id_submission;
  4432. }
  4433. else {
  4434. $id_submission = $iassign_submission->id;
  4435. } // if (!$iassign_submission)
  4436. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4437. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4438. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4439. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4440. $comments = $DB->get_record_sql(
  4441. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4442. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4443. if ($comments)
  4444. foreach ($comments as $tmp)
  4445. $sum_comment = $tmp;
  4446. if ($sum_comment == 0) {
  4447. $newentry = new stdClass();
  4448. $newentry->iassign_submissionid = $id_submission;
  4449. $newentry->comment_authorid = $USER->id;
  4450. $newentry->timecreated = time();
  4451. $newentry->comment = $submission_comment;
  4452. $newentry->receiver = $receiver;
  4453. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4454. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  4455. // Trigger module viewed event
  4456. $event = \mod_iassign\event\submission_comment_created::create(array(
  4457. 'objectid' => $this->iassign->id,
  4458. 'context' => $this->context
  4459. ));
  4460. $event->add_record_snapshot('course', $this->course);
  4461. $event->trigger();
  4462. }
  4463. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4464. // if ($this->action=='viewsubmission') {
  4465. // echo $OUTPUT->header();
  4466. // $this->return_last('confirm_add_comment', $link_return);
  4467. // die;
  4468. // }
  4469. return true;
  4470. } // function write_comment_submission()
  4471. /// Writes a new submission
  4472. // The first student answer is under 'function get_answer()'
  4473. function new_submission ($iassignid, $id_user, $receiver) {
  4474. global $USER, $DB, $OUTPUT;
  4475. $newentry = new stdClass();
  4476. $newentry->iassign_statementid = $iassignid;
  4477. $newentry->userid = $id_user;
  4478. $newentry->timecreated = time();
  4479. $newentry->timemodified = time();
  4480. $newentry->answer = 0; // student only submit message
  4481. if ($receiver == 2) // teacher message to student (write id teacher)
  4482. $newentry->teacher = $USER->id;
  4483. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4484. return_home_course('error_insert_submissions');
  4485. else {
  4486. // Trigger module view event
  4487. $event = \mod_iassign\event\submission_created::create(array(
  4488. 'objectid' => $this->iassign->id,
  4489. 'context' => $this->context
  4490. ));
  4491. $event->add_record_snapshot('course', $this->course);
  4492. $event->trigger();
  4493. }
  4494. return $newentry->id;
  4495. }
  4496. /// Return to a specific address of page
  4497. function return_last ($message, $link_return) {
  4498. global $DB, $OUTPUT;
  4499. print $OUTPUT->box_start();
  4500. print '<table width=100% border=0 valign="top">' . "\n";
  4501. print '<tr><td align="left"><strong>' . "\n";
  4502. print_string($message, 'iassign');
  4503. print '</strong></td>' . "\n";
  4504. print '<td width=20% align="right">' . "\n";
  4505. print $link_return;
  4506. print '</td></tr></table>' . "\n";
  4507. print $OUTPUT->box_end();
  4508. print $OUTPUT->footer();
  4509. die();
  4510. } // function return_last($message, $link_return)
  4511. } // class iassign
  4512. /// Class for manage activities
  4513. class activity {
  4514. var $activity;
  4515. /// Constructor of class.
  4516. // @param int $id Id of activity
  4517. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4518. //D public function activity($id) { self::__construct($id); }
  4519. function __construct ($id) {
  4520. global $DB;
  4521. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4522. if (empty($this->activity))
  4523. $this->activity = null;
  4524. }
  4525. /// Get an activity
  4526. // @return NULL
  4527. function get_activity () {
  4528. if ($this->activity != null)
  4529. return $this->activity;
  4530. else
  4531. return null;
  4532. }
  4533. /// Delete interactive activities
  4534. function delete ($return) {
  4535. global $USER, $CFG, $DB, $OUTPUT;
  4536. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4537. print $OUTPUT->header();
  4538. $output .= $OUTPUT->box_start();
  4539. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4540. if ($iassign_submission_currents) {
  4541. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4542. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4543. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4544. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4545. $output .= $OUTPUT->box_end();
  4546. $output .= $OUTPUT->footer();
  4547. print $output;
  4548. die();
  4549. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4550. } // if ($iassign_submission_currents)
  4551. else
  4552. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>\n";
  4553. $output .= '<table width=50% border=0>';
  4554. $output .= '<tr valign="top"><td>';
  4555. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>\n";
  4556. $output .= '</td><td>';
  4557. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4558. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4559. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>\n";
  4560. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4561. $output .= "</form>\n";
  4562. $output .= '</td><td>';
  4563. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4564. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4565. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4566. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4567. $output .= "</form>\n";
  4568. $output .= '</td></tr></table>' . "\n";
  4569. $output .= $OUTPUT->box_end();
  4570. $output .= $OUTPUT->footer();
  4571. print $output;
  4572. } // function delete($return)
  4573. /// Function for confirm the delete of activity
  4574. // @param String $return Url of return
  4575. // @param Object $iassign Object content an activity
  4576. function deleteyes ($return, $iassign) {
  4577. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4578. $msg = '';
  4579. if (!empty($this->activity->id)) {
  4580. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4581. if ($iassign_submission_currents) {
  4582. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4583. foreach ($iassign_submission_currents as $iassign_submission)
  4584. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4585. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4586. } // if ($iassign_submission_currents)
  4587. }
  4588. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4589. // Remove all files associated to this activity:
  4590. $fs = get_file_storage();
  4591. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4592. $this->delete_calendar($this->activity->id);
  4593. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4594. iassign::update_grade_iassign($this->activity->iassignid);
  4595. if ($delete_iassign_current) {
  4596. $iassign->return_home_course('confirm_delete_iassign');
  4597. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4598. } else {
  4599. $iassign->return_home_course('error_confirm_delete_iassign');
  4600. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4601. }
  4602. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4603. }
  4604. } // function deleteyes($return, $iassign)
  4605. /// Change fields 'iassign_statement.position' between 2 activities
  4606. // @calledby : class this->move_iassign($move_action, $target, $return)
  4607. // @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})
  4608. static function move_change_activity_position ($DB, $idFrom, $idTo, $posFrom, $posTo) { //1
  4609. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4610. $newentry->id = $idFrom; // ID of the "source activity" //1 $this->activity->id -> $idFrom
  4611. $newentry->position = $posFrom; // final position to source //1 $final_position_source -> $posFrom
  4612. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4613. print_error('error_update_move_iassign', 'iassign');
  4614. }
  4615. else if ($idFrom != $idTo) { // first update performed successfully - change second only if they are different
  4616. $newentry->id = $idTo; //1 $iassign_target->id -> $idTo
  4617. $newentry->position = $posTo; //1 $final_position_target -> $posTo
  4618. if (!$DB->update_record('iassign_statement', $newentry))
  4619. print_error('error_update_move_iassign', 'iassign');
  4620. }
  4621. }
  4622. /// Changes position of activities (between those inside a group of interactive activities)
  4623. // @param $move_action = must be "up" or "down"
  4624. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4625. function move_iassign ($move_action, $target, $return) {
  4626. global $DB, $OUTPUT;
  4627. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4628. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4629. if ($move_action=="firstdown") {
  4630. $final_position_source = 2;
  4631. $final_position_target = 1;
  4632. }
  4633. else
  4634. if ($move_action=="down") {
  4635. $final_position_target = $this->activity->position;
  4636. $final_position_source = $final_position_target + 1;
  4637. }
  4638. else
  4639. if ($move_action=="up") {
  4640. $final_position_target = $this->activity->position;
  4641. $final_position_source = $final_position_target - 1;
  4642. }
  4643. else { // error:
  4644. print_error('error_update_move_iassign', 'iassign');
  4645. exit;
  4646. }
  4647. activity::move_change_activity_position($DB, $this->activity->id, $iassign_target->id, $final_position_source, $final_position_target); // efectively exchange 'position'
  4648. redirect($return);
  4649. } // function move_iassign($move_action, $target, $return)
  4650. /// Enable or disable the display of interactive activities
  4651. function visible_iassign ($return) {
  4652. global $DB;
  4653. $newentry = new stdClass();
  4654. $newentry->id = $this->activity->id;
  4655. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4656. if (!$DB->update_record('iassign_statement', $newentry))
  4657. print_error('error_update_visible_iassign', 'iassign');
  4658. redirect($return);
  4659. }
  4660. /// Add news interactive activities (register in table 'iassign_statement')
  4661. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4662. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4663. function new_iassign ($param) {
  4664. global $DB;
  4665. $newentry = new stdClass();
  4666. $newentry->iassignid = $param->iassignid;
  4667. $newentry->name = $param->name;
  4668. $newentry->type_iassign = $param->type_iassign;
  4669. if (!isset($param->store_all_submissions)) { // if is an old acitivity, field 'store_all_submissions' is not defined
  4670. $newentry->store_all_submissions = 0;
  4671. }
  4672. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4673. $proposition = $param->proposition;
  4674. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4675. else $proposition_text = $proposition;
  4676. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4677. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4678. //TODO Then get it directly from the form data $_POST!
  4679. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4680. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4681. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4682. $newentry->author_name = $param->author_name;
  4683. $newentry->author_modified_name = $param->author_modified_name;
  4684. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4685. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4686. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4687. $newentry->grade = $param->grade;
  4688. $newentry->timemodified = time();
  4689. $newentry->timecreated = time();
  4690. if ($param->type_iassign == 1) {
  4691. $newentry->timedue = 0;
  4692. $newentry->timeavailable = 0;
  4693. } // if ($param->type_iassign == 1)
  4694. else {
  4695. $newentry->timedue = $param->timedue;
  4696. $newentry->timeavailable = $param->timeavailable;
  4697. }
  4698. $newentry->preventlate = $param->preventlate;
  4699. $newentry->test = $param->test;
  4700. $newentry->special_param1 = $param->special_param1;
  4701. $newentry->visible = $param->visible;
  4702. $newentry->position = $param->position;
  4703. $newentry->max_experiment = $param->max_experiment;
  4704. $newentry->dependency = $param->dependency;
  4705. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4706. $newentry->show_answer = $param->show_answer;
  4707. $id = $DB->insert_record("iassign_statement", $newentry);
  4708. if ($id) {
  4709. $component = 'mod_iassign';
  4710. $filearea = 'exercise';
  4711. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4712. $file = $fs->get_file_by_id($param->file);
  4713. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4714. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4715. //$itemid = $id;
  4716. // File already inserted in other context!
  4717. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4718. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4719. $updateentry = new stdClass();
  4720. $updateentry->id = $id;
  4721. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4722. $updateentry->filesid = $newfile->get_itemid();
  4723. if (!$DB->update_record("iassign_statement", $updateentry))
  4724. print_error('error_add', 'iassign');
  4725. if ($param->type_iassign == 3)
  4726. iassign::update_grade_iassign($param->iassignid);
  4727. //TODO iLM_HTML5 :: //MOOC2014
  4728. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4729. //D if ($iassign_ilm_configs) {
  4730. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4731. //D if ($iassign_ilm_config->param_type != 'static') {
  4732. //D $newentry = new stdClass();
  4733. //D $newentry->iassign_statementid = $id;
  4734. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4735. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4736. //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});
  4737. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4738. //D print_error('error_add_param', 'iassign');
  4739. //D }
  4740. //D }
  4741. //D }
  4742. // log event --------------------------------------------------------------------------------------
  4743. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4744. // log event --------------------------------------------------------------------------------------
  4745. return $id;
  4746. }
  4747. else
  4748. print_error('error_add', 'iassign');
  4749. } // function new_iassign($param)
  4750. /// Add the calendar entries for this iassign
  4751. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4752. // @return bool
  4753. static function add_calendar ($iassignid) {
  4754. global $DB, $CFG;
  4755. require_once($CFG->dirroot . '/calendar/lib.php');
  4756. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4757. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4758. $event = new stdClass();
  4759. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4760. $event->description = $iassign_statement_activity_item->name;
  4761. $event->courseid = $iassign->course;
  4762. $event->groupid = 0;
  4763. $event->userid = 0;
  4764. $event->modulename = 'iassign';
  4765. $event->instance = $iassign->id;
  4766. $event->eventtype = 'due';
  4767. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4768. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4769. calendar_event::create($event);
  4770. }
  4771. /// Update the calendar entries for this iassign
  4772. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4773. // @return bool
  4774. function update_calendar ($iassignid, $olddescription) {
  4775. global $DB, $CFG;
  4776. require_once($CFG->dirroot . '/calendar/lib.php');
  4777. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4778. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4779. $event = new stdClass();
  4780. $event->id = 0;
  4781. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4782. if ($events) {
  4783. foreach ($events as $value) {
  4784. if ($value->description == $olddescription) {
  4785. $event->id = $value->id;
  4786. }
  4787. }
  4788. }
  4789. if ($event->id != 0) {
  4790. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4791. $event->description = $iassign_statement_activity_item->name;
  4792. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4793. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4794. $calendarevent = calendar_event::load($event->id);
  4795. $calendarevent->update($event);
  4796. } else
  4797. $this->add_calendar($iassignid);
  4798. }
  4799. /// Update the calendar entries for this iassign
  4800. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4801. // @return bool
  4802. function delete_calendar ($iassignid) {
  4803. global $DB, $CFG;
  4804. require_once($CFG->dirroot . '/calendar/lib.php');
  4805. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4806. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4807. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4808. if ($events) {
  4809. foreach ($events as $value) {
  4810. if ($value->description == $iassign_statement_activity_item->name) {
  4811. $DB->delete_records('event', array('id' => $value->id));
  4812. }
  4813. }
  4814. }
  4815. }
  4816. /// Update interactive activities
  4817. function update_iassign ($param) {
  4818. global $DB;
  4819. $component = 'mod_iassign';
  4820. $filearea = 'exercise';
  4821. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4822. $file = $fs->get_file_by_id($param->file);
  4823. $fileold = $fs->get_file_by_id($param->fileold);
  4824. if ($param->file != $param->fileold) {
  4825. if ($fileold) {
  4826. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4827. foreach ($fileoldarea as $value) {
  4828. $value->delete();
  4829. }
  4830. }
  4831. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4832. $itemid = $file->get_itemid() + $param->iassign_id;
  4833. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4834. $param->file = $newfile->get_itemid();
  4835. }
  4836. else
  4837. $param->file = $file->get_itemid();
  4838. }
  4839. else {
  4840. $param->file = $file->get_itemid();
  4841. }
  4842. $newentry = new stdClass();
  4843. $newentry->id = $param->iassign_id;
  4844. $newentry->name = $param->name;
  4845. $newentry->type_iassign = $param->type_iassign;
  4846. if (!isset($param->store_all_submissions)) { // if is an old acitivity, field 'store_all_submissions' is not defined
  4847. $newentry->store_all_submissions = 0;
  4848. }
  4849. //2019 $newentry->proposition = $param->proposition;
  4850. $proposition = $param->proposition;
  4851. if (is_array($proposition))
  4852. $proposition_text = $proposition['text'];
  4853. else
  4854. $proposition_text = $proposition;
  4855. $newentry->proposition = $proposition_text;
  4856. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4857. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4858. $newentry->grade = $param->grade;
  4859. $newentry->author_modified_name = $param->author_modified_name;
  4860. $newentry->timemodified = time();
  4861. if ($param->type_iassign == 1) {
  4862. $newentry->timedue = 0;
  4863. $newentry->timeavailable = 0;
  4864. } // if ($param->type_iassign == 1)
  4865. else {
  4866. $newentry->timedue = $param->timedue;
  4867. $newentry->timeavailable = $param->timeavailable;
  4868. }
  4869. $newentry->preventlate = $param->preventlate;
  4870. $newentry->test = $param->test;
  4871. if (isset($param->special_param1))
  4872. $newentry->special_param1 = $param->special_param1;
  4873. else
  4874. $newentry->special_param1 = NULL;
  4875. $newentry->visible = $param->visible;
  4876. $newentry->max_experiment = $param->max_experiment;
  4877. $newentry->dependency = $param->dependency;
  4878. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4879. $newentry->show_answer = $param->show_answer;
  4880. if (!$DB->update_record("iassign_statement", $newentry))
  4881. print_error('error_update', 'iassign');
  4882. if ($param->type_iassign == 3) {
  4883. iassign::update_grade_iassign($param->iassignid);
  4884. }
  4885. //$id = $newentry->id; // MOOC 2016 --- inicio
  4886. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4887. //if ($iassign_activity_item_configs) {
  4888. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4889. // $newentry = new stdClass();
  4890. // $newentry->id = $iassign_activity_item_config->id;
  4891. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4892. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4893. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4894. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4895. // print_error('error_edit_param', 'iassign');
  4896. // }
  4897. // } // MOOC 2016 --- final
  4898. // log event --------------------------------------------------------------------------------------
  4899. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4900. // log event --------------------------------------------------------------------------------------
  4901. return $newentry->id;
  4902. // if ($param->type_iassign==3)
  4903. // $this->update_grade_iassign($param->iassignid);
  4904. } // function update_iassign($param)
  4905. /// Show information of activity
  4906. function show_info_iassign () {
  4907. global $DB, $OUTPUT;
  4908. $output = '';
  4909. if ($this->activity->type_iassign == 3) {
  4910. if ($this->activity->dependency == 0) {
  4911. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4912. } else {
  4913. $dependencys = explode(';', $this->activity->dependency);
  4914. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4915. foreach ($dependencys as $dependency) {
  4916. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4917. if ($dependencyiassign)
  4918. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4919. } // foreach ($dependencys as $dependency)
  4920. } // if ($iassign_statement_activity_item->dependency == 0)
  4921. if ($this->activity->max_experiment == 0)
  4922. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4923. else
  4924. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4925. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4926. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4927. $output .= $this->toggle_columns_script();
  4928. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4929. print $OUTPUT->box($output);
  4930. } // function show_info_iassign()
  4931. /// Provide script to toggle columns
  4932. static function toggle_columns_script () {
  4933. $output = "";
  4934. $output .= '<script>
  4935. function toLeft () {
  4936. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4937. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4938. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4939. document.getElementById("columnsbutton").style.color = "#1da075";
  4940. }
  4941. function toDefault () {
  4942. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4943. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4944. document.getElementById("fullscreen").style.marginTop = "0";
  4945. document.getElementById("columnsbutton").style.color = "#343a40";
  4946. }
  4947. var activate = false;
  4948. function toggleColumns () {
  4949. if (activate) {
  4950. activate = false;
  4951. toDefault();
  4952. } else {
  4953. activate = true;
  4954. toLeft();
  4955. }
  4956. }
  4957. </script>'; // '
  4958. $output .= '<span tabindex="0" data-toggle="tooltip" title="' . get_string('enable_disable_columns', 'iassign')
  4959. . '" 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";
  4960. return $output;
  4961. } // function write_comment_submission()
  4962. static function get_latest_array_item ($DB, $iassignid, $position) { //TODO: may be search for the greatest grade?
  4963. $iassign_statement = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'position' => $position));
  4964. $item = NULL;
  4965. foreach ($iassign_statement as $item) ; // get the last item!
  4966. if ($item) return $item; // return the last one
  4967. return NULL;
  4968. }
  4969. /// Shows date of opening and closing activities
  4970. function view_dates () {
  4971. global $USER, $CFG, $DB, $OUTPUT;
  4972. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4973. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4974. $status_iassign = "";
  4975. $status_iassign1 = "";
  4976. $status_iassign2 = "";
  4977. if ($this->activity->type_iassign == 1) // activity of type example
  4978. $type_iassign = get_string('example_iassign', 'iassign');
  4979. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4980. $type_iassign = get_string('test_iassign', 'iassign');
  4981. if ($this->activity->timeavailable > time()) {
  4982. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4983. } elseif ($this->activity->timedue < time()) {
  4984. $status_iassign = get_string('last_timedue', 'iassign');
  4985. }
  4986. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4987. $type_iassign = get_string('exercise_iassign', 'iassign');
  4988. if ($this->activity->timeavailable > time()) {
  4989. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4990. } elseif ($this->activity->timedue < time()) { // after delivery
  4991. $status_iassign = get_string('last_timedue', 'iassign');
  4992. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4993. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4994. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4995. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4996. if ($this->activity->test == 1) // allowed to test after of deadline
  4997. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4998. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4999. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  5000. } // elseif ($iassign_statement_activity_item->test == 0)
  5001. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  5002. } // elseif ($iassign_statement_activity_item->timedue < time())
  5003. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  5004. $output = '<table width=100% >' . "\n";
  5005. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  5006. $output .= '<tr>' . "\n";
  5007. //leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  5008. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  5009. //leo $output .= '<td width=80%>' . $type_iassign;
  5010. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  5011. // $output .= '</td>' . "\n";
  5012. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  5013. // Link (with icon) to report survey (to present all interactivy exercises inside this block)
  5014. $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>";
  5015. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  5016. }
  5017. else {
  5018. // Get all previous/next solution sent by this student (present link to his last answer)
  5019. // $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  5020. $iassign_previous = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position-1); // previous activity of this student inside this block
  5021. // $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  5022. $iassign_next = activity::get_latest_array_item($DB, $this->activity->iassignid, $this->activity->position+1); // next activity of this student inside this block
  5023. $link_next = "";
  5024. $link_previous = "";
  5025. if ($iassign_previous) { // previous_activity
  5026. $url_previous = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_previous->id;
  5027. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>\n";
  5028. }
  5029. if ($iassign_next) { // next_activity
  5030. $url_next = "view.php?id=" . $USER->cm . "&userid_iassign=" . $USER->id . "&action=view&iassign_current=" . $iassign_next->id;
  5031. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>\n";
  5032. }
  5033. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  5034. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  5035. $output .= '</tr></table>' . "\n";
  5036. $output .= '<table width=100% >' . "\n";
  5037. if ($this->activity->type_iassign > 1) {
  5038. if ($this->activity->timeavailable)
  5039. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  5040. if ($this->activity->timedue)
  5041. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  5042. } // if ($iassign_statement_activity_item->type_iassign > 1)
  5043. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  5044. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  5045. $output .= '</table>' . "\n";
  5046. print $OUTPUT->box($output);
  5047. } // function view_dates()
  5048. } // class activity
  5049. /// Class to manage Interactive Learning Module (iLM)
  5050. class ilm {
  5051. var $ilm;
  5052. /// Constructor of class
  5053. // @param int $id Id of iLM
  5054. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  5055. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  5056. function __construct ($id) {
  5057. global $DB;
  5058. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  5059. if (empty($this->ilm))
  5060. $this->ilm = null;
  5061. }
  5062. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  5063. // @calledby view_iassign_current()
  5064. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  5065. global $USER, $CFG, $DB;
  5066. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  5067. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5068. $typec = strtolower($iassign_ilm->type);
  5069. require_once 'ilm_handlers/' . $typec . '.php';
  5070. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  5071. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  5072. return $retorno;
  5073. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  5074. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  5075. // @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);
  5076. // @param int $iassign_statement_activity_itemid Id of iassign statement
  5077. // @param Object $file File in use in activity
  5078. // @return int Return the id of log
  5079. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  5080. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  5081. $newentry = new stdClass();
  5082. $newentry->iassign_statementid = $iassign_activity_itemid;
  5083. $newentry->userid = $USER->id;
  5084. $newentry->filesid = $content_or_id_from_ilm_security;
  5085. $newentry->timecreated = time();
  5086. $newentry->view = 1;
  5087. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  5088. if (!$id_iLM_security) {
  5089. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  5090. } // from (!$DB->insert_record("iassign_security", $newentry))
  5091. return $id_iLM_security;
  5092. }
  5093. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  5094. // @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);
  5095. // @param int $userid
  5096. // @param int $iassign_activity_itemid Id of iassign statement
  5097. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  5098. global $DB;
  5099. // 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")
  5100. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  5101. }
  5102. } // class ilm
  5103. /// Class to manage settings of iLM.
  5104. class ilm_settings {
  5105. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  5106. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5107. // @param int $ilm_id Id of iLM
  5108. // @param array $options An array with options for create dynamic tag html APPLET
  5109. // @return string Return with a tag html APPLET created
  5110. static function build_ilm_tags ($ilm_id, $options = array()) {
  5111. global $DB;
  5112. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5113. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5114. $typec = strtolower($iassign_ilm->type);
  5115. require_once 'ilm_handlers/' . $typec . '.php';
  5116. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  5117. return $retorno;
  5118. } // static function build_ilm_tags($ilm_id, $options = array())
  5119. /// Function for get modified date of iLM file
  5120. // @param string $file_jar String with Ids of iLM files
  5121. // @return string Return with the filenames and modified date
  5122. static function applet_filetime ($file_jar) {
  5123. $filetime = "";
  5124. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5125. $files_jar = explode(",", $file_jar);
  5126. foreach ($files_jar as $one_file) {
  5127. $file = $fs->get_file_by_id($one_file);
  5128. if ($file)
  5129. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  5130. }
  5131. return $filetime;
  5132. }
  5133. /// Function for verify an default applet
  5134. // @param String $file_jar String containing an list de ids of applet files
  5135. // @return boolean Return true or fale if applet is default
  5136. static function applet_default ($file_jar) {
  5137. $is_default = true;
  5138. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5139. $files_jar = explode(",", $file_jar);
  5140. foreach ($files_jar as $one_file) {
  5141. $file = $fs->get_file_by_id($one_file);
  5142. if ($file)
  5143. $is_default &= ($file->get_itemid() == 0);
  5144. }
  5145. return $is_default;
  5146. }
  5147. /// Function for get form variables for add, edit, or copy iLM
  5148. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  5149. // @see settings_form.php
  5150. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  5151. // @param int $ilm_id Id of iLM
  5152. // @param string $action String with the action
  5153. // @return object Return an object with forms variables
  5154. static function add_edit_copy_ilm ($ilm_id, $action) {
  5155. global $USER, $DB, $CFG;
  5156. require_once('settings_form.php'); // put the form
  5157. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5158. $param = new stdClass();
  5159. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  5160. $param->action = $action;
  5161. $param->ilm_id = $ilm_id;
  5162. $CFG->action_ilm = $action;
  5163. $CFG->ilm_id = $ilm_id;
  5164. if ($action == 'add') {
  5165. $param->title = get_string('add_ilm', 'iassign');
  5166. $param->name = "";
  5167. $param->version = "";
  5168. $param->url = "";
  5169. $param->description = "";
  5170. $param->extension = "";
  5171. $param->author = $USER->id;
  5172. $param->file_jar = "";
  5173. $param->file_jar_static = "";
  5174. $param->file_class = "";
  5175. $param->width = 800;
  5176. $param->height = 600;
  5177. $param->enable = 0; // 0 - hide / 1 - show
  5178. $param->timecreated = time();
  5179. $param->timemodified = time();
  5180. $param->evaluate = 0;
  5181. $param->parent = 0;
  5182. }
  5183. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5184. if ($iassign_ilm) {
  5185. $description = json_decode($iassign_ilm->description);
  5186. $param->title = get_string('edit_ilm', 'iassign');
  5187. $param->id = $iassign_ilm->id;
  5188. $param->name_ilm = $iassign_ilm->name;
  5189. $param->name = $iassign_ilm->name;
  5190. $param->version = $iassign_ilm->version;
  5191. $param->ilm_type = $iassign_ilm->type;
  5192. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5193. $param->url = $iassign_ilm->url; // iLM official URL
  5194. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5195. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5196. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5197. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5198. if (!isset($description->{current_language()})) {
  5199. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5200. else
  5201. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5202. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5203. }
  5204. else
  5205. $param->description = $description->{current_language()};
  5206. $param->description_lang = $iassign_ilm->description;
  5207. $param->extension = $iassign_ilm->extension;
  5208. $param->author = $iassign_ilm->author;
  5209. $param->file_jar = $iassign_ilm->file_jar;
  5210. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5211. $param->file_class = $iassign_ilm->file_class;
  5212. $param->width = $iassign_ilm->width;
  5213. $param->height = $iassign_ilm->height;
  5214. $param->enable = $iassign_ilm->enable;
  5215. $param->timecreated = $iassign_ilm->timecreated;
  5216. $param->timemodified = time();
  5217. $param->evaluate = $iassign_ilm->evaluate;
  5218. $param->parent = $iassign_ilm->parent;
  5219. }
  5220. }
  5221. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5222. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5223. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5224. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5225. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5226. // echo "Sem dados<br/>"; exit;
  5227. return;
  5228. }
  5229. $description = json_decode($iassign_ilm->description);
  5230. if ($iassign_ilm) {
  5231. if ($iassign_ilm->parent == 0)
  5232. $iassign_ilm->parent = $ilm_id;
  5233. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5234. $param->title = get_string('new_version_ilm', 'iassign');
  5235. $param->name_ilm = $iassign_ilm->name;
  5236. $param->name = $iassign_ilm->name;
  5237. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5238. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5239. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5240. $param->ilm_type = $iassign_ilm->type;
  5241. $param->url = $iassign_ilm->url;
  5242. $param->description = $description->{current_language()};
  5243. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5244. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5245. $param->extension = $iassign_ilm->extension;
  5246. $param->author = $USER->id;
  5247. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5248. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5249. $param->file_jar_static = '';
  5250. $param->file_class = $iassign_ilm->file_class;
  5251. $param->width = $iassign_ilm->width;
  5252. $param->height = $iassign_ilm->height;
  5253. $param->enable = 0;
  5254. $param->timecreated = time();
  5255. $param->timemodified = time();
  5256. $param->evaluate = $iassign_ilm->evaluate;
  5257. $param->parent = $iassign_ilm->parent;
  5258. }
  5259. }
  5260. elseif ($action == 'copy') {
  5261. $description = json_decode($iassign_ilm->description);
  5262. if ($iassign_ilm) {
  5263. if ($iassign_ilm->parent == 0)
  5264. $iassign_ilm->parent = $ilm_id;
  5265. $param->title = get_string('copy_ilm', 'iassign');
  5266. $param->id = $iassign_ilm->id;
  5267. $param->name_ilm = $iassign_ilm->name;
  5268. $param->name = $iassign_ilm->name;
  5269. $param->version = "";
  5270. $param->ilm_type = $iassign_ilm->type;
  5271. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5272. $param->url = $iassign_ilm->url;
  5273. $param->description = $description->{current_language()};
  5274. $param->description_lang = $iassign_ilm->description;
  5275. $param->extension = $iassign_ilm->extension;
  5276. $param->author = $USER->id;
  5277. $param->file_jar = '';
  5278. $param->file_jar_static = '';
  5279. $param->file_class = $iassign_ilm->file_class;
  5280. $param->width = $iassign_ilm->width;
  5281. $param->height = $iassign_ilm->height;
  5282. $param->enable = 0;
  5283. $param->timecreated = time();
  5284. $param->timemodified = time();
  5285. $param->evaluate = $iassign_ilm->evaluate;
  5286. $param->parent = $iassign_ilm->parent;
  5287. }
  5288. }
  5289. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5290. //D var_dump(debug_backtrace());
  5291. //D print_r(debug_backtrace());
  5292. return $param;
  5293. } // static function add_edit_copy_ilm($ilm_id, $action)
  5294. /// Function for save iLM file in moodledata
  5295. // @param int $itemid Itemid of file save in draft (upload file)
  5296. // @param int $ilm_id Id of iLM
  5297. // @return string Return an string with ids of iLM files
  5298. static function new_file_ilm ($itemid, $iassign_ilm) {
  5299. global $CFG, $USER, $DB;
  5300. $return = null;
  5301. $file_jar = array();
  5302. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5303. $contextuser = context_user::instance($USER->id);
  5304. $contextsystem = context_system::instance();
  5305. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5306. if ($files_ilm) {
  5307. foreach ($files_ilm as $value) {
  5308. // CHECK IF file is HTML type
  5309. if ($iassign_ilm->type == 1) {
  5310. // Check if the file extension is ZIP
  5311. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5312. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5313. if ((strtolower($ext) == 'zip')) {
  5314. // Coping...:
  5315. $destination = 'ilm_debug/' . $value->get_filename();
  5316. $value->copy_content_to($destination);
  5317. // Extracting content...:
  5318. $zip = new ZipArchive();
  5319. $extracted = './ilm';
  5320. $dir = "";
  5321. if ($zip->open($destination) === TRUE) {
  5322. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5323. if (is_dir($dir)) {
  5324. $i = 1;
  5325. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5326. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5327. $i++;
  5328. }
  5329. $name = $previous . "_" . $i;
  5330. $dir = './ilm/' . $name . "/";
  5331. $j = 0;
  5332. while ($item_name = $zip->getNameIndex($j)) {
  5333. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5334. $j++;
  5335. }
  5336. $zip->close();
  5337. }
  5338. $zip->open($destination);
  5339. $zip->extractTo($extracted);
  5340. $zip->close();
  5341. // After the extraction, remove it from DEBUG
  5342. unlink($destination);
  5343. } else { // Error trying to open destination...
  5344. // After the extraction error, also remove it from DEBUG
  5345. unlink($destination);
  5346. print_error('error_add_ilm_zip', 'iassign');
  5347. }
  5348. return $dir;
  5349. }
  5350. } // if ($iassign_ilm->type == 1)
  5351. if ($value->get_filename() != '.') {
  5352. $file_ilm = array(
  5353. 'userid' => $USER->id,
  5354. 'contextid' => $contextsystem->id,
  5355. 'component' => 'mod_iassign',
  5356. 'filearea' => 'ilm',
  5357. 'itemid' => rand(1, 999999999),
  5358. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5359. 'filename' => $value->get_filename());
  5360. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5361. array_push($file_jar, $file_ilm->get_id());
  5362. }
  5363. }
  5364. if (!empty($file_jar)) {
  5365. $return = implode(",", $file_jar);
  5366. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5367. foreach ($old_file_jar as $value) {
  5368. $file = $fs->get_file_by_id($value);
  5369. if ($file)
  5370. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5371. }
  5372. }
  5373. }
  5374. else // if ($files_ilm)
  5375. $return = $iassign_ilm->file_jar;
  5376. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5377. return $return;
  5378. } // static function new_file_ilm($itemid, $iassign_ilm)
  5379. /// Function for save in database an new iLM
  5380. // @param object $param An object with iLM params
  5381. static function new_ilm ($itemid) {
  5382. global $CFG, $USER, $OUTPUT;
  5383. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5384. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5385. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5386. }
  5387. $pathtemp = $CFG->dataroot . '/temp/';
  5388. $contextuser = context_user::instance($USER->id);
  5389. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5390. $zip = new zip_packer();
  5391. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5392. foreach ($files as $file) {
  5393. if (!$file->is_directory())
  5394. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5395. }
  5396. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5397. // Verifica se o pacote possui o XML
  5398. if (!$application_xml) {
  5399. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5400. return;
  5401. } else {
  5402. $missing = "";
  5403. if (!isset($application_xml->name)) {
  5404. $missing .= "name";
  5405. }
  5406. if (!isset($application_xml->version)) {
  5407. $missing .= ", version";
  5408. }
  5409. if (!isset($application_xml->type)) {
  5410. $missing .= ", type";
  5411. }
  5412. if (!isset($application_xml->extension)) {
  5413. $missing .= ", extension";
  5414. }
  5415. if (!isset($application_xml->file_jar)) {
  5416. $missing .= ", file_jar";
  5417. }
  5418. if (!isset($application_xml->file_class)) {
  5419. $missing .= ", file_class";
  5420. }
  5421. if (!isset($application_xml->width)) {
  5422. $missing .= ", width";
  5423. }
  5424. if (!isset($application_xml->height)) {
  5425. $missing .= ", height";
  5426. }
  5427. if (!isset($application_xml->evaluate)) {
  5428. $missing .= ", evaluate";
  5429. }
  5430. if (strlen($missing) > 2) {
  5431. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5432. return;
  5433. }
  5434. }
  5435. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5436. $typec = strtolower($application_xml->type);
  5437. require_once 'ilm_handlers/' . $typec . '.php';
  5438. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5439. return $retorno;
  5440. } // static function new_ilm($itemid)
  5441. /// Function for save in database an iLM edit
  5442. // @param object $param An object with iLM params
  5443. static function edit_ilm ($param, $itemid) {
  5444. // Descobrir o tipo de iLM:
  5445. global $DB, $USER, $CFG;
  5446. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5447. $pathtemp = $CFG->dataroot . '/temp/';
  5448. $contextuser = context_user::instance($USER->id);
  5449. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5450. $zip = new zip_packer();
  5451. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5452. $files_extract = null;
  5453. foreach ($files as $file) {
  5454. if (!$file->is_directory())
  5455. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5456. }
  5457. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5458. $typec = strtolower($iassign_t->type);
  5459. require_once 'ilm_handlers/' . $typec . '.php';
  5460. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5461. }
  5462. /// Function for register the new iLM (in database and in the directory)
  5463. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5464. // @param object $param An object with iLM params
  5465. static function copy_new_version_ilm ($param) {
  5466. global $DB, $CFG, $USER;
  5467. $itemid = $param->file;
  5468. $pathtemp = $CFG->dataroot . '/temp/';
  5469. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5470. //D echo "pathtemp=$pathtemp<br/>";
  5471. $contextuser = context_user::instance($USER->id);
  5472. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5473. $zip = new zip_packer();
  5474. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5475. $files_extract = null;
  5476. foreach ($files as $file) {
  5477. if (!$file->is_directory())
  5478. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5479. }
  5480. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5481. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5482. $typec = strtolower($iassign_t->type);
  5483. require_once 'ilm_handlers/' . $typec . '.php';
  5484. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5485. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5486. } // static function copy_new_version_ilm($param)
  5487. //VER::
  5488. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5489. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5490. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5491. /// Function for change visibility of iLM
  5492. // @param int $ilm_id Id of iLM
  5493. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5494. static function visible_ilm ($ilm_id, $status) {
  5495. global $DB;
  5496. if ($status == 0)
  5497. $visible = 1;
  5498. else
  5499. $visible = 0;
  5500. $newentry = new stdClass();
  5501. $newentry->id = $ilm_id;
  5502. $newentry->enable = $visible;
  5503. if (!$DB->update_record("iassign_ilm", $newentry))
  5504. error(get_string('error_edit_ilm', 'iassign'));
  5505. }
  5506. /// Function for confirm change default iLM
  5507. // @param int $ilm_id Id of iLM
  5508. // @param int $ilm_parent Id of parent iLM
  5509. // @return string Return with an string for create default page confirmation
  5510. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5511. global $OUTPUT, $DB;
  5512. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5513. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5514. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5515. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5516. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5517. return $return;
  5518. }
  5519. /// Function for change the default iLM
  5520. // @see settings_ilm.php
  5521. // @param int $ilm_id Id of iLM
  5522. // @return int Return Id of default iLM
  5523. static function default_ilm ($ilm_id) {
  5524. global $DB;
  5525. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5526. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5527. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5528. $iassign_ilm_default->id = $iassign_ilm->id;
  5529. $iassign_ilm_default->parent = 0;
  5530. $iassign_ilm->parent = $iassign_ilm_default->id;
  5531. $iassign_ilm->id = 0;
  5532. $iassign_ilm_default->enable = 1;
  5533. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5534. print_error('error_edit_ilm', 'iassign');
  5535. }
  5536. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5537. if (!$inserted) {
  5538. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5539. print_error($msg_error);
  5540. //xx print_error('error_add_ilm', 'iassign');
  5541. }
  5542. return $iassign_ilm_default->id;
  5543. } // static function default_ilm ($ilm_id)
  5544. /// Function for confirm delete iLM
  5545. // @param int $ilm_id Id of iLM
  5546. // @param int $ilm_parent Id of parent iLM
  5547. // @return string Return with an string for create delete page confirmation
  5548. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5549. global $OUTPUT, $DB;
  5550. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5551. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5552. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5553. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5554. }
  5555. /// Function for delete directory where the iLM is allocated.
  5556. // @param string $dirPath
  5557. // @throws InvalidArgumentException
  5558. public static function delete_dir ($dirPath) {
  5559. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5560. $dirPath .= '/';
  5561. }
  5562. $files = glob($dirPath . '*', GLOB_MARK);
  5563. foreach ($files as $file) {
  5564. if (is_dir($file)) {
  5565. ilm_settings::delete_dir($file);
  5566. } else {
  5567. unlink($file);
  5568. }
  5569. }
  5570. rmdir($dirPath);
  5571. }
  5572. /// Function for delete iLM
  5573. // @param int $ilm_id Id of iLM
  5574. // @return int Return Id of parent iLM
  5575. static function delete_ilm ($ilm_id) {
  5576. global $DB;
  5577. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5578. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5579. $typec = strtolower($iassign_ilm->type);
  5580. require_once 'ilm_handlers/' . $typec . '.php';
  5581. $retorno = $typec::delete_ilm($ilm_id);
  5582. return $retorno;
  5583. }
  5584. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5585. // @param int $ilm_id Id of iLM
  5586. static function export_ilm ($ilm_id) {
  5587. global $DB;
  5588. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5589. if (!$iassign_ilm) return; // security debug...
  5590. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5591. $typec = strtolower($iassign_ilm->type);
  5592. if (!$typec) $typec = "html5"; // security debug...
  5593. require_once 'ilm_handlers/' . $typec . '.php';
  5594. $typec::export_ilm($ilm_id);
  5595. } // static function export_ilm($ilm_id)
  5596. //TODO iLM_HTML5 :: //MOOC 2016
  5597. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5598. // @param int $ilm_id Id of iLM
  5599. static function export_update_ilm ($ilm_id) {
  5600. global $DB, $CFG;
  5601. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5602. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5603. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5604. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5605. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5606. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5607. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5608. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5609. $upgrade_descriptor .= '</upgrade>' . "\n";
  5610. file_put_contents($xml_filename, $upgrade_descriptor);
  5611. header("Pragma: public");
  5612. header("Expires: 0");
  5613. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5614. header("Cache-Control: private", false);
  5615. header('Content-Type: application/xml; charset=utf-8');
  5616. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5617. header("Content-Length: " . @filesize($xml_filename));
  5618. set_time_limit(0);
  5619. @readfile("$xml_filename") || die("File not found.");
  5620. unlink($xml_filename);
  5621. exit;
  5622. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5623. /// Function for save iLM from XML descriptor
  5624. // @param array $application_xml Data of XML descriptor
  5625. // @param array $files_extract Filenames of extract files
  5626. // @return array Return an array content id of JAR files
  5627. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5628. global $CFG, $USER;
  5629. // Tratamento diferenciado se for do tipo HTML5:
  5630. $source = "";
  5631. $diretorio = "";
  5632. if (strtolower($application_xml->type) == 'html5') {
  5633. $i = 0;
  5634. foreach ($files_extract as $key => $value) {
  5635. $file = $CFG->dataroot . '/temp/' . $key;
  5636. // Verifica se já existe a pasta no diretório dos iLM:
  5637. if ($i == 0) {
  5638. $source = $file;
  5639. if (file_exists("ilm/" . basename($file))) {
  5640. $j = 1;
  5641. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5642. $j++;
  5643. }
  5644. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5645. // mkdir($diretorio, 0777, true);
  5646. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5647. }
  5648. else {
  5649. $diretorio = 'ilm/' . basename($file);
  5650. // mkdir($diretorio, 0777, true);
  5651. mkdir($diretorio, 0755, true);
  5652. }
  5653. break;
  5654. }
  5655. $i++;
  5656. }
  5657. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5658. if ($item->isDir()) {
  5659. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5660. }
  5661. else {
  5662. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5663. }
  5664. }
  5665. ilm_settings::delete_dir($source);
  5666. return "./" . $diretorio;
  5667. }
  5668. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5669. $file_jar = array();
  5670. $files_ilm = explode(",", $application_xml->file_jar);
  5671. $contextsystem = context_system::instance();
  5672. foreach ($files_ilm as $value) {
  5673. $file_ilm = array(
  5674. 'userid' => $USER->id,
  5675. 'contextid' => $contextsystem->id,
  5676. 'component' => 'mod_iassign',
  5677. 'filearea' => 'ilm',
  5678. 'itemid' => rand(1, 999999999),
  5679. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5680. 'filename' => $value);
  5681. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5682. array_push($file_jar, $file_ilm->get_id());
  5683. }
  5684. foreach ($files_extract as $key => $value) {
  5685. $file = $CFG->dataroot . '/temp/' . $key;
  5686. if (file_exists($file))
  5687. unlink($file);
  5688. }
  5689. return $file_jar;
  5690. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5691. /// Function for import the iLM from an package
  5692. // @param int $itemid Itemid of zip file
  5693. static function import_ilm ($itemid) {
  5694. global $CFG, $USER, $OUTPUT;
  5695. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5696. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5697. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5698. }
  5699. $pathtemp = $CFG->dataroot . '/temp/';
  5700. $contextuser = context_user::instance($USER->id);
  5701. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5702. $zip = new zip_packer();
  5703. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5704. foreach ($files as $file) {
  5705. if (!$file->is_directory())
  5706. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5707. }
  5708. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5709. // Verifica se o pacote possui o XML
  5710. if (!$application_xml) {
  5711. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5712. return;
  5713. } else {
  5714. $missing = "";
  5715. if (!isset($application_xml->name)) {
  5716. $missing .= "name";
  5717. }
  5718. if (!isset($application_xml->version)) {
  5719. $missing .= ", version";
  5720. }
  5721. if (!isset($application_xml->type)) {
  5722. $missing .= ", type";
  5723. }
  5724. if (!isset($application_xml->extension)) {
  5725. $missing .= ", extension";
  5726. }
  5727. if (!isset($application_xml->file_jar)) {
  5728. $missing .= ", file_jar";
  5729. }
  5730. if (!isset($application_xml->file_class)) {
  5731. $missing .= ", file_class";
  5732. }
  5733. if (!isset($application_xml->width)) {
  5734. $missing .= ", width";
  5735. }
  5736. if (!isset($application_xml->height)) {
  5737. $missing .= ", height";
  5738. }
  5739. if (!isset($application_xml->evaluate)) {
  5740. $missing .= ", evaluate";
  5741. }
  5742. if (strlen($missing) > 2) {
  5743. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5744. return;
  5745. }
  5746. }
  5747. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5748. $typec = strtolower($application_xml->type);
  5749. require_once 'ilm_handlers/' . $typec . '.php';
  5750. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5751. } // static function import_ilm($itemid)
  5752. /// Function for list iLM defaults
  5753. // @return string Return an string with a table of iLM
  5754. static function list_ilm () {
  5755. global $DB, $OUTPUT;
  5756. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5757. $str = '';
  5758. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5759. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5760. if ($iassign_ilm) {
  5761. foreach ($iassign_ilm as $ilm) {
  5762. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5763. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5764. $str .= '<tr><td>';
  5765. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5766. $str .= '<tr>';
  5767. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5768. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5769. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5770. $str .= '</tr>';
  5771. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5772. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5773. $str .= '</table>';
  5774. $str .= '</td></tr>';
  5775. }
  5776. }
  5777. $str .= '</table>';
  5778. return $str;
  5779. }
  5780. /// Function for download and install an upgrade of an iLM
  5781. // @param int $ilm_id Id of iLM
  5782. static function upgrade_ilm ($ilm_id) {
  5783. global $DB, $CFG, $USER;
  5784. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5785. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5786. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5787. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5788. if (!$result)
  5789. print_error('error_upgrade_ilm', 'iassign');
  5790. else {
  5791. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5792. $extension = explode(".", $zip_filename);
  5793. if ($extension[count($extension) - 1] != 'ipz') {
  5794. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5795. die;
  5796. }
  5797. $zip = new zip_packer();
  5798. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5799. $contextuser = context_user::instance($USER->id);
  5800. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5801. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5802. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5803. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5804. if (file_exists($zip_filename))
  5805. unlink($zip_filename);
  5806. if (empty($file_jar)) {
  5807. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5808. print_error($msg_error);
  5809. //xx print_error('error_add_ilm', 'iassign');
  5810. }
  5811. else {
  5812. $newentry = new stdClass();
  5813. $newentry->name = (String) $application_xml->name;
  5814. $newentry->version = (String) $application_xml->version;
  5815. $newentry->url = (String) $application_xml->url;
  5816. $newentry->description = $description_str;
  5817. $newentry->extension = strtolower((String) $application_xml->extension);
  5818. $newentry->file_jar = implode(",", $file_jar);
  5819. $newentry->file_class = (String) $application_xml->file_class;
  5820. $newentry->width = (String) $application_xml->width;
  5821. $newentry->height = (String) $application_xml->height;
  5822. $newentry->enable = 0;
  5823. $newentry->timemodified = time();
  5824. $newentry->author = $USER->id;
  5825. $newentry->timecreated = time();
  5826. $newentry->evaluate = (String) $application_xml->evaluate;
  5827. $newentry->parent = $ilm_id;
  5828. }
  5829. }
  5830. return $iassign_ilm->id;
  5831. } // static function upgrade_ilm($ilm_id)
  5832. //MOOC2014 -- inicio
  5833. //TODO: REVIEW
  5834. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5835. // static function move_iassign($ilm_id)
  5836. //MOOC2014 -- final
  5837. /// Function for list iLM versions with all informations, under "admin" plugin view: .../mod/iassign/settings_ilm.php?action=view&ilm_id=".$ilmid."&from=admin
  5838. // @return string Return an string with a table of iLM
  5839. static function view_ilm ($ilmid, $from) {
  5840. global $DB;
  5841. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5842. // Get the iLM type and calls its correspondent handler ('Java' or 'HTML5')
  5843. $typec = strtolower($iassign_ilm->type);
  5844. require_once 'ilm_handlers/' . $typec . '.php';
  5845. $retorno = $typec::view_ilm($ilmid, $from);
  5846. return $retorno;
  5847. }
  5848. /// Function for get form variables for add, edit, or copy iLM params
  5849. // @param int $ilm_param_id Id of iLM param
  5850. // @param string $action String with the action
  5851. // @return object Return an object with forms variables
  5852. static function add_edit_copy_param ($ilm_param_id, $action) {
  5853. global $DB;
  5854. require_once('params_form.php');
  5855. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5856. $param = new stdClass();
  5857. $param->action = $action;
  5858. $param->ilm_param_id = $ilm_param_id;
  5859. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5860. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5861. $type = $iassign_ilm_config->param_type;
  5862. if ($action == 'add') {
  5863. $param->title = get_string('add_ilm', 'iassign');
  5864. $param->iassign_ilmid = $ilm_param_id;
  5865. $param->param_name = "";
  5866. $param->param_value = "";
  5867. $param->description = "";
  5868. $param->visible = 1;
  5869. }
  5870. elseif ($action == 'edit') {
  5871. if ($iassign_ilm_config) {
  5872. $param->title = get_string('edit_ilm', 'iassign');
  5873. $param->id = $iassign_ilm_config->id;
  5874. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5875. $param->param_type = $type; //MOOC2014
  5876. $param->param_name = $iassign_ilm_config->param_name;
  5877. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5878. $param->param_value = $iassign_ilm_config->param_value;
  5879. else //MOOC2014
  5880. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5881. $param->param_value = $iassign_ilm_config->param_value;
  5882. $param->description = $iassign_ilm_config->description;
  5883. $param->visible = $iassign_ilm_config->visible;
  5884. }
  5885. }
  5886. elseif ($action == 'copy') {
  5887. if ($iassign_ilm_config) {
  5888. $param->title = get_string('copy_ilm', 'iassign');
  5889. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5890. $param->param_type = $type; //MOOC2014
  5891. $param->param_name = $iassign_ilm_config->param_name;
  5892. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5893. $param->param_value = $iassign_ilm_config->param_value;
  5894. else //MOOC2014
  5895. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5896. $param->description = $iassign_ilm_config->description;
  5897. $param->visible = $iassign_ilm_config->visible;
  5898. }
  5899. }
  5900. return $param;
  5901. } // static function add_edit_copy_param($ilm_param_id, $action)
  5902. /// Function for change visibility of iLM param
  5903. // @param int $ilm_param_id Id of iLM param
  5904. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5905. static function visible_param ($ilm_param_id, $status) {
  5906. global $DB, $CFG;
  5907. if ($status == 0)
  5908. $visible = 1;
  5909. else
  5910. $visible = 0;
  5911. $newentry = new stdClass();
  5912. $newentry->id = $ilm_param_id;
  5913. $newentry->visible = $visible;
  5914. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5915. error(get_string('error_edit_param', 'iassign'));
  5916. }
  5917. /// Function for save in database an new iLM param
  5918. // @param object $param An object with iLM params
  5919. static function add_param ($param) {
  5920. global $DB;
  5921. $newentry = new stdClass();
  5922. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5923. //MOOC2014 $newentry->param_name = $param->param_name;
  5924. $newentry->param_type = $param->param_type; //MOOC2014
  5925. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5926. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5927. $newentry->param_value = $param->param_value;
  5928. else //MOOC2014
  5929. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5930. $newentry->description = $param->description;
  5931. $newentry->visible = $param->visible;
  5932. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5933. if (!$newentry->id) {
  5934. print_error('error_add_param', 'iassign');
  5935. }
  5936. }
  5937. /// Function for save in database a iLM param edit
  5938. // @param object $param An object with iLM params
  5939. static function edit_param ($param) {
  5940. global $DB;
  5941. $updentry = new stdClass();
  5942. $updentry->id = $param->id;
  5943. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5944. $updentry->param_type = $param->param_type; //MOOC2014
  5945. // $updentry->param_name = $param->param_name;
  5946. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5947. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5948. $updentry->param_value = $param->param_value;
  5949. else //MOOC2014
  5950. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5951. $updentry->description = $param->description;
  5952. $updentry->visible = $param->visible;
  5953. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5954. error(get_string('error_edit_param', 'iassign'));
  5955. }
  5956. }
  5957. /// Function for save in database a iLM param copy
  5958. // @param object $param An object with iLM params
  5959. static function copy_param ($param) {
  5960. global $DB;
  5961. $newentry = new stdClass();
  5962. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5963. //$newentry->param_name = $param->param_name;
  5964. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5965. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5966. $newentry->param_value = $param->param_value;
  5967. else //MOOC2014
  5968. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5969. $newentry->description = $param->description;
  5970. $newentry->visible = $param->visible;
  5971. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5972. if (!$newentry->id) {
  5973. print_error('error_add_param', 'iassign');
  5974. }
  5975. }
  5976. /// Function for delete iLM param of database
  5977. // @param int $param_id Id of iLM param
  5978. static function delete_param ($param_id) {
  5979. global $DB;
  5980. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5981. print_error('error_delete_param', 'iassign');
  5982. }
  5983. }
  5984. } // class ilm_settings
  5985. /// Class for manage iLM files (editor).
  5986. class ilm_manager {
  5987. var $id; // course id
  5988. var $url;
  5989. var $from;
  5990. /// Constructor for the base ilm_manager class
  5991. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5992. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5993. function __construct ($id, $url, $from) {
  5994. $this->id = $id; // course id
  5995. $this->url = $url;
  5996. $this->from = $from;
  5997. }
  5998. /// Function to get iAssign content file in Moodle data (exercise)
  5999. // @calledby x function preview_ilm($iassign_ilm) :
  6000. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  6001. function get_file_ilm () {
  6002. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6003. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6004. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  6005. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6006. $md_file = $fs->get_file_by_id($fileid);
  6007. $ilm_content_file = $md_file->get_content();
  6008. return $ilm_content_file;
  6009. }
  6010. /// Function for creating a new file from the iLM online editor
  6011. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  6012. function ilm_editor_new () {
  6013. global $CFG, $DB, $OUTPUT, $PAGE;
  6014. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6015. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6016. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6017. $context = context_course::instance($this->id);
  6018. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6019. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  6020. if (!$iassign) {
  6021. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  6022. die();
  6023. }
  6024. $temp = explode(",", $iassign->extension);
  6025. $extension = $temp[0]; // default extension for this iLM
  6026. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  6027. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6028. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  6029. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  6030. if ($stringArchiveContent != NULL) {
  6031. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  6032. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6033. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  6034. $filename = optional_param('filename', NULL, PARAM_RAW);
  6035. //Leo $filename = iassign_utils::format_filename($filename); //
  6036. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  6037. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  6038. //2019/02 $arrayfilename = explode(".", $filename);
  6039. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  6040. //2019/02 $count_dots = count($arrayfilename);
  6041. //2019/02 if ($count_dots > 0) { // at least one dot mark
  6042. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  6043. //2019/02 if ($last_name != $extension)
  6044. //2019/02 $filename = $filename . '.' . $extension;
  6045. //2019/02 }
  6046. //2019/02 else { // no extension...
  6047. //2019/02 $filename = $filename . '.' . $extension;
  6048. //2019/02 }
  6049. // Store the name of recent created file
  6050. $_SESSION['file_name'] = $filename;
  6051. //$this->write_file_iassign($string, $filename);
  6052. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  6053. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  6054. die();
  6055. }
  6056. else { // if ($stringArchiveContent != NULL)
  6057. // iLM On-line editor
  6058. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6059. $str_get_iLM = "window.frames.iLM";
  6060. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6061. }
  6062. else { // otherwise it is JAR named 'iLM'
  6063. $str_get_iLM = "document.iLM";
  6064. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6065. }
  6066. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6067. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  6068. $files_array = '';
  6069. foreach ($files as $value) {
  6070. if ($value->get_filename() != ".")
  6071. $files_array .= "'" . $value->get_filename() . "',";
  6072. }
  6073. $files_array .= "''";
  6074. $file = null;
  6075. $ia_content = "";
  6076. $filename = "";
  6077. $error_files_exists = get_string('error_file_exists', 'iassign');
  6078. $output = "<script type='text/javascript'>
  6079. //<![CDATA[
  6080. //D alert('locallib.php: ilm_editor_new');
  6081. function submit_iLM_Answer () {
  6082. var docFormOnLineEditor = document.formEnvio;
  6083. var resposta_exerc = new Array(3);
  6084. var valor_resposta = new Array(3);
  6085. var sessao = new Array(3);
  6086. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6087. resposta_exerc[0] = doc_iLM.getAnswer();
  6088. valor_resposta[0] = doc_iLM.getEvaluation();
  6089. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  6090. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  6091. var files = new Array(" . $files_array . ");
  6092. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  6093. if (docFormOnLineEditor.filename.value=='') {
  6094. // ERROR: the file name is empty
  6095. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  6096. return false;
  6097. }
  6098. // }
  6099. for (i=0; i<files.length; i++) {
  6100. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  6101. alert('" . $error_files_exists . "');
  6102. return false;
  6103. }
  6104. }
  6105. docFormOnLineEditor.submit();
  6106. return true;
  6107. }
  6108. //]]>
  6109. </script>\n";
  6110. $output .= "
  6111. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6112. $output .= $OUTPUT->box_start();
  6113. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  6114. $output .= "
  6115. <table width='100%' cellpadding='20'>
  6116. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  6117. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  6118. </tr>
  6119. </table>\n";
  6120. $output .= $OUTPUT->box_end();
  6121. $output .= "<center>\n";
  6122. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  6123. // Since it is the activity file, it is not necessary to use 'ilm_security'
  6124. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  6125. $output .= $output_ilm;
  6126. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  6127. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  6128. </center>
  6129. </form>\n";
  6130. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6131. $PAGE->navbar->add($title);
  6132. $PAGE->set_title($title);
  6133. $PAGE->set_heading($title); // insert title above the navigation bar
  6134. print $OUTPUT->header();
  6135. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6136. print $output;
  6137. print $OUTPUT->footer();
  6138. }
  6139. die();
  6140. } // function ilm_editor_new()
  6141. /// Function for editing an file in online editor
  6142. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  6143. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  6144. global $CFG, $DB, $OUTPUT, $PAGE;
  6145. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  6146. $dirid = optional_param('dirid', NULL, PARAM_INT);
  6147. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6148. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  6149. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  6150. // If iLM is not registered, error!
  6151. if (!$iassign) {
  6152. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  6153. die;
  6154. }
  6155. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  6156. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  6157. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  6158. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  6159. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  6160. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  6161. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  6162. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  6163. if ($stringArchiveContent != NULL) {
  6164. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  6165. die();
  6166. } else { // if ($stringArchiveContent != NULL)
  6167. $end_file = '';
  6168. if ($content_file) {
  6169. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6170. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6171. }
  6172. $temp = explode(",", $iassign->extension);
  6173. $extension = $temp[0]; // default extension for this iLM
  6174. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6175. $str_get_iLM = "window.frames.iLM";
  6176. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6177. } else { // otherwise it is JAR named 'iLM'
  6178. $str_get_iLM = "document.iLM";
  6179. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6180. }
  6181. $output = "<script type='text/javascript'>
  6182. //<![CDATA[
  6183. function submit_iLM_Answer () {
  6184. var docFormEditor = document.formEnvio;
  6185. var activityAnswer; // to get activity answer (text)
  6186. var activityValue; // to get activity answer value (float)
  6187. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6188. //activityAnswer = doc_iLM.getAnswer();
  6189. //activityValue = doc_iLM.getEvaluation();
  6190. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6191. activityValue = " . $str_get_iLM . ".getEvaluation();
  6192. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6193. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6194. docFormEditor.submit();
  6195. return true;
  6196. }
  6197. //]]>
  6198. </script>\n";
  6199. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6200. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6201. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6202. // return true;
  6203. // }
  6204. $output .= "
  6205. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6206. $output .= $OUTPUT->box_start();
  6207. $output .= "
  6208. <table width='100%' cellpadding='20'>
  6209. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6210. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6211. <input type='hidden' name='filename' value='$filename'/></td>
  6212. <td>
  6213. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6214. </tr>
  6215. </table>\n";
  6216. $output .= $OUTPUT->box_end();
  6217. $output .= " <center>\n";
  6218. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6219. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6220. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6221. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6222. </center>
  6223. </form>\n";
  6224. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6225. $PAGE->navbar->add($title);
  6226. $PAGE->set_title($title);
  6227. $PAGE->set_heading($title); // insert title above the navigation bar
  6228. print $OUTPUT->header();
  6229. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6230. print $output;
  6231. print $OUTPUT->footer();
  6232. } // else if ($stringArchiveContent != NULL)
  6233. die();
  6234. } // function ilm_editor_update()
  6235. /// Function for write iAssign file in Moodle data (exercise)
  6236. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6237. // @param string $stringArchiveContent Content of iassign file
  6238. // @param string $filename Filename of iassign file
  6239. function write_file_iassign ($stringArchiveContent, $filename) {
  6240. global $USER;
  6241. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6242. $context = context_course::instance($this->id);
  6243. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6244. $dirid = $this->get_dir_ilm('dirid');
  6245. $dir = $fs->get_file_by_id($dirid);
  6246. $fileinfo = array('contextid' => $context->id, // ID of course
  6247. 'component' => 'mod_iassign', // usually = table name
  6248. 'filearea' => 'activity', // usually = table name
  6249. 'itemid' => 0, // usually = ID of row in table
  6250. 'filepath' => '/', // any path beginning and ending whith '/'
  6251. 'userid' => $USER->id,
  6252. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6253. 'filename' => $filename); // any filename
  6254. // Create file containing text. '$stringArchiveContent'
  6255. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6256. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6257. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6258. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6259. // 'Activité interactive enregistrée avec succès sous le nom:';
  6260. // 'Atividade interativa gravada com sucesso sob o nome:'
  6261. $output = "
  6262. <script type='text/javascript'>
  6263. //<![CDATA[
  6264. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6265. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6266. //]]>
  6267. </script>";
  6268. print $output;
  6269. die();
  6270. }
  6271. /// Function for write iAssign file in Moodle data (exercise)
  6272. // @param string $stringArchiveContent Content of iassign file
  6273. // @param string $filename Filename of iassign file
  6274. // @param int $itemid Itemid of iassign file
  6275. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6276. global $OUTPUT, $USER;
  6277. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6278. $context = context_course::instance($this->id);
  6279. $dirid = $this->get_dir_ilm('dirid');
  6280. if ($stringArchiveContent != (-1)) {
  6281. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6282. $file = $fs->get_file_by_id($fileid);
  6283. if (!$file) {
  6284. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6285. die;
  6286. }
  6287. $fileinfo = array('contextid' => $context->id, // ID of context
  6288. 'component' => 'mod_iassign', // usually = table name
  6289. 'filearea' => 'activity', // usually = table name
  6290. 'itemid' => 0, // usually = ID of row in table
  6291. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6292. 'userid' => $USER->id,
  6293. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6294. 'license' => 'allrightsreserved', // allrightsreserved
  6295. 'timecreated' => $file->get_timecreated(),
  6296. 'filename' => $file->get_filename()); // any filename
  6297. $file->delete();
  6298. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6299. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6300. }
  6301. $output = "<script type='text/javascript'>
  6302. //<![CDATA[
  6303. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6304. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6305. //]]>
  6306. </script>";
  6307. print $output;
  6308. die();
  6309. }
  6310. /// Function for create an tag for iAssign filter
  6311. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6312. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6313. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6314. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6315. // @param int $fileid Id of file
  6316. // @return string Return an string with an tag of iassign filter
  6317. function tag_ilm ($fileid) {
  6318. global $DB;
  6319. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6320. $width = '600';
  6321. $height = '400';
  6322. $file = $fs->get_file_by_id($fileid);
  6323. $filetype = explode(".", $file->get_filename());
  6324. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6325. foreach ($iassign_ilm as $value) {
  6326. $extensions = explode(",", $value->extension);
  6327. if (in_array($filetype[1], $extensions)) {
  6328. $width = $value->width;
  6329. $height = $value->height;
  6330. }
  6331. }
  6332. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6333. }
  6334. /// Function for delete iAssign file in Moodle data (exercise)
  6335. function delete_file_ilm () {
  6336. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6337. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6338. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6339. $file = $fs->get_file_by_id($fileid);
  6340. if ($file)
  6341. $file->delete();
  6342. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6343. die();
  6344. }
  6345. /// Function for delete selected iAssign file in Moodle data (exercise)
  6346. function delete_selected_ilm () {
  6347. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6348. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6349. $context = context_course::instance($this->id);
  6350. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6351. $dirid = $this->get_dir_ilm('dirid');
  6352. foreach ($files_id as $file_id) {
  6353. $file = $fs->get_file_by_id($file_id);
  6354. if ($file) {
  6355. if (!$file->is_directory())
  6356. $file->delete();
  6357. else {
  6358. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6359. foreach ($files_delete as $value)
  6360. $value->delete();
  6361. $file->delete();
  6362. }
  6363. }
  6364. }
  6365. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6366. die();
  6367. }
  6368. /// Function for duplicate iAssign file from "online" edition
  6369. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6370. function duplicate_file_ilm () {
  6371. global $USER, $COURSE;
  6372. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6373. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6374. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6375. $filename = optional_param('filename', NULL, PARAM_RAW);
  6376. $file = $fs->get_file_by_id($fileid);
  6377. $context = context_course::instance($this->id);
  6378. $fileinfo = array(
  6379. 'contextid' => $context->id, // ID of context
  6380. 'component' => 'mod_iassign', // usually = table name
  6381. 'filearea' => 'activity', // usually = table name
  6382. 'itemid' => 0, // usually = ID of row in table
  6383. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6384. 'userid' => $USER->id,
  6385. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6386. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6387. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6388. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6389. die();
  6390. }
  6391. /// Function for rename iAssign file
  6392. function rename_file_ilm () {
  6393. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6394. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6395. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6396. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6397. $file = $fs->get_file_by_id($fileid);
  6398. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6399. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6400. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6401. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6402. die();
  6403. }
  6404. /// Function for get iassign file for iassign form
  6405. function add_ilm () {
  6406. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6407. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6408. $output = "
  6409. <script type='text/javascript'>
  6410. //<![CDATA[
  6411. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6412. iassign_file_link.innerHTML = '$filename';
  6413. window.opener.document.forms['mform1'].file.value='$fileid';
  6414. window.opener.document.forms['mform1'].filename.value='$filename';
  6415. window.close();
  6416. //]]>
  6417. </script>";
  6418. print $output;
  6419. die();
  6420. }
  6421. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6422. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6423. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6424. function preview_ilm ($courseid, $iassign_ilm) {
  6425. global $OUTPUT, $CFG, $USER;
  6426. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6427. $title = get_string('modulename', 'iassign'); // iAssign
  6428. print $OUTPUT->header();
  6429. print $OUTPUT->box_start();
  6430. $javascript = "
  6431. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6432. <script type='text/javascript'>
  6433. //<![CDATA[
  6434. function submit_close () {
  6435. window.opener.location.reload();
  6436. window.close();
  6437. }
  6438. //]]>
  6439. </script>\n";
  6440. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6441. // to the complete "applet" tag
  6442. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6443. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6444. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6445. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6446. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6447. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6448. if ($ilm_name != "ivprog") {
  6449. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6450. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6451. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6452. } else {
  6453. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6454. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6455. $timecreated = time();
  6456. $token = md5($timecreated);
  6457. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6458. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6459. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6460. $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)
  6461. }
  6462. $html = "
  6463. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6464. <table border='1'>
  6465. <tr><td>
  6466. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6467. <!-- iLM calls : end -->
  6468. </td></tr>
  6469. </table>
  6470. <table>
  6471. <tr>
  6472. <td align='center'>
  6473. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6474. </td></tr>
  6475. </table>
  6476. </form>\n";
  6477. print $javascript . $html;
  6478. print $OUTPUT->box_end();
  6479. //NAO echo format_string($html); // Moodle 3.X
  6480. die();
  6481. } // function preview_ilm($courseid, $iassign_ilm)
  6482. //r_ function preview_ilm ($iassign_ilm)
  6483. //r_ /// Function for preview iassign file from iassign filter.
  6484. //r_ function preview_ilm() {
  6485. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6486. //r_ $tag_filter = $this->tag_ilm($fileid);
  6487. //r_ $javascript = "<script type='text/javascript'>
  6488. //r_ //<![CDATA[
  6489. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6490. //r_ //]]>
  6491. //r_ </script>";
  6492. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6493. //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>
  6494. //r_ </table></form></body></html>";
  6495. //r_ echo $javascript . format_text($html);
  6496. //r_ die;
  6497. //r_ }
  6498. /// Function for export an package (zip) of iassign files
  6499. function export_files_ilm () {
  6500. global $CFG;
  6501. $context = context_course::instance($this->id);
  6502. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6503. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6504. $zip = new zip_archive();
  6505. $zip->open($zip_filename);
  6506. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6507. foreach ($files_id as $file_id) {
  6508. $file = $fs->get_file_by_id($file_id);
  6509. if (!$file->is_directory())
  6510. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6511. else {
  6512. $zip->add_directory($file->get_filepath());
  6513. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6514. foreach ($files_zip as $value) {
  6515. if (!$value->is_directory())
  6516. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6517. else
  6518. $zip->add_directory($value->get_filepath());
  6519. }
  6520. }
  6521. }
  6522. $zip->close();
  6523. header("Pragma: public");
  6524. header("Expires: 0");
  6525. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6526. header("Cache-Control: private", false);
  6527. header("Content-Type: application/zip");
  6528. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6529. header("Content-Transfer-Encoding: binary");
  6530. header("Content-Length: " . @filesize($zip_filename));
  6531. set_time_limit(0);
  6532. @readfile("$zip_filename") || die("File not found.");
  6533. unlink($zip_filename);
  6534. exit;
  6535. }
  6536. /// Function of execute a command in button editor tinymce
  6537. // @param int $fileid Id of file
  6538. function tinymce_ilm ($fileid) {
  6539. $tag_filter = $this->tag_ilm($fileid);
  6540. $output = "<script type='text/javascript'>
  6541. //<![CDATA[
  6542. var tag_filter = '$tag_filter';
  6543. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6544. // all right, insert it
  6545. } else {
  6546. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6547. }
  6548. // window.close();
  6549. //]]>
  6550. </script>\n";
  6551. print $output;
  6552. die();
  6553. }
  6554. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6555. /// Function to add content to the Editor Window
  6556. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6557. // @param int $fileid Id of file
  6558. function editor_ilm ($fileid, $editor) {
  6559. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6560. $output1 = "<script type='text/javascript'>
  6561. //<![CDATA[
  6562. var tag_filter = '$tag_filter';\n";
  6563. if ($editor == 'atto') {
  6564. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6565. } elseif ($editor == 'tinyMCE') {
  6566. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6567. } else
  6568. $output2 = "";
  6569. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6570. window.close();
  6571. //]]>
  6572. </script>\n";
  6573. //D var_dump($output);
  6574. print $output1 . $output2 . $output3;
  6575. die();
  6576. }
  6577. /// Function to add content to the Atto Editor Window
  6578. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6579. // @param int $fileid Id of file
  6580. function atto_ilm ($fileid) {
  6581. global $CFG, $DB;
  6582. $tag_filter = $this->tag_ilm($fileid);
  6583. $output = "<script type='text/javascript'>
  6584. //<![CDATA[
  6585. var tag_filter = '$tag_filter';
  6586. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6587. // all right, insert iLM tag to this editor
  6588. } else {
  6589. // error trying to insert
  6590. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6591. }
  6592. //window.close();
  6593. //]]>
  6594. </script>\n";
  6595. print $output;
  6596. die();
  6597. }
  6598. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6599. // @param string $key Key for return information
  6600. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6601. function get_dir_ilm ($key) {
  6602. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6603. $context = context_course::instance($this->id);
  6604. $dirid = optional_param('dirid', 0, PARAM_INT);
  6605. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6606. if ($dirid == 0) {
  6607. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6608. $dirid = $dir->get_id();
  6609. }
  6610. else {
  6611. $dir = $fs->get_file_by_id($dirid);
  6612. $dir_base = $dir->get_filepath();
  6613. }
  6614. $dir_parent = $dir->get_parent_directory();
  6615. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6616. return $data[$key];
  6617. }
  6618. /// Function for create an new dir
  6619. function new_dir_ilm () {
  6620. global $USER;
  6621. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6622. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6623. $dir_base = $this->get_dir_ilm('dir_base');
  6624. $context = context_course::instance($this->id);
  6625. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6626. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6627. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6628. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6629. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6630. }
  6631. /// Function for delete an dir
  6632. function delete_dir_ilm () { //
  6633. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6634. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6635. $context = context_course::instance($this->id);
  6636. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6637. $dir_parent = $this->get_dir_ilm('dir_parent');
  6638. if ($dir) {
  6639. if ($dir->is_directory()) {
  6640. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6641. foreach ($files_delete as $value)
  6642. $value->delete();
  6643. $dir->delete();
  6644. }
  6645. }
  6646. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6647. die();
  6648. }
  6649. /// Function for rename an dir
  6650. function rename_dir_ilm () {
  6651. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6652. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6653. $context = context_course::instance($this->id);
  6654. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6655. $dir_parent = $this->get_dir_ilm('dir_parent');
  6656. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6657. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6658. if ($dir->is_directory()) {
  6659. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6660. foreach ($files_rename_path as $value)
  6661. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6662. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6663. }
  6664. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6665. die();
  6666. }
  6667. /// Function for move an dir and your content for other dir
  6668. function selected_move_ilm () {
  6669. global $PAGE, $OUTPUT, $CFG;
  6670. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6671. $context = context_course::instance($this->id);
  6672. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6673. $dirid = $this->get_dir_ilm('dirid');
  6674. $dir_base = $this->get_dir_ilm('dir_base');
  6675. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6676. $code_javascript_ilm = "
  6677. <script type='text/javascript'>
  6678. //<![CDATA[
  6679. function getRadiobutton () {
  6680. var radioButtons = document.getElementsByTagName('input');
  6681. var param = '';
  6682. for (var counter=0; counter < radioButtons.length; counter++) {
  6683. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6684. param = radioButtons[counter].value;
  6685. }
  6686. return param;
  6687. }
  6688. function move_selected_ilm () {
  6689. var msgAnswer;
  6690. if (getRadiobutton() != '') {
  6691. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6692. if (msgAnswer)
  6693. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6694. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6695. }
  6696. else
  6697. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6698. }
  6699. function cancel_selected_ilm () {
  6700. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6701. }
  6702. //]]>
  6703. </script>\n";
  6704. $title = get_string('move_files', 'iassign');
  6705. $PAGE->set_title($title);
  6706. $PAGE->set_pagelayout('base');
  6707. print $OUTPUT->header();
  6708. print $OUTPUT->heading($title);
  6709. $dir_paths = array();
  6710. print $OUTPUT->box_start();
  6711. print "<center>";
  6712. foreach ($files_id as $file_id) {
  6713. $file = $fs->get_file_by_id($file_id);
  6714. if ($file) {
  6715. if (!$file->is_directory())
  6716. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6717. else {
  6718. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6719. array_push($dir_paths, $file->get_filepath());
  6720. }
  6721. }
  6722. }
  6723. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6724. if ($dir_base != '/') {
  6725. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6726. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6727. }
  6728. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6729. foreach ($files_tree as $file) {
  6730. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6731. $is_parent = false;
  6732. foreach ($dir_paths as $dir) {
  6733. $path = explode("/", $dir);
  6734. array_pop($path);
  6735. $path[count($path) - 1] = '';
  6736. $path = implode("/", $path);
  6737. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6738. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6739. }
  6740. if ($is_parent == false) {
  6741. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6742. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6743. }
  6744. }
  6745. }
  6746. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6747. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6748. print "</center>";
  6749. print $OUTPUT->box_end();
  6750. print $OUTPUT->footer();
  6751. print $code_javascript_ilm;
  6752. die;
  6753. }
  6754. /// Function for move files for an dir
  6755. function move_files_ilm () {
  6756. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6757. $context = context_course::instance($this->id);
  6758. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6759. $dirid = $this->get_dir_ilm('dirid');
  6760. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6761. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6762. foreach ($files_id as $file_id) {
  6763. $file = $fs->get_file_by_id($file_id);
  6764. if ($file) {
  6765. if ($file->is_directory()) {
  6766. $pathname = explode("/", $file->get_filepath());
  6767. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6768. foreach ($files_move_path as $value) {
  6769. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6770. $value->rename($path_move, $value->get_filename());
  6771. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6772. }
  6773. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6774. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6775. $file->rename($path_move, $file->get_filename());
  6776. } else {
  6777. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6778. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6779. }
  6780. }
  6781. }
  6782. //die;
  6783. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6784. die();
  6785. } // function move_files_ilm()
  6786. /// Function for recover files in use on all activities of a course
  6787. function recover_files_ilm () {
  6788. global $DB, $USER;
  6789. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6790. $courseid = optional_param('id', NULL, PARAM_INT);
  6791. $dirid = $this->get_dir_ilm('dirid');
  6792. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6793. $contextfile = context_course::instance($this->id);
  6794. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6795. foreach ($iassigns as $iassign) {
  6796. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6797. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6798. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6799. $context = context_module::instance($cm->id);
  6800. // Before associtaion 'files.id' with 'iassign_statement.iassign_ilmid': $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->filesid);
  6801. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6802. if ($files) {
  6803. foreach ($files as $value) {
  6804. $extension = explode(".", $value->get_filename());
  6805. if (!$value->is_directory()) {
  6806. $fileinfo = array('contextid' => $contextfile->id,
  6807. 'component' => 'mod_iassign',
  6808. 'filearea' => 'activity',
  6809. 'itemid' => 0,
  6810. 'filepath' => $this->get_dir_ilm('dir_base'),
  6811. 'userid' => $USER->id,
  6812. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6813. 'license' => 'allrightsreserved',
  6814. 'timecreated' => time(),
  6815. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6816. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6817. }
  6818. }
  6819. } // if ($files)
  6820. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6821. } // foreach ($iassigns as $iassign)
  6822. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6823. die();
  6824. } // function recover_files_ilm()
  6825. /// Auxiliary function the get all files in a given context
  6826. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6827. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6828. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6829. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6830. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6831. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6832. // (NAO s_iassign_statement.file = s_files.id)
  6833. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6834. $dir_base = $this->get_dir_ilm('dir_base');
  6835. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6836. $countf = 0;
  6837. $array_files_id = array(); // all files from this context
  6838. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6839. //$filename = $item_fc->get_filename();
  6840. //$filepath = $item_fc->get_filepath();
  6841. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6842. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6843. // $array_files_aux[] = $item_fc;
  6844. $itemid = $item_fc->get_id();
  6845. if (!in_array($itemid, $array_files_id)) {
  6846. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6847. if ($fileuserid == $userid)
  6848. $filesfrommine[] = $item_fc;
  6849. else
  6850. $filesfromothers[] = $item_fc;
  6851. $array_files_id[] = $itemid;
  6852. $countf++;
  6853. }
  6854. }
  6855. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6856. return $countf;
  6857. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6858. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6859. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6860. function get_all_ilm_files_by_fileid ($fileid) {
  6861. global $DB, $USER;
  6862. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6863. //TODO Criar coluna 'authorid'
  6864. $str_query = "SELECT * FROM {iassign_statement} WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6865. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6866. return $array_iassign_ilm;
  6867. }
  6868. //NN
  6869. //NN
  6870. // Build string with JavaScript code with function to edit/remove/double iLM files
  6871. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6872. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6873. global $CFG;
  6874. $error_files_exists = get_string('error_file_exists', 'iassign');
  6875. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6876. $code_javascript_ilm = "
  6877. <script type='text/javascript'>
  6878. //<![CDATA[
  6879. function preview_ilm (fileid, ilmid) { //JavaScript function
  6880. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6881. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6882. }
  6883. function update_ilm (ilmid, fileid) { //JavaScript function
  6884. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6885. }
  6886. function delete_ilm (ilmid, fileid) { //JavaScript function
  6887. var msgAnswer;
  6888. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6889. if (msgAnswer) {
  6890. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6891. }
  6892. }
  6893. function delete_selected_ilm () { //JavaScript function
  6894. var msgAnswer;
  6895. var param = getCheckbox();
  6896. if (param.join() != '') {
  6897. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6898. if (msgAnswer)
  6899. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6900. }
  6901. else
  6902. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6903. }
  6904. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6905. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6906. }
  6907. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6908. var filenamecopy;
  6909. var i;
  6910. var files = new Array(" . $files_array . ");
  6911. do {
  6912. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6913. } while (filenamecopy == '');
  6914. if (filenamecopy == null)
  6915. return false;\n
  6916. else {
  6917. for (i=0;i<files.length;i++) {
  6918. if (files[i]==filenamecopy) {
  6919. alert('" . $error_files_exists . "');
  6920. return false;\n
  6921. }
  6922. }\n" .
  6923. // @see: function 'duplicate_file_ilm()' above
  6924. "
  6925. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6926. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6927. } // else
  6928. }
  6929. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6930. var filenamecopy;
  6931. var i;
  6932. var files = new Array($files_array);
  6933. do {
  6934. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6935. } while (filenamecopy == '');
  6936. if (filenamecopy == null)
  6937. return false;
  6938. else {
  6939. for (i=0;i<files.length;i++) {
  6940. if (files[i]==filenamecopy) {
  6941. alert('" . $error_files_exists . "');
  6942. return false;
  6943. }
  6944. }
  6945. 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;
  6946. }
  6947. }
  6948. function export_files_ilm () { //JavaScript function
  6949. var param = getCheckbox();
  6950. if (param.join() != '')
  6951. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6952. else
  6953. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6954. }
  6955. function select_all_ilm () { //JavaScript function
  6956. var checkBoxes = document.getElementsByTagName('input');
  6957. var selectAll = document.getElementById('select_all');
  6958. for (var counter=0; counter < checkBoxes.length; counter++) {
  6959. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6960. checkBoxes[counter].checked = selectAll.checked;
  6961. }
  6962. }
  6963. function getCheckbox () { //JavaScript function
  6964. var checkBoxes = document.getElementsByTagName('input');
  6965. var param = new Array();
  6966. for (var counter=0; counter < checkBoxes.length; counter++) {
  6967. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6968. param.push(checkBoxes[counter].value);
  6969. }
  6970. return param;
  6971. }
  6972. function new_dir_ilm () { //JavaScript function
  6973. var dirname = '';
  6974. var i;
  6975. var dirs = new Array(" . $dirs_array . ");
  6976. do {
  6977. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6978. } while (dirname == '');
  6979. if (dirname == null)
  6980. return false;\n
  6981. else {
  6982. for (i=0;i<dirs.length;i++) {
  6983. if (dirs[i]==dirname) {
  6984. alert('" . $error_dir_exists . "');
  6985. return false;\n
  6986. }
  6987. }
  6988. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6989. }
  6990. }
  6991. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6992. var msgAnswer;
  6993. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6994. if (msgAnswer) {
  6995. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6996. }
  6997. }
  6998. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6999. var dirnamecopy;
  7000. var i;
  7001. var dirs = new Array($dirs_array);
  7002. do {
  7003. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7004. } while (dirnamecopy == '');
  7005. if (dirnamecopy == null)
  7006. return false;\n
  7007. else {
  7008. for (i=0;i<dirs.length;i++) {
  7009. if (dirs[i]==dirnamecopy) {
  7010. alert('" . $error_dir_exists . "');
  7011. return false;\n
  7012. }
  7013. }
  7014. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7015. }
  7016. }
  7017. function move_selected_ilm (ilmid) { //JavaScript function
  7018. var param = getCheckbox();
  7019. if (param.join() != '')
  7020. 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();
  7021. else
  7022. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7023. }
  7024. function recover_files_ilm () { //JavaScript function
  7025. var msgAnswer;
  7026. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7027. if (msgAnswer) {
  7028. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7029. }
  7030. }
  7031. window.onload = function() { //JavaScript function
  7032. var xPosition = 0;
  7033. var yPosition = 0;
  7034. element=document.getElementById('new_file');
  7035. while(element) {
  7036. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7037. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7038. element = element.offsetParent;
  7039. }
  7040. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7041. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7042. location.hash = '#new_file';
  7043. };
  7044. //]]>
  7045. </script>\n"; // end of $code_javascript_ilm
  7046. return $code_javascript_ilm;
  7047. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  7048. /// List iassign files from course directory
  7049. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  7050. function view_files_ilm ($iassign_ilm_class, $extension) {
  7051. global $CFG, $DB, $USER, $OUTPUT;
  7052. $fs = get_file_storage();
  7053. $context = context_course::instance($this->id);
  7054. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  7055. $dirid = $this->get_dir_ilm('dirid');
  7056. $dir_base = $this->get_dir_ilm('dir_base');
  7057. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  7058. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  7059. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  7060. $files_array = '';
  7061. foreach ($files_course as $value) {
  7062. if (!$value->is_directory())
  7063. $files_array .= "'" . $value->get_filename() . "',";
  7064. }
  7065. $files_array .= "''";
  7066. $error_files_exists = get_string('error_file_exists', 'iassign');
  7067. $dirs_array = '';
  7068. foreach ($files_course as $value) {
  7069. if ($value->is_directory()) {
  7070. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  7071. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  7072. }
  7073. }
  7074. $dirs_array .= "''";
  7075. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  7076. //TODO: Rever o 'preview', pois so' apresenta uma vez!
  7077. $code_javascript_ilm = "
  7078. <script type='text/javascript'>
  7079. //<![CDATA[
  7080. function preview_ilm (fileid, ilmid) {
  7081. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  7082. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  7083. }
  7084. function update_ilm (ilmid, fileid) {
  7085. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7086. }
  7087. function delete_ilm (ilmid, fileid) {
  7088. var msgAnswer;
  7089. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  7090. if (msgAnswer) {
  7091. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  7092. }
  7093. }
  7094. function delete_selected_ilm () {
  7095. var msgAnswer;
  7096. var param = getCheckbox();
  7097. if (param.join() != '') {
  7098. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  7099. if (msgAnswer)
  7100. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  7101. }
  7102. else
  7103. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  7104. }
  7105. function add_ilm_iassign (ilmid, filename, fileid) {
  7106. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  7107. }
  7108. function duplicate_ilm (ilmid, filename, fileid) {
  7109. var filenamecopy;
  7110. var i;
  7111. var files = new Array($files_array);
  7112. do {
  7113. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  7114. } while (filenamecopy == '');
  7115. if (filenamecopy == null)
  7116. return false;\n
  7117. else {
  7118. for (i=0;i<files.length;i++) {
  7119. if (files[i]==filenamecopy) {
  7120. alert('$error_files_exists');
  7121. return false;\n
  7122. }
  7123. }\n" .
  7124. // @see: function 'duplicate_file_ilm()' above
  7125. "
  7126. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  7127. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  7128. } // else
  7129. }
  7130. function rename_ilm (ilmid, filename, fileid) {
  7131. var filenamecopy;
  7132. var i;
  7133. var files = new Array($files_array);
  7134. do {
  7135. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  7136. } while (filenamecopy == '');
  7137. if (filenamecopy == null)
  7138. return false;
  7139. else {
  7140. for (i=0;i<files.length;i++) {
  7141. if (files[i]==filenamecopy) {
  7142. alert('$error_files_exists');
  7143. return false;
  7144. }
  7145. }
  7146. 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;
  7147. }
  7148. }
  7149. function export_files_ilm () {
  7150. var param = getCheckbox();
  7151. if (param.join() != '')
  7152. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  7153. else
  7154. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  7155. }
  7156. function select_all_ilm () {
  7157. var checkBoxes = document.getElementsByTagName('input');
  7158. var selectAll = document.getElementById('select_all');
  7159. for (var counter=0; counter < checkBoxes.length; counter++) {
  7160. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  7161. checkBoxes[counter].checked = selectAll.checked;
  7162. }
  7163. }
  7164. function getCheckbox () {
  7165. var checkBoxes = document.getElementsByTagName('input');
  7166. var param = new Array();
  7167. for (var counter=0; counter < checkBoxes.length; counter++) {
  7168. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7169. param.push(checkBoxes[counter].value);
  7170. }
  7171. return param;
  7172. }
  7173. function new_dir_ilm () {
  7174. var dirname = '';
  7175. var i;
  7176. var dirs = new Array($dirs_array);
  7177. do {
  7178. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7179. } while (dirname == '');
  7180. if (dirname == null)
  7181. return false;\n
  7182. else {
  7183. for (i=0;i<dirs.length;i++) {
  7184. if (dirs[i]==dirname) {
  7185. alert('$error_dir_exists');
  7186. return false;\n
  7187. }
  7188. }
  7189. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7190. }
  7191. }
  7192. function delete_dir_ilm (ilmid, dirid) {
  7193. var msgAnswer;
  7194. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7195. if (msgAnswer) {
  7196. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7197. }
  7198. }
  7199. function rename_dir_ilm (ilmid, dirname, dirid) {
  7200. var dirnamecopy;
  7201. var i;
  7202. var dirs = new Array($dirs_array);
  7203. do {
  7204. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7205. } while (dirnamecopy == '');
  7206. if (dirnamecopy == null)
  7207. return false;\n
  7208. else {
  7209. for (i=0;i<dirs.length;i++) {
  7210. if (dirs[i]==dirnamecopy) {
  7211. alert('$error_dir_exists');
  7212. return false;\n
  7213. }
  7214. }
  7215. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7216. }
  7217. }
  7218. function move_selected_ilm (ilmid) {
  7219. var param = getCheckbox();
  7220. if (param.join() != '')
  7221. 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();
  7222. else
  7223. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7224. }
  7225. function recover_files_ilm () {
  7226. var msgAnswer;
  7227. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7228. if (msgAnswer) {
  7229. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7230. }
  7231. }
  7232. window.onload = function() {
  7233. var xPosition = 0;
  7234. var yPosition = 0;
  7235. element=document.getElementById('new_file');
  7236. while(element) {
  7237. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7238. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7239. element = element.offsetParent;
  7240. }
  7241. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7242. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7243. location.hash = '#new_file';
  7244. };
  7245. //]]>
  7246. </script>\n";
  7247. $output = "";
  7248. $select_all = "";
  7249. $count_files = 0;
  7250. $extensions_allow = array();
  7251. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7252. foreach ($iassign_ilm as $item_iassign_ilm)
  7253. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7254. foreach ($files_course as $value) {
  7255. $filename = $value->get_filename();
  7256. $filepath = $value->get_filepath();
  7257. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7258. $pathname = $pathname[count($pathname) - 1];
  7259. $fileid = $value->get_id();
  7260. $tmp = explode(".", $filename);
  7261. if (count($tmp)>1) // avoid error if the file has no extension
  7262. $filetype = $tmp[1];
  7263. else // probably error...
  7264. $filetype = '';
  7265. $author = $value->get_author();
  7266. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7267. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7268. $extensions = explode(",", $extension);
  7269. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7270. $count_files++;
  7271. // buscar fileid nas tabelas do iassign
  7272. $list_filein_use = "";
  7273. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7274. if ($iassign_statement_activity_list) {
  7275. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7276. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7277. }
  7278. }
  7279. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7280. if (!$iassign_ilm) {
  7281. $iassign_ilm = new stdClass();
  7282. $iassign_ilm->id = $ilmid;
  7283. }
  7284. // Do not use $var inside "..." - problem with some "unusual" operational system
  7285. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7286. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7287. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7288. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7289. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7290. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7291. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7292. $check_select = "";
  7293. $link_rename = "";
  7294. $link_delete = "";
  7295. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7296. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7297. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7298. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7299. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7300. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7301. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7302. if ($value->get_userid() == $USER->id) {
  7303. if ($iassign_statement_activity_list) {
  7304. $check_select = "";
  7305. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7306. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7307. $link_rename = "";
  7308. } else {
  7309. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7310. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7311. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7312. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7313. }
  7314. }
  7315. if (!in_array($filetype, $extensions_allow)) {
  7316. $link_edit = "";
  7317. $link_add_ilm_iassign = "";
  7318. $link_add_ilm_tinymce = "";
  7319. $link_add_ilm_atto = "";
  7320. $link_filter = "";
  7321. }
  7322. if ($value->is_directory()) {
  7323. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7324. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7325. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7326. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7327. <td><center>$author</center></td>
  7328. <td><center>$timecreated</center></td>
  7329. <td><center>$timemodified</center></td></tr>\n";
  7330. }
  7331. else if ($this->from == 'iassign') {
  7332. $new_id = "";
  7333. $new_class = "";
  7334. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7335. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7336. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7337. }
  7338. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7339. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7340. <td><center>$author</center></td>
  7341. <td><center>$timecreated</center></td>
  7342. <td><center>$timemodified</center></td></tr>\n";
  7343. }
  7344. else if ($this->from == 'block') {
  7345. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</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 == 'tinymce') {
  7352. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</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 == 'atto') {
  7359. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</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. }
  7366. }
  7367. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7368. $dir_base = "";
  7369. $header = "";
  7370. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7371. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7372. foreach ($basename as $value) {
  7373. $dir_base .= $value . "/";
  7374. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7375. if ($dir_id) {
  7376. if ($value == "") {
  7377. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7378. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7379. } else {
  7380. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7381. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7382. }
  7383. }
  7384. } // foreach ($basename as $value)
  7385. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7386. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7387. $html .= "
  7388. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7389. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7390. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7391. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7392. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7393. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7394. </table>\n";
  7395. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7396. $html .= "<table width='100%'><tr>\n";
  7397. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7398. if ($count_files != 0) {
  7399. $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";
  7400. $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";
  7401. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7402. }
  7403. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7404. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7405. $html .= "</form>\n";
  7406. print $code_javascript_ilm;
  7407. print $html;
  7408. } // function view_files_ilm($extension)
  7409. } // class ilm_manager
  7410. /// Class to insert of icons
  7411. class iassign_icons {
  7412. static function insert ($icon) {
  7413. global $CFG;
  7414. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7415. return $string;
  7416. }
  7417. }
  7418. /// Class with util functions for plugin manage
  7419. class iassign_utils {
  7420. /// Function to return the filename extension
  7421. // @param string The $filename as an string
  7422. // @return string Return an string (last group after '.')
  7423. static function filename_extension ($filename) {
  7424. if ($filename == null || $filename == '') {
  7425. return null;
  7426. }
  7427. $itens = explode('.', $filename);
  7428. $num = count($itens);
  7429. if ($num < 2) {
  7430. return null;
  7431. }
  7432. return $itens[$num - 1];
  7433. }
  7434. /// Use the PHP class/package ZipArchive to create a Zip file
  7435. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7436. // 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
  7437. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7438. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7439. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7440. $zip = new zip_archive(); //2
  7441. $res = $zip->open($full_path_zip_filename);
  7442. $total_vet = count($vet_student_filename);
  7443. for ($ii=0; $ii<$total_vet; $ii++) {
  7444. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7445. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7446. }
  7447. $ret = $zip->close();
  7448. iassign_utils::download_file($full_path_zip_filename);
  7449. $filenameZip = $zip->filename;
  7450. return array($ret, $zip);
  7451. }
  7452. static function download_file ($zip_filename) {
  7453. header("Pragma: public");
  7454. header("Expires: 0");
  7455. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7456. header("Cache-Control: private", false);
  7457. header("Content-Type: application/zip");
  7458. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7459. header("Content-Transfer-Encoding: binary");
  7460. header("Content-Length: " . @filesize($zip_filename));
  7461. set_time_limit(0);
  7462. @readfile("$zip_filename") || die("File not found.");
  7463. unlink($zip_filename);
  7464. }
  7465. /// Function for format filename remove special caracters
  7466. // @param string $text String for clean
  7467. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7468. // @return string Return an string in clean format
  7469. static function format_filename ($text) {
  7470. if ($text != '.') {
  7471. //D $text = htmlspecialchars(urldecode($text));
  7472. //D echo "locallib.php: format_filename: $text<br/>";
  7473. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7474. $text = json_decode($text)->{current_language()};
  7475. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7476. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7477. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7478. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7479. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7480. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7481. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7482. // E.g. text = "exerc_midpoint.course.geo"
  7483. // 0123456789012345678901234
  7484. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7485. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7486. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7487. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7488. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7489. //$ext = strrpos($text, ".");
  7490. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7491. //$text = str_replace($array1, $array2, $text);
  7492. }
  7493. return $text;
  7494. }
  7495. /// Function to filter characters to the file name to iLM content
  7496. // @param string $text String for clean
  7497. // @param string $ext String ot the extension of the iLM
  7498. // @return string Return an string in clean format
  7499. static function filter_filename_extension ($filename, $ext) {
  7500. if ($filename != '.') {
  7501. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7502. $arrTo = array("_","","","","","","","","","","","","");
  7503. $filename = str_replace($arrFrom, $arrTo, $filename);
  7504. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7505. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7506. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7507. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7508. $index_lastposition = strlen($filenameF);
  7509. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7510. $text = str_replace(".", "_", $text); // erase all other "."
  7511. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7512. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7513. }
  7514. else
  7515. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7516. return $filenameF;
  7517. }
  7518. /// Function for format pathname remove special caracters
  7519. // @param string $text String for clean
  7520. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7521. // @return string Return an string in clean format
  7522. static function format_pathname ($text, $is_lowercase = true) {
  7523. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7524. $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", "-", "_", "", "", "");
  7525. $text = str_replace($array1, $array2, $text);
  7526. if ($is_lowercase)
  7527. $text = strtolower($text);
  7528. return $text;
  7529. }
  7530. /// Function for format file name from iLM original name
  7531. // @param string $text String to build the file neam
  7532. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7533. // @return string Return an string in clean format
  7534. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7535. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7536. $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", "-", "_", "", "", "");
  7537. $index_firstposition_blank = strpos($ilm_name, " ");
  7538. if ($index_firstposition_blank) { // truncate the name!
  7539. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7540. }
  7541. $index_firstposition_dots = strpos($ilm_name, ":");
  7542. if ($index_firstposition_dots) { // truncate the name!
  7543. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7544. }
  7545. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7546. if ($is_lowercase)
  7547. $namefiltered = strtolower($namefiltered);
  7548. return $namefiltered;
  7549. }
  7550. /// Function for insert version in the filename
  7551. // @param string $filename Name of file
  7552. // @return string Return the filename with version
  7553. static function version_filename ($filename) {
  7554. $array_filename = explode('.', $filename);
  7555. if (count($array_filename) > 1)
  7556. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7557. else
  7558. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7559. return $filename;
  7560. }
  7561. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7562. static function remove_code_message ($string) {
  7563. $array = explode("&lt;ia_uc&gt;", $string);
  7564. return $array[0];
  7565. }
  7566. }
  7567. // class iassign_utils
  7568. /// Class with language functions for plugin manage
  7569. class iassign_language {
  7570. /// Function for return text in language or get default language (en)
  7571. // @param string $lang Code of language
  7572. // @param string $description JSON text content all languages
  7573. // @return string Return an string in the language selected
  7574. static function get_description_lang ($lang, $descriptions) {
  7575. $description_lang = "";
  7576. $description = json_decode($descriptions);
  7577. if ($description == null) {
  7578. $description_lang = $descriptions;
  7579. }
  7580. else {
  7581. if (isset($description->{$lang}))
  7582. $description_lang = $description->{$lang};
  7583. else
  7584. if (isset($description->en)) //MOOC2014
  7585. $description_lang = $description->en;
  7586. else //MOOC2014
  7587. $description_lang = "en"; //MOOC2014
  7588. }
  7589. return $description_lang;
  7590. }
  7591. /// Function for return all language supported by iLM
  7592. // @param string $descriptions JSON text content all languages
  7593. // @return string Return as string with all languages
  7594. static function get_all_lang ($descriptions) {
  7595. $langs = "";
  7596. $description = json_decode($descriptions);
  7597. if ($description) {
  7598. foreach ($description as $key => $value) {
  7599. $langs .= $key . " ; ";
  7600. }
  7601. $langs = substr($langs, 0, strlen($langs) - 3);
  7602. }
  7603. return $langs;
  7604. }
  7605. /// Function for convert json in xml //MOOC2014
  7606. // @param string $json JSON text
  7607. // @return string Return as string with xml tags
  7608. static function json_to_xml ($json) {
  7609. $xml = "";
  7610. $json = json_decode($json);
  7611. foreach ($json as $key => $value) {
  7612. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7613. }
  7614. return $xml;
  7615. }
  7616. }
  7617. // class iassign_language
  7618. /// Class with log functions for plugin manage.
  7619. class iassign_log {
  7620. /// Function for insert log event
  7621. // @param string $action Code action of event
  7622. // @param string $information Text for describe action of event
  7623. // @param int $cmid Id of context module
  7624. // @param int $ilmid Id of iLM
  7625. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7626. global $COURSE, $CFG, $USER, $DB;
  7627. $newentry = new stdClass();
  7628. $newentry->time = time();
  7629. $newentry->userid = $USER->id;
  7630. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7631. $newentry->course = $COURSE->id;
  7632. $newentry->cmid = $cmid;
  7633. $newentry->ilmid = $ilmid;
  7634. $newentry->action = $action;
  7635. $newentry->info = $information;
  7636. $newentry->language = current_language();
  7637. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7638. if (ini_get("browscap") && function_exists('get_browse')) {
  7639. $browser = get_browse(null, true);
  7640. $newentry->javascript = $browser['javascript'];
  7641. $newentry->java = $browser['javaapplets'];
  7642. }
  7643. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7644. print_error('error_add_log', 'iassign');
  7645. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7646. } // class iassign_log