locallib.php 412 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();',
  253. 'notifications' => '$this->view_notifications();');
  254. $action_iassign_limit = array(
  255. 'view' => '$this->view_iassign_current();',
  256. //'newcomment' => '$this->get_answer();',
  257. 'viewsubmission' => '$this->view_iassign_current();',
  258. 'edit_status' => '$this->edit_status();',
  259. 'edit_grade' => '$this->edit_grade();',
  260. 'export_csv' => '$this->export_csv();',
  261. 'report' => '$this->report();',
  262. 'print' => '$this->report();',
  263. 'stats' => '$this->stats();',
  264. 'printstats' => '$this->stats();');
  265. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  266. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  267. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  268. 'visible' => '$this->activity->visible_iassign($this->return);',
  269. 'delete' => '$this->activity->delete($this->return);',
  270. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  271. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  272. 'add' => '$this->add_edit_iassign();',
  273. 'edit' => '$this->add_edit_iassign();',
  274. 'get_answer' => '$this->get_answer();',
  275. 'duplicate_activity' => '$this->duplicate_activity();',
  276. 'move_activity' => '$this->move_activity();',
  277. 'auto_evaluate' => '$this->auto_evaluate();',
  278. 'all_submissions' => '$this->all_submissions();',
  279. 'delete_submissions' => '$this->delete_submissions();',
  280. 'download_submissions' => '$this->download_submissions();',
  281. 'open_individual_submission' => '$this->open_individual_submission();',
  282. 'get_individual_submission' => '$this->get_individual_submission();',
  283. 'get_student_submission' => '$this->get_student_submission();',
  284. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  285. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  286. );
  287. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  288. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  289. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  290. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  291. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  292. }
  293. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  294. eval($action_iassign_limit[$this->action]);
  295. }
  296. else { // Student reaches this point
  297. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  298. // Arrive here with: "get_answer"; "view"
  299. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  300. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  301. }
  302. } // function action()
  303. /// This method prints the student submission to a specific exercise
  304. function get_student_submission () {
  305. global $DB;
  306. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  307. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  308. if (!$student || !$exercise) exit;
  309. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  310. if ($iassign_submission)
  311. print($iassign_submission->answer);
  312. die();
  313. }
  314. /// This method prints the teacher exercise
  315. function get_teacher_exercise () {
  316. global $DB, $COURSE;
  317. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  318. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  319. $fs = get_file_storage(); // Get reference to all files in Moodle data
  320. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  321. foreach ($files as $file) {
  322. if ($file->get_filename() != ".") {
  323. print($file->get_content());
  324. }
  325. }
  326. die();
  327. }
  328. /// This method receives the data from auto_eval event
  329. /// @see auto_evaluate()
  330. function post_auto_eval_result () {
  331. global $COURSE, $CFG, $USER, $DB;
  332. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  333. exit;
  334. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  335. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  336. $student = optional_param('student', -1, PARAM_INT);
  337. $grade = optional_param('grade', 0, PARAM_FLOAT);
  338. // 1: Recuperar a nota atual:
  339. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  340. // 2: Atualizar a tabela:
  341. $update_entry = new stdClass();
  342. $update_entry->id = $actual->id;
  343. $update_entry->previous_grade = $actual->grade;
  344. $update_entry->grade = $grade;
  345. // Update the iassign_submission
  346. $DB->update_record("iassign_submission", $update_entry);
  347. }
  348. /// Function to help download all_submissions files
  349. function download_submissions_help ($list) {
  350. global $DB, $CFG, $OUTPUT;
  351. // Get list of iLMs
  352. $ilm_list = $DB->get_records("iassign_ilm");
  353. // Get list of enrolled students:
  354. $params_temp = array('shortname' => 'student');
  355. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  356. $context = context_course::instance($this->course->id);
  357. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  358. $students_list = $DB->get_records_sql(
  359. "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);
  360. $json_obj = new stdclass();
  361. $json_obj->submissions = [];
  362. $csvfields = [];
  363. $csvfields[] = 'submissionid';
  364. $csvfields[] = 'file';
  365. $csvfields[] = 'filesize';
  366. $csvfields[] = 'timestamp';
  367. $csvfields[] = 'humandate';
  368. $csvfields[] = 'grade';
  369. $csvfields[] = 'userid';
  370. $csvfields[] = 'exerciseid';
  371. $json_obj->submissions[] = $csvfields;
  372. $exercise_dir = [];
  373. $exercises_list = [];
  374. foreach ($list as $item) {
  375. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  376. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  377. $exercises_list[] = $temp;
  378. $exercise_dir[] = $temp->id;
  379. }
  380. }
  381. $student_dir = [];
  382. $students_list = [];
  383. foreach ($list as $item) {
  384. if (!in_array($item->userid, $student_dir)) {
  385. $temp = $DB->get_record("user", array("id" => $item->userid));
  386. $students_list[] = $temp;
  387. $student_dir[] = $temp->id;
  388. }
  389. }
  390. //2021 $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  391. //TODO: tem que criar moodledata/temp/iassign_files
  392. // Create $CFG->dataroot/temp/iassign_files
  393. $tempfilespath = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp';
  394. if (!file_exists($tempfilespath)) {
  395. mkdir($tempfilespath, 0777, true);
  396. }
  397. $iassignfilespath = $tempfilespath . DIRECTORY_SEPARATOR . 'iassign_files';
  398. if (!file_exists($iassignfilespath)) {
  399. mkdir($iassignfilespath, 0777, true);
  400. }
  401. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp'
  402. . DIRECTORY_SEPARATOR . 'iassign_files' . DIRECTORY_SEPARATOR;
  403. if (!file_exists($diretorio)) {
  404. 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.';
  405. exit;
  406. }
  407. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  408. $zip = new zip_archive(); // create ZIP
  409. if (!$zip->open($zip_filename)) {
  410. 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;
  411. exit;
  412. }
  413. ;
  414. foreach ($exercises_list as $exercise) {
  415. $dir_ex = iassign_utils::format_filename($exercise->name);
  416. $zip->add_directory($dir_ex);
  417. $extension_ilm = '';
  418. foreach ($ilm_list as $ilm) {
  419. if ($exercise->iassign_ilmid == $ilm->id) {
  420. $extension_ilm = $ilm->extension;
  421. break;
  422. }
  423. }
  424. foreach ($students_list as $student) {
  425. $individual_dir =
  426. $dir_ex . DIRECTORY_SEPARATOR .
  427. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  428. $zip->add_directory($individual_dir);
  429. $i = 1;
  430. foreach($list as $item) {
  431. if ($item->userid == $student->id && $item->iassign_statementid == $exercise->id) {
  432. $date = new DateTime();
  433. $date->setTimestamp($item->timecreated);
  434. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s')) . '.' . $extension_ilm;
  435. $zip->add_file_from_string($new_file, $item->answer);
  436. $temp_json = [];
  437. $temp_json[] = intval($item->id);
  438. $temp_json[] = $new_file;
  439. $temp_json[] = strlen($new_file);
  440. $temp_json[] = intval($item->timecreated);
  441. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  442. $temp_json[] = doubleval($item->grade);
  443. $temp_json[] = intval($item->userid);
  444. $temp_json[] = intval($exercise->id);
  445. $json_obj->submissions[] = $temp_json;
  446. }
  447. }
  448. }
  449. }
  450. $csv_str = "";
  451. foreach($json_obj->submissions as $sub) {
  452. $csv_str .= $this->csvstr($sub) . "\n";
  453. }
  454. $zip->add_file_from_string('index.csv', $csv_str);
  455. $zip->close();
  456. iassign_utils::download_file($zip_filename);
  457. exit;
  458. }
  459. function csvstr(array $fields) : string {
  460. $f = fopen('php://memory', 'r+');
  461. if (fputcsv($f, $fields) === false) {
  462. return false;
  463. }
  464. rewind($f);
  465. $csv_line = stream_get_contents($f);
  466. return rtrim($csv_line);
  467. }
  468. /// Download submissions from table iassign_allsubmissions
  469. function download_submissions () {
  470. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  471. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  472. exit;
  473. $type = optional_param('type', NULL, PARAM_TEXT);
  474. $item = optional_param('item', NULL, PARAM_TEXT);
  475. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  476. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  477. $sub_list = [];
  478. if ($type == 'individual') {
  479. $sub_list[] = $DB->get_record(
  480. 'iassign_allsubmissions', array('id' => $item));
  481. } elseif ($type == 'student') {
  482. $sub_list = $DB->get_records(
  483. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  484. } elseif ($type == 'exercise') {
  485. $sub_list = $DB->get_records(
  486. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  487. } elseif ($type == 'block') {
  488. $exercises_in_block = $DB->get_records(
  489. 'iassign_statement', array('iassignid' => $iassign_id));
  490. foreach ($exercises_in_block as $exercise) {
  491. $temp = $DB->get_records(
  492. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  493. $sub_list = array_merge($sub_list, $temp);
  494. }
  495. }
  496. $this->download_submissions_help($sub_list);
  497. }
  498. /// Delete submissions in table iassign_allsubmissions
  499. function delete_submissions () {
  500. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  501. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  502. exit;
  503. $type = optional_param('type', NULL, PARAM_TEXT);
  504. $item = optional_param('item', NULL, PARAM_TEXT);
  505. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  506. if ($type == 'individual') {
  507. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  508. } elseif ($type == 'student') {
  509. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  510. } elseif ($type == 'exercise') {
  511. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  512. }
  513. }
  514. function get_individual_submission () {
  515. global $DB, $USER;
  516. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  517. exit;
  518. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  519. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  520. print $submission->answer;
  521. }
  522. /// Open individual submission
  523. function open_individual_submission () {
  524. global $DB, $USER, $CFG;
  525. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  526. exit;
  527. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  528. $id = $this->cm->id;
  529. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  530. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  531. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  532. $atual_statement = $DB->get_record("iassign_statement", array("id" => $atual_submission->iassign_statementid));
  533. $all_submissions = $DB->get_records('iassign_allsubmissions',
  534. array('iassign_statementid' => $atual_submission->iassign_statementid, 'userid' => $atual_submission->userid));
  535. $user = $DB->get_record('user', array('id' => $atual_submission->userid));
  536. $previous = null;
  537. $next = null;
  538. $i = 0;
  539. $found = false;
  540. foreach($all_submissions as $individual) {
  541. if (!$found && $individual->id != $submissionid) {
  542. $previous = $individual;
  543. }
  544. if ($found) {
  545. $next = $individual;
  546. break;
  547. }
  548. if ($individual->id === $submissionid) {
  549. $found = true;
  550. }
  551. $i ++;
  552. }
  553. print '<center>';
  554. 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>';
  555. print '<tr><td>' . get_string('student', 'iassign') . '</td><td>' . $user->firstname . ' ' . $user->lastname . '</td></tr>';
  556. print '<tr><td>' . get_string('grade_student', 'iassign') . ':</td><td>' . $atual_submission->grade . '</td></tr>';
  557. print '<tr><td>' . get_string('all_submissions_manager_date', 'iassign') . ':</td><td>' . userdate($atual_submission->timecreated) . '</td></tr>';
  558. print '</table>';
  559. if ($previous) {
  560. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  561. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  562. } else {
  563. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  564. }
  565. print ' (' . $i . '/' . count($all_submissions) . ')';
  566. if ($next) {
  567. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  568. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  569. } else {
  570. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  571. }
  572. $statement = $DB->get_record('iassign_statement', array('id' => $atual_submission->iassign_statementid));
  573. print
  574. //array("type" => "editor_new", "notSEND" => "true")
  575. ilm_settings::build_ilm_tags($statement->iassign_ilmid, ['type' => "activity", 'Proposition' => $url, "notSEND" => "false"]);
  576. print '</center>';
  577. }
  578. /// Manage all submissions in exercises to table iassign_allsubmissions
  579. function all_submissions () {
  580. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  581. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  582. exit;
  583. print $OUTPUT->header();
  584. $this->print_main_menu();
  585. $id = $this->cm->id;
  586. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  587. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  588. print '
  589. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  590. <div class="modal-dialog modal-dialog-centered" role="document">
  591. <div class="modal-content">
  592. <div class="modal-header">
  593. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  594. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  595. <span aria-hidden="true">&times;</span>
  596. </button>
  597. </div>
  598. <div class="modal-body">' . get_string('all_submissions_manager_confirm', 'iassign') . '</div>
  599. <div class="modal-footer">
  600. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  601. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  602. </div>
  603. </div>
  604. </div>
  605. </div>'; // "
  606. print '
  607. <script>
  608. var sub_type;
  609. var sub_item;
  610. var sub_el;
  611. var sub_exercise;
  612. function delete_submission (type, item, el, exercise = 0) {
  613. sub_type = type;
  614. sub_item = item;
  615. sub_exercise = exercise;
  616. sub_el = el.closest("tr");
  617. if (!sub_el) sub_el = el.closest("a");
  618. $("#modalConfirm").modal();
  619. }
  620. function confirm_delete () {
  621. var url = "'.$enderecoPOST.'&action=delete_submissions";
  622. var xhttp = new XMLHttpRequest();
  623. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  624. xhttp.send();
  625. $("#modalConfirm").modal("hide");
  626. if ($(sub_el).attr("href"))
  627. $($(sub_el).attr("href")).remove();
  628. if (sub_el) sub_el.remove();
  629. }
  630. function download_submission(type, item, exercise = 0, iassign = 0) {
  631. var url = "'.$enderecoPOST.'&action=download_submissions";
  632. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  633. document.location = url;
  634. }
  635. function open_submission(item) {
  636. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  637. var poupup = window.open(url, "popup", "width=900,height=900");
  638. }
  639. </script>' . chr(13); // '
  640. // Get list of exercises in the instance:
  641. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  642. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  643. print '<h2 class="m-b-2 mt-5">' . get_string('all_submissions_manager', 'iassign') . '';
  644. 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>';
  645. // Get list of enrolled students:
  646. $params_temp = array('shortname' => 'student');
  647. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  648. $context = context_course::instance($this->course->id);
  649. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  650. $students_list = $DB->get_records_sql(
  651. "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);
  652. print '<div>';
  653. foreach ($exercises_list as $exercise) {
  654. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  655. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  656. print '
  657. <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> '
  658. . $exercise->name
  659. . ' - ' . $iassign_ilm->name
  660. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  661. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  662. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  663. . $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> '
  664. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  665. . '</a>';
  666. print '<div class="collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  667. foreach ($students_list as $student) {
  668. $total = 0;
  669. $student_submissions = [];
  670. foreach ($submissions_list as $submission) {
  671. if ($submission->userid == $student->userid) {
  672. $student_submissions[] = $submission;
  673. $total ++;
  674. }
  675. }
  676. 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");\'>
  677. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  678. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  679. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  680. . '<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> '
  681. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  682. . ' </a>';
  683. print '<div class="collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  684. print '<table class="table table-striped table-hover"><thead>
  685. <tr>
  686. <th scope="col">#</th>
  687. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  688. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  689. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  690. </tr>
  691. </thead><tbody>'; // "
  692. $i = 1;
  693. foreach ($student_submissions as $individual) {
  694. $date = new DateTime();
  695. $date->setTimestamp($individual->timecreated);
  696. print '<tr>';
  697. print '<td>'.$i++.'</td>';
  698. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  699. print '<td>'.$individual->grade.'</td>';
  700. print '<td>
  701. <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>
  702. <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>
  703. <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>';
  704. print " </tr>\n";
  705. }
  706. print '</tbody></table>';
  707. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  708. print '</div>';
  709. }
  710. print '</div>';
  711. }
  712. print '</div>';
  713. print $OUTPUT->footer();
  714. } // function all_submissions()
  715. /// This method runs activities auto evaluation in teacher area
  716. function auto_evaluate () {
  717. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  718. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  719. exit;
  720. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  721. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  722. // Get list of exercises in the instance:
  723. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  724. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  725. // Get list of enrolled students:
  726. $params_temp = array('shortname' => 'student');
  727. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  728. $context = context_course::instance($this->course->id);
  729. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  730. $students_list = $DB->get_records_sql(
  731. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  732. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  733. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  734. print $OUTPUT->header();
  735. $this->print_main_menu();
  736. print '<div class="mt-5 mb-4"><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  737. print '<ul style="list-style-type: none; margin: 1em;">';
  738. foreach ($exercises_list as $exercise) {
  739. $matches = [];
  740. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  741. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  742. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  743. if ($matches[0][0]) {
  744. 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>';
  745. } else {
  746. 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>';
  747. }
  748. } else {
  749. if ($matches[0][0]) {
  750. 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>';
  751. } else {
  752. 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>';
  753. }
  754. }
  755. }
  756. print '</ul>
  757. <center>
  758. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  759. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  760. <div id="evaluate_message" style="color: red"></div>
  761. <div id="evaluate_alerts"></div>
  762. <div>
  763. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  764. <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>
  765. </div>
  766. </center>'; // close "
  767. print ' </div>';
  768. print ' <script>';
  769. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  770. print ' var submissions = [';
  771. // Get list of student id have submit for each exercise:
  772. foreach ($exercises_list as $exercise) {
  773. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  774. print '
  775. {
  776. "exerciseid": "' . $exercise->id . '",
  777. "grade": ' . $exercise->grade . ',
  778. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  779. "submited": ['; // "
  780. $params_temp = array('iassign_statementid' => $exercise->id);
  781. $submited = $DB->get_records_sql( // Get userid and his grade
  782. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  783. " WHERE s.iassign_statementid = :iassign_statementid", $params_temp);
  784. foreach ($submited as $ss) {
  785. print($ss->userid . ',');
  786. }
  787. print '],';
  788. print '"allgrades": [';
  789. foreach ($submited as $ss) {
  790. print( $ss->grade . ',');
  791. }
  792. print ']
  793. },'; // close "
  794. } // foreach ($exercises_list as $exercise)
  795. print " ];\n";
  796. print '
  797. var total_submissions = 0;
  798. var selected_exercises;
  799. var count_steps;
  800. var value_by_step;
  801. var stoped = false;
  802. var time_interval = 5000;
  803. var var_interval;
  804. function add_hover_th (id_th, id_li) { //AJAX
  805. $("#" + id_th).hover(function() {
  806. $("#" + id_li).css("background-color", "#d9d8d8");
  807. $(this).css("background-color", "#d9d8d8");
  808. }, function() {
  809. $("#" + id_li).css("background-color", "");
  810. $(this).css("background-color", "");
  811. });
  812. }
  813. function start_evaluation () {
  814. stoped = false;
  815. //AJAX
  816. $("#progress_bar").css("display", "none");
  817. $("#evaluate_message").text("");
  818. $("#evaluate_alerts").text("");
  819. $(".added-col").remove();
  820. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  821. selected_exercises = [];
  822. var c = 0;
  823. for (var i = 0; i < exercises.length; i++) {
  824. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  825. selected_exercises[c++] = exercises[i];
  826. }
  827. }
  828. if (selected_exercises.length == 0) {
  829. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  830. return;
  831. } else {
  832. $("input:checkbox").attr("disabled", true); //AJAX
  833. for (var i = 0; i < selected_exercises.length; i++) {
  834. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  835. //AJAX
  836. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  837. $("#table-results tbody tr").each(function(e) {
  838. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  839. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  840. });
  841. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  842. }
  843. //AJAX
  844. $("#button_start").prop("disabled", true);
  845. $("#button_stop").prop("disabled", false);
  846. $("#progress_bar").css("display", "block");
  847. }
  848. total_submissions = selected_exercises.length * students.length;
  849. count_steps = 0;
  850. value_by_step = 100/total_submissions;
  851. actual_exercise = 0;
  852. actual_student = 0;
  853. actual_submission = 0;
  854. get_original_propositions();
  855. var_interval = setInterval(verifyBreak, time_interval);
  856. } // function start_evaluation()
  857. var actual_exercise;
  858. var actual_student;
  859. var actual_submission;
  860. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  861. function run_individual_evaluation () {
  862. if (stoped) return;
  863. // Verify if student really sent his answer
  864. var found = false;
  865. for (var j = 0; j < submissions.length; j++) {
  866. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  867. for (var k = 0; k < submissions[j].submited.length; k++) {
  868. if (students[actual_student] == submissions[j].submited[k]) {
  869. found = true;
  870. break;
  871. }
  872. }
  873. break;
  874. }
  875. }
  876. if (found == false) {
  877. postResultAutoEval();
  878. } else {
  879. // If it was sent, search it...
  880. var final_url = "";
  881. 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];
  882. for (var j = 0; j < submissions.length; j++) {
  883. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  884. final_url = submissions[j].ilm;
  885. break;
  886. }
  887. }
  888. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  889. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  890. window.frames["ifrm"].location=final_url;
  891. }
  892. } // function run_individual_evaluation()
  893. var break_student = -1;
  894. var break_exercise = -1;
  895. function verifyBreak () {
  896. if (actual_student == break_student && actual_exercise == break_exercise) {
  897. postResultAutoEval(-6);
  898. break_student = -1;
  899. break_exercise = -1;
  900. return;
  901. } else {
  902. break_student = actual_student;
  903. break_exercise = actual_exercise;
  904. }
  905. }
  906. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  907. function getStudentAnswerURL () {
  908. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  909. }
  910. // This function is called by the iLM!!!
  911. function getAutoEvalOriginalData () {
  912. return original_propositions[actual_exercise];
  913. }
  914. function updateProgressBar () {
  915. if (stoped) return;
  916. var temp = (count_steps * value_by_step)|0;
  917. count_steps ++;
  918. temp = temp > 100 ? 100 : temp;
  919. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  920. if (temp >= 100) {
  921. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  922. $("#button_start").prop("disabled", false);
  923. $("#button_stop").prop("disabled", true);
  924. $("input:checkbox").attr("disabled", false);
  925. clearInterval(var_interval);
  926. }
  927. }
  928. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  929. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  930. function postResultAutoEval (grade = null) {
  931. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  932. if (grade == null) {
  933. $("#"+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>\');
  934. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  935. } else {
  936. // Verify if the re-evaluation grade is the of that one registered:
  937. var actual_value = 0;
  938. var actual_student_grade = 0;
  939. for (var k = 0; k < submissions.length; k++) {
  940. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  941. actual_value = submissions[k].grade;
  942. for (var h = 0; h < submissions[k].submited.length; h++) {
  943. if (submissions[k].submited[h] == students[actual_student]) {
  944. actual_student_grade = submissions[k].allgrades[h];
  945. break;
  946. }
  947. }
  948. break;
  949. }
  950. }
  951. // @FeedbackConvention
  952. if (grade < 0) {
  953. switch (grade) {
  954. case -1:
  955. // Test-cases are empty:
  956. $("#"+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>\');
  957. var mm = actual_exercise;
  958. $("#"+id_t).find(".details-button").click(function(e) {
  959. $(".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>\');
  960. });
  961. break;
  962. case -2:
  963. // Test-cases were manually altered by the student (fraud!):
  964. $("#"+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>\');
  965. var mm = actual_exercise;
  966. $("#"+id_t).find(".details-button").click(function(e) {
  967. $(".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>");
  968. });
  969. //AJAX
  970. $.ajax({
  971. dataType: "html",
  972. 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",
  973. success: function(d) {} });
  974. break;
  975. case -5:
  976. // Execution failed:
  977. $("#"+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>\');
  978. var mm = actual_exercise;
  979. //AJAX
  980. $("#"+id_t).find(".details-button").click(function(e) {
  981. $(".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>\');
  982. });
  983. break;
  984. case -6: // iLM not answering was detected in "verifyBreak()"
  985. // The iLM are not answering:
  986. //AJAX
  987. $("#"+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>\');
  988. $("#"+id_t).find(".details-button").click(function(e) {
  989. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  990. });
  991. break;
  992. }
  993. //AJAX
  994. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  995. } else {
  996. console.log((grade), (actual_student_grade));
  997. if ((grade) == (actual_student_grade)) {
  998. $("#"+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>\');
  999. } else { // Notas diferem:
  1000. $("#"+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>\');
  1001. var mm = actual_exercise;
  1002. //AJAX
  1003. $("#"+id_t).find(".details-button").click(function(e) {
  1004. $(".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>\');
  1005. });
  1006. //AJAX
  1007. // Send to the endpoint the post_auto_eval_result to verify:
  1008. $.ajax({
  1009. dataType: "html",
  1010. 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),
  1011. success: function(d) {}
  1012. });
  1013. }
  1014. //AJAX
  1015. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  1016. }
  1017. }
  1018. updateProgressBar();
  1019. // Does it must continue in the same exercise or stop?
  1020. if (actual_student < students.length) {
  1021. actual_student ++;
  1022. run_individual_evaluation();
  1023. } else {
  1024. actual_student = 0;
  1025. // Does it go to next exercise or is it finished?
  1026. if (actual_exercise < selected_exercises.length) {
  1027. actual_exercise++;
  1028. run_individual_evaluation();
  1029. } else {
  1030. //AJAX
  1031. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1032. }
  1033. }
  1034. }
  1035. var original_propositions;
  1036. function get_original_propositions () {
  1037. original_propositions = [];
  1038. var count = 0;
  1039. for (var i = 0; i < exercises.length; i++) {
  1040. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1041. //AJAX
  1042. $.ajax({
  1043. dataType: "html",
  1044. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1045. success: function(d) { // variable "d" has the iLM content
  1046. original_propositions[count] = d; // exercise original content
  1047. count ++;
  1048. if (count == selected_exercises.length) {
  1049. run_individual_evaluation();
  1050. }
  1051. }
  1052. });
  1053. }
  1054. }
  1055. }
  1056. function stop_evaluation () {
  1057. stoped = true;
  1058. //AJAX
  1059. $("#button_start").prop("disabled", false);
  1060. $("#button_stop").prop("disabled", true);
  1061. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1062. $("input:checkbox").attr("disabled", false);
  1063. $("#evaluate_alerts").text("' . get_string('auto_evaluate_stopped', 'iassign') . '");
  1064. clearInterval(var_interval);
  1065. }
  1066. var exercises = [ '; // '
  1067. foreach ($exercises_list as $exercise) {
  1068. print $exercise->id . ',';
  1069. }
  1070. print ' ];';
  1071. print ' var students = [ ';
  1072. foreach ($students_list as $student) {
  1073. print $student->userid . ',';
  1074. }
  1075. print '];';
  1076. print ' var ilms = [';
  1077. foreach ($exercises_list as $exercise) {
  1078. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1079. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1080. }
  1081. print ']';
  1082. print '</script>';
  1083. print '
  1084. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1085. <div class="modal-dialog modal-dialog-centered" role="document">
  1086. <div class="modal-content">
  1087. <div class="modal-header">
  1088. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1089. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1090. <span aria-hidden="true">&times;</span>
  1091. </button>
  1092. </div>
  1093. <div class="modal-body">
  1094. ...
  1095. </div>
  1096. <div class="modal-footer">
  1097. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1098. </div>
  1099. </div>
  1100. </div>
  1101. </div>'; //
  1102. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1103. print '<table id="table-results" class="table table-hover m-t-1">
  1104. <thead>
  1105. <tr id="cols-exercises">
  1106. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1107. </tr>
  1108. </thead>
  1109. <tbody>'; // "
  1110. foreach ($students_list as $student) {
  1111. $user = $DB->get_record('user', array('id' => $student->userid));
  1112. $avatar = new user_picture($user);
  1113. $avatar->courseid = $COURSE->id;
  1114. $avatar->link = true;
  1115. print ' <tr data-student="' . $student->userid . '">
  1116. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1117. </tr>' . "\n"; // "
  1118. }
  1119. print " </tbody>
  1120. </table>\n";
  1121. print $OUTPUT->footer();
  1122. } // function auto_evaluate()
  1123. /// This method moves an iAssign activity
  1124. function move_activity () {
  1125. global $USER, $CFG, $DB, $COURSE;
  1126. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1127. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1128. $update_entry_new_iassign = new stdClass();
  1129. $update_entry_new_iassign->id = $iassign_id;
  1130. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1131. // Update the iassign_statement
  1132. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1133. // Update file context
  1134. $c_i = context_module::instance($this->cm->id);
  1135. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1136. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1137. $path_module = context_course::instance($COURSE->id);
  1138. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1139. $course_module = get_coursemodule_from_instance('iassign', $iassign_destiny);
  1140. if ($context_file) {
  1141. $id_context = $context_file->id;
  1142. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1143. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1144. $context = context_module::instance($USER->cm);
  1145. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->id);
  1146. foreach ($files as $value) {
  1147. if ($value->get_filename() != ".") {
  1148. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1149. $newfile = null;
  1150. $destiny_context = context_module::instance($course_module->id);
  1151. $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());
  1152. $updateentry = new stdClass();
  1153. $updateentry->id = $iassign_id;
  1154. $updateentry->filesid = $iassign_id;
  1155. $DB->update_record("iassign_statement", $updateentry);
  1156. break;
  1157. }
  1158. }
  1159. }
  1160. $destiny_url = new moodle_url('/mod/iassign/view.php', array('id' => $course_module->id));
  1161. 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);
  1162. exit;
  1163. }
  1164. /// This method duplicates an iAssign activity
  1165. function duplicate_activity () {
  1166. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1167. $id = $this->cm->id;
  1168. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1169. $context = context_module::instance($this->cm->id);
  1170. $contextuser = context_user::instance($USER->id);
  1171. // Get the the iAssign acitivity to be duplicated
  1172. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1173. // Remove the current id of activity
  1174. $id_source_copy = $iassign_statement->id;
  1175. $iassign_statement->id=0;
  1176. // Include prefix (Copy of ...)
  1177. $iassign_statement->name = get_string('duplicate_iassign_prefix', 'iassign') . ' ' . $iassign_statement->name;
  1178. // Get the information about current author, and add this information in author_modified field
  1179. $author = $DB->get_record("user", array('id' => $USER->id));
  1180. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1181. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1182. // Store the activity in the table
  1183. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1184. // Duplicate activity file
  1185. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1186. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $id_source_copy);
  1187. foreach ($files as $value) {
  1188. if ($value->get_filename() != ".") {
  1189. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1190. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $id_), $value);
  1191. $updateentry = new stdClass();
  1192. $updateentry->id = $id_;
  1193. $updateentry->filesid = $id_;
  1194. // Update the duplicated iLM iAssign with new file id
  1195. $DB->update_record("iassign_statement", $updateentry);
  1196. }
  1197. }
  1198. }
  1199. // log event --------------------------------------------------------------------------------------
  1200. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1201. $this->return_home_course('duplicated_activity');
  1202. exit;
  1203. }
  1204. // / This method gets the content from comment and register it
  1205. function add_comment () {
  1206. global $USER, $DB;
  1207. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1208. $comment = false;
  1209. if ($submission_comment)
  1210. $comment = $this->write_comment_submission();
  1211. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1212. if (!$id_submission) {
  1213. $iassign_submission =
  1214. $DB->get_record("iassign_submission",
  1215. array(
  1216. "iassign_statementid" => $this->activity->get_activity()->id,
  1217. "userid" => $USER->id
  1218. )
  1219. );
  1220. if ($iassign_submission) {
  1221. $id_submission = $iassign_submission->id;
  1222. }
  1223. }
  1224. $content = $this->search_comment_submission($id_submission);
  1225. ob_end_clean();
  1226. header("Connection: close\r\n");
  1227. header("Content-Encoding: none\r\n");
  1228. header('Content-Type: text/html');
  1229. ob_start();
  1230. echo $this->search_comment_submission($id_submission);
  1231. $size = ob_get_length();
  1232. header("Content-Length: $size");
  1233. ob_end_flush();
  1234. flush();
  1235. ob_end_clean();
  1236. // Send email to users:
  1237. $iassign_submission =
  1238. $DB->get_record("iassign_submission",
  1239. array(
  1240. "id" => $id_submission
  1241. )
  1242. );
  1243. $this->send_alert_new_comment($submission_comment, $iassign_submission->userid);
  1244. }
  1245. /// This method alerts envolved to new comment sent
  1246. function send_alert_new_comment ($comment, $student_id = -1) {
  1247. global $USER, $DB, $COURSE, $SITE;
  1248. $subject = $COURSE->shortname . ": " . get_string('new_comment_mail_subject', 'iassign');
  1249. $url_curso;
  1250. $url_submissao;
  1251. $text = "<p style='margin-top: 1rem;'>";
  1252. $text .= "<a href=\""
  1253. . new moodle_url('/course/view.php', array('id' => $COURSE->id))
  1254. . "\">" . $COURSE->shortname . "</a> "
  1255. . " &#8811; ";
  1256. $modinfo = get_fast_modinfo($COURSE);
  1257. for ($i = 0; $i < count($modinfo->sections); $i++) {
  1258. if ($modinfo->get_section_info($i)
  1259. && $modinfo->get_section_info($i)->id == $this->cm->section) {
  1260. $url_curso = new moodle_url('/course/view.php', array('id' => $COURSE->id));
  1261. $text .= "<a href=\""
  1262. . $url_curso . "#section-" . $modinfo->get_section_info($i)->section . "\">" . get_section_name($COURSE, $modinfo->get_section_info($i)->section)
  1263. . "</a> &#8811; ";
  1264. break;
  1265. }
  1266. }
  1267. $iassign = $DB->get_record('iassign', array('id' => $this->activity->get_activity()->iassignid));
  1268. $text .= "<a href=\""
  1269. . new moodle_url('/mod/iassign/view.php', array('id' => $this->cm->id))
  1270. . "\">"
  1271. . $iassign->name
  1272. . "</a>";
  1273. $text .= " &#8811; ";
  1274. $url_submissao = new moodle_url('/mod/iassign/view.php',
  1275. array(
  1276. 'id' => $this->cm->id,
  1277. 'action' => 'viewsubmission',
  1278. 'iassign_current' => $this->activity->get_activity()->id,
  1279. 'userid_iassign' => $USER->id));
  1280. $text .= "<a href=\""
  1281. . $url_submissao
  1282. . "\">"
  1283. . $this->activity->get_activity()->name
  1284. . "</a>";
  1285. $text .= "</p>";
  1286. $text .= "<div style='margin-left: .5rem;'>";
  1287. $text .= get_string('new_comment_mail_course', 'iassign') . ": <a href=\"" . $url_curso . "\">" . $COURSE->fullname . "</a>";
  1288. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1289. $text .= get_string('exercise', 'iassign') . ": <a href=\"" . $url_submissao . "\">" . $this->activity->get_activity()->name . "</a>";
  1290. $text .= "</div><div style='margin-top: .3rem; margin-left: .5rem;'>";
  1291. $text .= get_string('new_comment_mail_sent_by', 'iassign') . ': '
  1292. . "<a href=\"" . new moodle_url('/user/view.php', array('id' => $USER->id, 'course' => $COURSE->id)) . "\">"
  1293. . $USER->firstname . " " . $USER->lastname
  1294. . "</a>";
  1295. $text .= " - " . userdate(time());
  1296. $text .= "</div><div style='margin: 2rem;'>";
  1297. $text .= $comment;
  1298. $text .= "</div><div>";
  1299. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_open_exercise', 'iassign') . "</a> | ";
  1300. $text .= "<a href=\"" . $url_submissao . "#comments\">" . get_string('new_comment_mail_answer', 'iassign') . "</a>";
  1301. $text .= "</div>";
  1302. // Who has to receive?
  1303. $teachers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign');
  1304. $userfrom = \core_user::get_noreply_user();
  1305. if (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) { // a teacher has sent the comment:
  1306. // other teachers receive also: (excepts the sender)
  1307. foreach ($teachers as $teacher) {
  1308. if ($teacher->id != $USER->id) {
  1309. email_to_user(
  1310. $teacher,
  1311. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1312. $subject,
  1313. "",
  1314. $text,
  1315. '',
  1316. '',
  1317. false,
  1318. $userfrom->email,
  1319. 'Não responda a esta mensagem'
  1320. );
  1321. $message = new \core\message\message();
  1322. $message->component = 'mod_iassign';
  1323. $message->name = 'message';
  1324. $message->userfrom = core_user::get_noreply_user();
  1325. $message->userto = $teacher;
  1326. $message->subject = $subject;
  1327. $message->fullmessage = $text;
  1328. $message->fullmessageformat = FORMAT_MARKDOWN;
  1329. $message->fullmessagehtml = $text;
  1330. $message->smallmessage = $subject;
  1331. $message->notification = 1;
  1332. $message->contexturl = $url_submissao . '#comments';
  1333. $message->contexturlname = $this->activity->get_activity()->name;
  1334. $messageid = message_send($message);
  1335. }
  1336. }
  1337. // and student:
  1338. $student = $DB->get_record('user', array('id' => $student_id));
  1339. $formated_text = str_replace("viewsubmission", "view", $text);
  1340. email_to_user(
  1341. $student,
  1342. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1343. $subject,
  1344. "",
  1345. $formated_text,
  1346. '',
  1347. '',
  1348. false,
  1349. $userfrom->email,
  1350. 'Não responda a esta mensagem'
  1351. );
  1352. $url_student = new moodle_url('/mod/iassign/view.php',
  1353. array(
  1354. 'id' => $this->cm->id,
  1355. 'action' => 'view',
  1356. 'iassign_current' => $this->activity->get_activity()->id));
  1357. $message = new \core\message\message();
  1358. $message->component = 'mod_iassign';
  1359. $message->name = 'message';
  1360. $message->userfrom = core_user::get_noreply_user();
  1361. $message->userto = $student;
  1362. $message->subject = $subject;
  1363. $message->fullmessage = $formated_text;
  1364. $message->fullmessageformat = FORMAT_MARKDOWN;
  1365. $message->fullmessagehtml = $formated_text;
  1366. $message->smallmessage = $subject;
  1367. $message->notification = 1;
  1368. $message->contexturl = $url_student . '#comments';
  1369. $message->contexturlname = $this->activity->get_activity()->name;
  1370. $messageid = message_send($message);
  1371. } else { // a student has sent the comment:
  1372. foreach ($teachers as $teacher) {
  1373. email_to_user(
  1374. $teacher,
  1375. $USER->firstname . " " . $USER->lastname . " (via " . $SITE->shortname . ")",
  1376. $subject,
  1377. "",
  1378. $text,
  1379. '',
  1380. '',
  1381. false,
  1382. $userfrom->email,
  1383. 'Não responda a esta mensagem'
  1384. );
  1385. $message = new \core\message\message();
  1386. $message->component = 'mod_iassign';
  1387. $message->name = 'message';
  1388. $message->userfrom = core_user::get_noreply_user();
  1389. $message->userto = $teacher;
  1390. $message->subject = $subject;
  1391. $message->fullmessage = $text;
  1392. $message->fullmessageformat = FORMAT_MARKDOWN;
  1393. $message->fullmessagehtml = $text;
  1394. $message->smallmessage = $subject;
  1395. $message->notification = 1;
  1396. $message->contexturl = $url_submissao . '#comments';
  1397. $message->contexturlname = $this->activity->get_activity()->name;
  1398. $messageid = message_send($message);
  1399. }
  1400. }
  1401. }
  1402. /// This method gets the content from the iLM and register it
  1403. // It could be the "exercise template" (teacher) or an answer (student)
  1404. function get_answer () {
  1405. global $USER, $CFG, $DB, $OUTPUT;
  1406. $id = $this->cm->id;
  1407. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1408. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1409. if ($submission_ajax == 1) ob_start();
  1410. $comment = false;
  1411. if ($submission_comment)
  1412. $comment = $this->write_comment_submission();
  1413. // receives data of iLM using the current activity
  1414. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1415. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1416. // receives data of submission of current activity
  1417. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1418. // receives post and get
  1419. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1420. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1421. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1422. $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)
  1423. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1424. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1425. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1426. $msg = '';
  1427. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1428. $newentry = new stdClass();
  1429. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1430. $newentry->userid = $this->userid_iassign;
  1431. $newentry->timecreated = time();
  1432. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1433. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1434. $DB->insert_record("iassign_allsubmissions", $newentry);
  1435. }
  1436. // Feedback
  1437. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1438. $str_action = "view"; // repeat
  1439. if (strtolower($iassign_ilm->name) == "igeom") {
  1440. }
  1441. $title = get_string('evaluate_iassign', 'iassign');
  1442. print $OUTPUT->header();
  1443. print $OUTPUT->box_start();
  1444. // Action = { view ; repeat ; viewsubmission }
  1445. // * '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")
  1446. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1447. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1448. $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;
  1449. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1450. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1451. print '<table width=100% >';
  1452. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1453. //TODO alterar aqui???
  1454. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1455. // empty_answer_post = No solution was posted.
  1456. if ($comment)
  1457. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1458. else
  1459. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1460. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1461. } else {
  1462. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1463. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1464. // Correct answer!!
  1465. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1466. $this->write_solution = 1; //
  1467. $status = 3;
  1468. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1469. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1470. // log record
  1471. $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;
  1472. // Trigger module viewed event.
  1473. $event = \mod_iassign\event\submission_created::create(array(
  1474. 'objectid' => $this->iassign->id,
  1475. 'context' => $this->context,
  1476. 'other' => $info
  1477. ));
  1478. $event->add_record_snapshot('course', $this->course);
  1479. $event->trigger();
  1480. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1481. // Wrong answer...: get_answer_incorrect
  1482. $status = 2;
  1483. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1484. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1485. // log record
  1486. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1487. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1488. // Trigger module viewed event.
  1489. $event = \mod_iassign\event\submission_created::create(array(
  1490. 'objectid' => $this->iassign->id,
  1491. 'context' => $this->context,
  1492. 'other' => $info
  1493. ));
  1494. $event->add_record_snapshot('course', $this->course);
  1495. $event->trigger();
  1496. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1497. // Presents to the learner the result of the automatic evaluate?
  1498. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1499. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1500. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1501. print '<tr>';
  1502. // log record
  1503. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1504. // Trigger module viewed event.
  1505. $event = \mod_iassign\event\submission_created::create(array(
  1506. 'objectid' => $this->iassign->id,
  1507. 'context' => $this->context,
  1508. 'other' => $info
  1509. ));
  1510. $event->add_record_snapshot('course', $this->course);
  1511. $event->trigger();
  1512. } else { // yes!!!
  1513. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1514. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1515. print '<tr>';
  1516. print $msg;
  1517. }
  1518. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1519. $status = 1;
  1520. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1521. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1522. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1523. print '<tr>';
  1524. // log record
  1525. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1526. $event = \mod_iassign\event\submission_created::create(array(
  1527. 'objectid' => $this->iassign->id,
  1528. 'context' => $this->context,
  1529. 'other' => $info
  1530. ));
  1531. $event->add_record_snapshot('course', $this->course);
  1532. $event->trigger();
  1533. } // if ($iassign_ilm->evaluate == 1)
  1534. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1535. print '</tr></table>';
  1536. print $OUTPUT->box_end();
  1537. // add or update evaluate
  1538. if ($this->write_solution == 1) {
  1539. $timenow = time();
  1540. // new record
  1541. if (!$iassign_submission) {
  1542. $newentry = new stdClass();
  1543. $newentry->userid = $this->userid_iassign;
  1544. // $newentry->userid = $USER->id;
  1545. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1546. $newentry->timecreated = $timenow;
  1547. $newentry->timemodified = $timenow;
  1548. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1549. $newentry->grade = round($grade_student, 2);
  1550. $newentry->status = $status;
  1551. $newentry->experiment = 1;
  1552. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1553. print_error('error_insert', 'iassign');
  1554. } else {
  1555. // Trigger module viewed event.
  1556. $event = \mod_iassign\event\submission_created::create(array(
  1557. 'objectid' => $this->iassign->id,
  1558. 'context' => $this->context
  1559. ));
  1560. $event->add_record_snapshot('course', $this->course);
  1561. $event->trigger();
  1562. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1563. }
  1564. } elseif ($iassign_submission->status != 3) {
  1565. $newentry = new stdClass();
  1566. $newentry->id = $iassign_submission->id;
  1567. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1568. $newentry->userid = $iassign_submission->userid;
  1569. $newentry->timecreated = $iassign_submission->timecreated;
  1570. $newentry->timemodified = $timenow;
  1571. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1572. $newentry->grade = round($grade_student, 2);
  1573. $newentry->status = $status;
  1574. $newentry->experiment = $iassign_submission->experiment + 1;
  1575. if (!$DB->update_record("iassign_submission", $newentry)) {
  1576. print_error('error_update', 'iassign');
  1577. //D depurar...
  1578. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1579. //D $fp = fopen("teste1.txt","w");
  1580. //D fwrite($fp,$stringAux);
  1581. } else {
  1582. // Trigger module viewed event.
  1583. $event = \mod_iassign\event\submission_updated::create(array(
  1584. 'objectid' => $this->iassign->id,
  1585. 'context' => $this->context
  1586. ));
  1587. $event->add_record_snapshot('course', $this->course);
  1588. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1589. }
  1590. } else {
  1591. if ($return_get_answer == 1) {
  1592. $newentry = new stdClass();
  1593. $newentry->id = $iassign_submission->id;
  1594. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1595. $newentry->userid = $iassign_submission->userid;
  1596. $newentry->timecreated = $iassign_submission->timecreated;
  1597. $newentry->timemodified = $timenow;
  1598. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1599. $newentry->grade = round($grade_student, 2);
  1600. $newentry->status = $status;
  1601. $newentry->experiment = $iassign_submission->experiment + 1;
  1602. if (!$DB->update_record("iassign_submission", $newentry))
  1603. print_error('error_update', 'iassign');
  1604. else {
  1605. $event = \mod_iassign\event\submission_updated::create(array(
  1606. 'objectid' => $this->iassign->id,
  1607. 'context' => $this->context
  1608. ));
  1609. $event->add_record_snapshot('course', $this->course);
  1610. $event->trigger();
  1611. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1612. print $OUTPUT->box_start();
  1613. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1614. print $OUTPUT->box_end();
  1615. }
  1616. } elseif ($return_get_answer == 2) {
  1617. print $OUTPUT->box_start();
  1618. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1619. print $OUTPUT->box_end();
  1620. } else {
  1621. print $OUTPUT->box_start();
  1622. print "
  1623. <script type='text/javascript'>
  1624. //<![CDATA[
  1625. function overwrite () {
  1626. document.formEnvio.return_get_answer.value = 1;
  1627. document.formEnvio.submit();
  1628. }
  1629. function nooverwrite () {
  1630. document.formEnvio.return_get_answer.value = 2;
  1631. document.formEnvio.submit();
  1632. }
  1633. //]]>
  1634. </script>";
  1635. $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;
  1636. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1637. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1638. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1639. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1640. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1641. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1642. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1643. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1644. <input type='hidden' name='return_get_answer'/> ";
  1645. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1646. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1647. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1648. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1649. print " </form>";
  1650. print $OUTPUT->box_end();
  1651. }
  1652. }
  1653. } // if ($this->write_solution == 1)
  1654. print $OUTPUT->footer();
  1655. if ($submission_ajax == 1) {
  1656. ob_end_clean();
  1657. print 'OK';
  1658. }
  1659. die();
  1660. } // function get_answer()
  1661. /// Export in file the answer of student.
  1662. function export_file_answer () {
  1663. global $DB;
  1664. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1665. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1666. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1667. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1668. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1669. $extensions = explode(",", $iassign_ilm->extension);
  1670. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1671. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1672. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1673. header("Pragma: public");
  1674. header("Expires: 0");
  1675. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1676. header("Cache-Control: private", false);
  1677. header("Content-Type: document/unknown");
  1678. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1679. set_time_limit(0);
  1680. print($iassign_submission->answer);
  1681. exit;
  1682. } // function export_file_answer()
  1683. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1684. // @calledby $this->export_package_answer()
  1685. //TODO Precisa terminar! //TODO_HTML
  1686. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1687. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1688. <head>
  1689. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1690. $str_html .= " </head>
  1691. <body>\n";
  1692. $tam = sizeof($array_iassign_name);
  1693. for ($ii=0; $ii<$tam; $ii++) {
  1694. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1695. }
  1696. $str_html .= "
  1697. </body>\n</html>";
  1698. return $str_html;
  1699. }
  1700. /// Export an package (zip) with all answer of students
  1701. // @calledby $this->action()
  1702. function export_package_answer () {
  1703. global $DB, $CFG, $OUTPUT;
  1704. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1705. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1706. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1707. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1708. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1709. $userid = optional_param('userid', NULL, PARAM_INT);
  1710. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1711. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1712. //TODO_HTML echo "username=$username<br/>"; exit;
  1713. $current_date = date('Y_m_d_H');
  1714. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1715. // If temporary directory under Moodle data does not exists => create it
  1716. if (!is_dir($diretorio)) {
  1717. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1718. // created directory with permissions to be seen by everyone
  1719. }
  1720. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1721. if (!is_writable($diretorio)) { // send a highlighted message!
  1722. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1723. exit; // just in case
  1724. }
  1725. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1726. $zip = new zip_archive(); // create ZIP
  1727. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1728. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1729. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1730. $vet_student_filename = array();
  1731. $vet_student_content = array();
  1732. foreach ($iassign_statements as $iassign_statement) {
  1733. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1734. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1735. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1736. $extensions = explode(",", $iassign_ilm->extension);
  1737. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1738. if ($iassign_submission) {
  1739. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1740. $student_content = $iassign_submission->answer;
  1741. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1742. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1743. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1744. if ($resp) {
  1745. $vet_student_filename[] = $student_filename;
  1746. $vet_student_content[] = $student_content;
  1747. }
  1748. else { // send a highlighted message!
  1749. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1750. exit; // just in case
  1751. }
  1752. }
  1753. }
  1754. $zip->close(); // close the ZIP file
  1755. if (count($vet_student_filename)>0) {
  1756. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1757. $result_tf = $vet_result[0];
  1758. $filenameZip = $vet_result[1]->filename;
  1759. }
  1760. iassign_utils::download_file($zip_filename); // download the ZIP file
  1761. exit;
  1762. } // function export_package_answer()
  1763. /// Editing status of interactive activities
  1764. function edit_status () {
  1765. global $USER, $DB, $OUTPUT;
  1766. $newentry = new stdClass();
  1767. $newentry->id = $this->iassign_submission_current;
  1768. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1769. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1770. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1771. $newentry->status = $iassign_submission->status;
  1772. $newentry->teacher = $USER->id;
  1773. if (!$DB->update_record('iassign_submission', $newentry))
  1774. print_error('error_update', 'iassign');
  1775. else {
  1776. // Trigger module viewed event.
  1777. $event = \mod_iassign\event\submission_updated::create(array(
  1778. 'objectid' => $this->iassign->id,
  1779. 'context' => $this->context
  1780. ));
  1781. $event->add_record_snapshot('course', $this->course);
  1782. $event->trigger();
  1783. $this->action = 'viewsubmission';
  1784. $this->view_iassign_current();
  1785. } // if (!$DB->update_record('iassign_submission', $newentry))
  1786. } // function edit_status()
  1787. /// Editing grade of interactive activities
  1788. function edit_grade () {
  1789. global $USER, $DB, $OUTPUT;
  1790. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1791. if ($newgrade && $newgrade >= 0) {
  1792. $newentry = new stdClass();
  1793. $newentry->id = $this->iassign_submission_current;
  1794. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1795. $newentry->teacher = $USER->id;
  1796. if (!$DB->update_record('iassign_submission', $newentry))
  1797. print_error('error_update', 'iassign');
  1798. else {
  1799. // Trigger module viewed event.
  1800. $event = \mod_iassign\event\submission_updated::create(array(
  1801. 'objectid' => $this->iassign->id,
  1802. 'context' => $this->context
  1803. ));
  1804. $event->add_record_snapshot('course', $this->course);
  1805. $event->trigger();
  1806. }
  1807. } // if ($newgrade >= 0)
  1808. $this->action = 'viewsubmission';
  1809. $this->view_iassign_current();
  1810. }
  1811. /// Add or Edit interactive activities
  1812. // Get here when editing form and and submitted form data
  1813. // @calledby $this->action()
  1814. function add_edit_iassign () {
  1815. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1816. require_once('iassign_form.php');
  1817. $id = $this->cm->id; // All iAssign statement => iassign_statement.iassignid
  1818. $iassignid = $this->iassign->id;
  1819. $param = new stdClass(); // parameters to build data to the form - see bellow "$mform = new mod_iassign_form(...); $mform->set_data($param);
  1820. $param->action = $this->action; // hidden
  1821. $param->id = $id; // hidden
  1822. $param->special_param1 = 0; // 'special_param1 == 1' => script of iGeom
  1823. $COURSE->cm = $id;
  1824. $COURSE->iassignid = $iassignid;
  1825. $COURSE->iassign_file_id = NULL;
  1826. $context = context_module::instance($this->cm->id);
  1827. $contextuser = context_user::instance($USER->id);
  1828. $component = 'mod_iassign';
  1829. $filearea = 'exercise';
  1830. if (!empty($this->iassign_current))
  1831. $COURSE->iassign_id = $this->iassign_current;
  1832. else
  1833. $COURSE->iassign_id = 0;
  1834. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1835. if ($this->action == 'add') {
  1836. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1837. $params_temp = array('iassignid' => $iassignid);
  1838. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1839. $iassign_statement = $DB->get_records_sql($query_str, $params_temp); //
  1840. $total_of_activities = count($iassign_statement);
  1841. $param->iassignid = $iassignid;
  1842. $param->name = "";
  1843. $param->oldname = "";
  1844. $param->type_iassign = 3;
  1845. $param->proposition = "";
  1846. $author = $DB->get_record("user", array("id" => $USER->id));
  1847. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1848. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1849. $param->author = $param->author_name;
  1850. $param->author_modified = $param->author_modified_name;
  1851. $COURSE->iassign_list = array();
  1852. $param->iassign_list = array();
  1853. if ($iassign_statement) {
  1854. foreach ($iassign_statement as $iassign) {
  1855. $iassignid = $iassign->id;
  1856. $param->iassign_list[$iassignid] = 0;
  1857. $COURSE->iassign_list[$iassignid] = new stdClass();
  1858. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1859. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1860. $COURSE->iassign_list[$iassignid]->enable = 1;
  1861. } // foreach ($iassign_statement as $iassign)
  1862. }
  1863. $param->iassign_ilmid = 0;
  1864. $param->file = 0;
  1865. $param->fileold = 0;
  1866. $param->filename = "";
  1867. $param->grade = $iassign_data->grade;
  1868. $param->timemodified = time();
  1869. $param->timecreated = time();
  1870. $param->timeavailable = $iassign_data->timeavailable;
  1871. $param->timedue = $iassign_data->timedue;
  1872. $param->preventlate = $iassign_data->preventlate;
  1873. $param->test = $iassign_data->test;
  1874. $param->special_param1 = 0;
  1875. $param->visible = 1;
  1876. $param->max_experiment = $iassign_data->max_experiment;
  1877. $param->dependency = 0;
  1878. $param->automatic_evaluate = 1;
  1879. $param->show_answer = 1;
  1880. } // if ($this->action == 'add')
  1881. elseif ($this->action == 'edit') {
  1882. $COURSE->iassign_list = array();
  1883. $this_activity = $this->activity->get_activity();
  1884. if ($this_activity != null) { // first enter here: fill form data
  1885. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1886. $param->iassign_id = $iassign_statement_current->id; // oculto
  1887. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1888. $param->name = $iassign_statement_current->name;
  1889. $param->oldname = $iassign_statement_current->name;
  1890. $param->type_iassign = $iassign_statement_current->type_iassign;
  1891. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1892. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1893. $param->author_name = $iassign_statement_current->author_name; // oculto
  1894. $param->author = $iassign_statement_current->author_name;
  1895. $author = $DB->get_record("user", array('id' => $USER->id));
  1896. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1897. $param->author_modified = $param->author_modified_name;
  1898. $dependency = explode(';', $iassign_statement_current->dependency);
  1899. $param->iassign_list = array();
  1900. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '" . $iassignid . "' AND s.id!='" . $iassign_statement_current->id . "' AND s.dependency!=0";
  1901. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1902. $array_dependency = array();
  1903. $subdependency = "";
  1904. $sub_subdependency = "";
  1905. // Dependents on this exercise
  1906. if ($iassign_statement_dependency) {
  1907. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1908. // to whom this exercise depends
  1909. foreach ($inter as $tmp)
  1910. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1911. $list_dependency = $subdependency . $sub_subdependency;
  1912. $array_dependency = explode(";", $list_dependency);
  1913. }
  1914. // Get all activities in the same iAssigment block:
  1915. $str_query = "SELECT id, name FROM {iassign_statement} WHERE iassignid = '" . $iassignid . "' AND id!='" . $iassign_statement_current->id . "' ORDER BY position ASC";
  1916. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1917. $total_of_activities = count($all_others_iassign_statement) + 1;
  1918. $inter = array();
  1919. if ($all_others_iassign_statement) {
  1920. foreach ($all_others_iassign_statement as $iassign)
  1921. if (in_array($iassign->id, $dependency))
  1922. $inter[] = $iassign->id;
  1923. }
  1924. if ($all_others_iassign_statement) {
  1925. foreach ($all_others_iassign_statement as $iassign) {
  1926. $iassignid = $iassign->id;
  1927. $COURSE->iassign_list[$iassignid] = new stdClass();
  1928. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1929. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1930. if (in_array($iassignid, $dependency))
  1931. $param->iassign_list[$iassignid] = 1;
  1932. else
  1933. $param->iassign_list[$iassignid] = 0;
  1934. if (in_array($iassignid, $array_dependency))
  1935. $COURSE->iassign_list[$iassignid]->enable = 0;
  1936. else
  1937. $COURSE->iassign_list[$iassignid]->enable = 1;
  1938. } // foreach ($all_others_iassign_statement as $iassign)
  1939. } // if ($all_others_iassign_statement)
  1940. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid; // define iLM ID to be used to define 'select' on 'iassign_form.php'
  1941. $param->fileold = 0;
  1942. $param->filesid = 0;
  1943. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1944. $param->filename = '';
  1945. $param->grade = $iassign_statement_current->grade;
  1946. $param->timecreated = $iassign_statement_current->timecreated; // hidden
  1947. $param->timeavailable = $iassign_statement_current->timeavailable;
  1948. $param->timedue = $iassign_statement_current->timedue;
  1949. $param->preventlate = $iassign_statement_current->preventlate;
  1950. $param->test = $iassign_statement_current->test;
  1951. $param->special_param1 = $iassign_statement_current->special_param1; // 'special_param1 == 1' => script of iGeom
  1952. $param->position = $iassign_statement_current->position; // hidden
  1953. $param->visible = $iassign_statement_current->visible;
  1954. $param->max_experiment = $iassign_statement_current->max_experiment;
  1955. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1956. $param->show_answer = $iassign_statement_current->show_answer;
  1957. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1958. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->id);
  1959. if ($files) {
  1960. foreach ($files as $file) {
  1961. if ($file->get_filename() != '.') {
  1962. $param->filename = $file->get_filename();
  1963. $param->file = $file->get_id();
  1964. $param->fileold = $file->get_id();
  1965. $COURSE->iassign_file_id = $file->get_id();
  1966. }
  1967. }
  1968. }
  1969. //TODO //MOOC2014 -- inicio
  1970. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1971. //D if ($iassign_ilm_configs) {
  1972. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1973. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1974. //D } //MOOC2014 -- fim
  1975. } // if ($this_activity != null)
  1976. } // elseif ($this->action == 'edit')
  1977. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1978. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1979. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1980. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1981. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1982. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1983. $param->position = $total_of_activities;
  1984. // Create form and associate its data
  1985. // 'mform1' is used in: ./mod/iassign/iassign_form.php, ./mod/iassign/settings_form.php
  1986. // new mod_iassign_form(...) in ./mod/iassign/iassign_form.php extends /lib/formslib.php:
  1987. // /lib/formslib.php: __construct($action=null, $customdata=null, $method='post', $target='', $attributes=null, $editable=true, $ajaxformdata=null)
  1988. if (isset($param->iassign_ilmid)) {
  1989. // array is additional atributes to 'form'
  1990. // '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)"
  1991. $mform = new mod_iassign_form(null, array('special_param1'=>$param->special_param1), 'post', null, array('id'=>'mform1', 'iassign_ilmid'=>$param->iassign_ilmid), true, null);
  1992. }
  1993. else {
  1994. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1')); // ./mod/iassign/iassign_form.php
  1995. }
  1996. $mform->set_data($param); // define data in the form
  1997. if ($mform->is_cancelled()) {
  1998. $this->return_home_course('iassign_cancel');
  1999. exit;
  2000. }
  2001. else { // else if ($mform->is_cancelled())
  2002. $result = $mform->get_data();
  2003. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  2004. if ($result) {
  2005. $result->context = $context;
  2006. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  2007. $result->grade = 0;
  2008. if ($result->type_iassign == 1) {
  2009. $result->automatic_evaluate = 0;
  2010. $result->show_answer = 0;
  2011. }
  2012. elseif ($result->automatic_evaluate == 0)
  2013. $result->show_answer = 0;
  2014. // $_POST['iassign_list']
  2015. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  2016. if ($result->iassign_list) {
  2017. foreach ($result->iassign_list as $key => $value)
  2018. $result->dependency .= $key . ';';
  2019. }
  2020. else
  2021. $result->dependency = 0;
  2022. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  2023. //TODO Then get it directly from the form data $_POST!
  2024. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  2025. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  2026. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  2027. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  2028. if ($this->action == 'add') {
  2029. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  2030. if ($iassign_statement_name) {
  2031. $this->return_home_course('error_iassign_name');
  2032. die();
  2033. }
  2034. // Really insert the new iActivity in table '*_iassign_statement'
  2035. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  2036. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  2037. // Trigger module viewed event.
  2038. $event = \mod_iassign\event\iassign_created::create(array(
  2039. 'objectid' => $iassignid,
  2040. 'context' => $context
  2041. ));
  2042. $event->add_record_snapshot('course', $this->course);
  2043. $event->trigger();
  2044. $this->return_home_course('iassign_add');
  2045. } // if ($this->action == 'add')
  2046. elseif ($this->action == 'edit') {
  2047. $iassignid = $this->activity->update_iassign($result);
  2048. $this->activity->update_calendar($iassignid, $result->oldname);
  2049. // Trigger module viewed event.
  2050. $event = \mod_iassign\event\iassign_updated::create(array(
  2051. 'objectid' => $iassignid,
  2052. 'context' => $context
  2053. ));
  2054. $event->add_record_snapshot('course', $this->course);
  2055. $event->trigger();
  2056. $this->return_home_course('iassign_update');
  2057. } // elseif ($this->action == 'edit')
  2058. die();
  2059. } // if ($result)
  2060. } // else if ($mform->is_cancelled())
  2061. print $OUTPUT->header();
  2062. $mform->display();
  2063. print $OUTPUT->footer();
  2064. die();
  2065. } // function add_edit_iassign()
  2066. /// Search for dependencies
  2067. function search_dependency ($search_iassing_id, $iassign_statement) {
  2068. global $DB, $OUTPUT;
  2069. $dependency = "";
  2070. if ($iassign_statement)
  2071. foreach ($iassign_statement as $iassign) {
  2072. $inter_dependency = explode(';', $iassign->dependency);
  2073. if (in_array($search_iassing_id, $inter_dependency)) {
  2074. $dependency .= $iassign->id . ";";
  2075. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  2076. } // if (in_array($search_iassing_id, $inter_dependency))
  2077. } // foreach ($iassign_statement as $iassign)
  2078. return $dependency;
  2079. }
  2080. /// Search for "sub"dependency
  2081. function search_sub_dependency ($search_iassing_id) {
  2082. global $DB, $OUTPUT;
  2083. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  2084. $dependency = "";
  2085. if ($iassign_statement) {
  2086. $inter_dependency = explode(';', $iassign_statement->dependency);
  2087. foreach ($inter_dependency as $tmp) {
  2088. if ($tmp != 0)
  2089. $dependency .= $tmp . ";";
  2090. $dependency .= $this->search_sub_dependency($tmp);
  2091. } // foreach ($inter_dependency as $tmp)
  2092. } // if ($iassign_statement)
  2093. return $dependency;
  2094. }
  2095. // Warning message
  2096. static function warning_message_iassign ($strcode) {
  2097. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  2098. }
  2099. /// Update grade of iAssign
  2100. // Called always any iAssign activity is created
  2101. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  2102. static function update_grade_iassign ($iassignid) {
  2103. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2104. require_once($CFG->libdir . '/gradelib.php');
  2105. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  2106. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2107. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2108. // Each iAssign item is associated with one item on the "gradebook"
  2109. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  2110. //$sum_grade = 0;
  2111. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2112. //foreach($grade as $tmp) {
  2113. // $sum_grade += $tmp->grade;
  2114. // }
  2115. //1 Solution 1
  2116. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  2117. //1 $sum_grade = 0; //1
  2118. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  2119. //2 Solution 2
  2120. $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
  2121. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  2122. if (key($array_sum_grade))
  2123. $sum_grade = key($array_sum_grade); //2
  2124. else
  2125. $sum_grade = 0; //2
  2126. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  2127. $grades = NULL;
  2128. $params_temp = array('itemname' => $grade_iassign->name);
  2129. $params_temp['iteminstance'] = $iassignid;
  2130. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2131. //2016 if ($sum_grade != 0) {
  2132. $params_temp['grademax'] = $sum_grade;
  2133. $params_temp['rawgrademax'] = $sum_grade;
  2134. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2135. $params_temp['grademin'] = 0;
  2136. // @calls /lib/gradelib.php: call to grade_item->insert()
  2137. //TODO: is there any error here in Moodle version 3.0?
  2138. //TODO: Incorrect property 'grademax' found when inserting grade object
  2139. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  2140. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2141. }
  2142. /// Update grade of student
  2143. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  2144. global $CFG, $DB, $OUTPUT;
  2145. require_once($CFG->libdir . '/gradelib.php');
  2146. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  2147. // Review all the student submission for this iAssign activity
  2148. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  2149. $total_grade = 0;
  2150. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  2151. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  2152. if ($iassign_submission)
  2153. $total_grade += $iassign_submission->grade;
  2154. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  2155. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  2156. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  2157. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  2158. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  2159. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  2160. $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
  2161. if (key($array_sum_grade))
  2162. $sum_grade = key($array_sum_grade); //2
  2163. else
  2164. $sum_grade = 0; //2
  2165. $grades['userid'] = $userid;
  2166. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  2167. $params_temp = array('itemname' => $grade_iassign->name);
  2168. $params_temp['iteminstance'] = $iassignid;
  2169. $params_temp['gradetype'] = GRADE_TYPE_VALUE;
  2170. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  2171. $params_temp['grademax'] = $sum_grade;
  2172. $params_temp['rawgrademax'] = $sum_grade;
  2173. //2016 } else { $params_temp['grademax'] = 0; $params_temp['rawgrademax'] = 0; }
  2174. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params_temp);
  2175. }
  2176. /// Display caption of icons
  2177. function view_legend_icons () {
  2178. global $USER, $CFG, $DB, $OUTPUT;
  2179. $id = $this->cm->id;
  2180. if ($this->action == 'print')
  2181. print '<table border=1 width=100%><tr>';
  2182. else
  2183. print '<table width=100%><tr>';
  2184. print '<td >';
  2185. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  2186. if ($this->action != 'print') {
  2187. $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>";
  2188. $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>";
  2189. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  2190. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  2191. } // if ($this->action != 'print')
  2192. print '</tr></table>' . "\n";
  2193. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  2194. print '</td></tr></table>' . "\n";
  2195. } // function view_legend_icons()
  2196. /// Display activity current
  2197. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  2198. function view_iassign_current () {
  2199. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  2200. $id = $this->cm->id;
  2201. $iassignid = $this->iassign->id;
  2202. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2203. $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
  2204. // 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 ...
  2205. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2206. if (!$iassign_statement_activity_item) {
  2207. print $OUTPUT->header();
  2208. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2209. print $OUTPUT->footer();
  2210. exit;
  2211. }
  2212. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2213. $ilm_name = '';
  2214. if ($ilm->ilm)
  2215. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2216. // 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
  2217. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2218. // log record
  2219. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2220. //Trigger module viewed event.
  2221. $event = \mod_iassign\event\submission_viewed::create(array(
  2222. 'objectid' => $iassign->id,
  2223. 'context' => $this->context,
  2224. 'other' => $info
  2225. ));
  2226. $event->add_record_snapshot('course', $this->course);
  2227. $event->trigger();
  2228. // Search of iLM data used in the current activity
  2229. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2230. // Add actual activity to navbar:
  2231. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2232. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2233. print $OUTPUT->header();
  2234. if ($this->action == 'viewsubmission') {
  2235. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2236. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2237. else
  2238. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2239. } else {
  2240. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2241. }
  2242. if ($iassign_submission)
  2243. $this->update_comment($iassign_submission->id);
  2244. $file = $iassign_statement_activity_item->id;
  2245. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2246. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2247. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2248. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2249. $this->bottonPost = 0; // hide submit button
  2250. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2251. $this->view_iassign = false; // disable visualization of activity
  2252. $repeat = "";
  2253. $last_iassign = "";
  2254. $student_answer = "";
  2255. $comment = "";
  2256. // *** Teacher access (view learner's submission)
  2257. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2258. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2259. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2260. // ---> access teacher for test
  2261. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2262. $this->bottonPost = 1;
  2263. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2264. $this->activity->view_dates();
  2265. $USER->iassignEdit = $this->bottonPost;
  2266. $this->activity->show_info_iassign();
  2267. if ($iassign_submission) {
  2268. //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;
  2269. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2270. } else {
  2271. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2272. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2273. }
  2274. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2275. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2276. // Prepare tags to present the iLM
  2277. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2278. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2279. // *** (end) Teacher access (view the activity)
  2280. // *** Teacher access (view learner's submission to the activity)
  2281. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2282. // It is teacher or 'nonediting teacher' that can evaluate
  2283. // ----> area teacher evaluate
  2284. $row = optional_param('row', 0, PARAM_INT);
  2285. $column = optional_param('column', 0, PARAM_INT);
  2286. $link_next = iassign_icons::insert('right_disable');
  2287. $link_previous = iassign_icons::insert('left_disable');
  2288. $link_up = iassign_icons::insert('up_disable');
  2289. $link_down = iassign_icons::insert('down_disable');
  2290. // next_activity
  2291. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2292. $url_next = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column + 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_next . "&view_iassign=report&row=" . ($row) . "&column=" . ($column + 1);
  2293. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2294. }
  2295. // previous_activity
  2296. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2297. $url_previous = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row][$column - 1]->iassign_submission_current . "&userid_iassign=$this->userid_iassign&iassign_current=" . $USER->matrix_iassign[$row][$column]->iassign_previous . "&view_iassign=report&row=" . ($row) . "&column=" . ($column - 1);
  2298. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2299. }
  2300. // previous_student
  2301. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2302. $url_down = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row + 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_next . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row + 1) . "&column=" . ($column);
  2303. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2304. }
  2305. // next_student
  2306. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2307. $url_up = "view.php?action=viewsubmission&id=$id&iassign_submission_current=" . $USER->matrix_iassign[$row - 1][$column]->iassign_submission_current . "&userid_iassign=" . $USER->matrix_iassign[$row][$column]->user_previous . "&iassign_current=" . $this->activity->get_activity()->id . "&view_iassign=report&row=" . ($row - 1) . "&column=" . ($column);
  2308. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2309. }
  2310. if ($iassign_submission) {
  2311. $student_answer = $iassign_submission->answer;
  2312. }
  2313. $last_iassign = get_string('last_iassign', 'iassign');
  2314. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2315. // Messages related to due date (and user role)
  2316. $this->activity->view_dates();
  2317. print $OUTPUT->box_start();
  2318. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2319. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2320. print $OUTPUT->user_picture($user_data);
  2321. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2322. print '</td>' . "\n";
  2323. print '<td width=20% align=right>' . "\n";
  2324. print '<table width=50 cellpadding="0">';
  2325. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2326. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2327. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2328. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2329. print '</table>' . "\n";
  2330. print '</td></tr></table>' . "\n";
  2331. print $OUTPUT->box_end();
  2332. print $OUTPUT->box_start();
  2333. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2334. print '<td width=60% valign="top">' . "\n";
  2335. print '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>' . "\n";
  2336. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2337. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2338. $resp = get_string('yes');
  2339. else
  2340. $resp = get_string('no');
  2341. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2342. if ($iassign_statement_activity_item->show_answer == 1)
  2343. $resp = get_string('yes');
  2344. else
  2345. $resp = get_string('no');
  2346. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2347. print '</td>';
  2348. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2349. print '<td width=40% valign="top" align="left">';
  2350. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2351. // check status of solution sent by the student
  2352. if ($iassign_submission) {
  2353. switch ($iassign_submission->status) {
  2354. case 3 :
  2355. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2356. break;
  2357. case 2 :
  2358. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2359. break;
  2360. case 1 :
  2361. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2362. break;
  2363. default :
  2364. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2365. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2366. } // switch ($iassign_submission->status)
  2367. }
  2368. else { // if ($iassign_submission)
  2369. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2370. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2371. }
  2372. // update_status
  2373. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2374. $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);
  2375. print " <script type='text/javascript'>
  2376. //<![CDATA[
  2377. function overwriteStatus (newstatus) {
  2378. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2379. document.formEditStatus.return_status.value=newstatus;
  2380. document.formEditStatus.submit();
  2381. }
  2382. else
  2383. document.formEditStatus.return_status.value=-1;
  2384. }
  2385. //]]>
  2386. </script>";
  2387. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2388. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2389. 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";
  2390. print " <input type='hidden' name='return_status'>\n";
  2391. print "</form>\n";
  2392. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2393. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2394. $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);
  2395. print "
  2396. <script type='text/javascript'>
  2397. //<![CDATA[
  2398. function overwriteGrade (newgrade,maxgrade) {
  2399. if (newgrade<0 || newgrade>maxgrade) {
  2400. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2401. document.formEditGrade.return_grade.value=-1;
  2402. document.formEditGrade.submit();
  2403. }
  2404. else {
  2405. document.formEditGrade.return_grade.value=newgrade;
  2406. document.formEditGrade.submit();
  2407. }
  2408. }
  2409. //]]>
  2410. </script>";
  2411. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2412. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2413. print " <input type='text' name='grade' size='6'>";
  2414. print " <input type='hidden' name='return_grade'> ";
  2415. 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";
  2416. print "</form>";
  2417. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2418. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2419. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2420. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2421. if ($teacher)
  2422. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2423. } // if ($iassign_submission->experiment > 0)
  2424. print '</td>';
  2425. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2426. print '</tr></table>';
  2427. print $OUTPUT->box_end();
  2428. $USER->iassignEdit = $this->bottonPost;
  2429. print activity::toggle_columns_script();
  2430. if ($iassign_submission && $allow_resubmission) {
  2431. // Put the iLM to
  2432. print $OUTPUT->box_start();
  2433. print '<p><strong>' . $last_iassign . '</strong></p>';
  2434. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2435. $enderecoPOST = "";
  2436. // Prepare tags to present the iLM
  2437. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2438. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2439. print $OUTPUT->box_end();
  2440. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2441. // ATTENTION: exception used by iGeom (exercise with "script")
  2442. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2443. if (substr($ilm_name, 0, 5)=="igeom") {
  2444. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2445. $loadTeacherActivity = true;
  2446. }
  2447. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2448. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2449. print activity::toggle_columns_script();
  2450. // Prepare tags to present the iLM
  2451. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2452. }
  2453. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2454. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2455. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2456. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2457. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2458. // *** (end) Teacher access (view learner's submission to the activity)
  2459. // *** Student access (view the activity)
  2460. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2461. // It could be the learner (he could send or resend the activity)
  2462. // ---> access student
  2463. $time_now = time();
  2464. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2465. // activity of type example - not submit button for submission
  2466. $this->view_iassign = true;
  2467. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2468. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2469. // activity of type test - iLM automatic evaluator - submit button for submission
  2470. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2471. $this->bottonPost = 1;
  2472. $this->view_iassign = true;
  2473. } else
  2474. $this->view_iassign = false;
  2475. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2476. // activity of type exercise (learner can send his answer, if yet open...)
  2477. $this->view_iassign = true;
  2478. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2479. $this->view_iassign = false;
  2480. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2481. $this->bottonPost = 1; // allow the submit button
  2482. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2483. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2484. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2485. if (!$iassign_submission) {
  2486. $str_iassign_submission_id = '';
  2487. $str_iassign_submission_answer = '';
  2488. }
  2489. else {
  2490. $str_iassign_submission_id = $iassign_submission->id;
  2491. $str_iassign_submission_answer = $iassign_submission->answer;
  2492. }
  2493. if ($this->action != 'repeat') {
  2494. $repeat = "<a href='view.php?action=repeat&id="
  2495. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2496. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2497. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2498. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2499. }
  2500. $this->bottonPost = 1;
  2501. $this->write_solution = 1; // can register his submission
  2502. $student_answer = $str_iassign_submission_answer;
  2503. }
  2504. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2505. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2506. $last_iassign = get_string('last_iassign', 'iassign');
  2507. if ($iassign_submission) {
  2508. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2509. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2510. $student_answer = $iassign_submission->answer;
  2511. } else {
  2512. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2513. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2514. }
  2515. }
  2516. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2517. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2518. $this->bottonPost = 1;
  2519. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2520. } else {
  2521. $last_iassign = get_string('last_iassign', 'iassign');
  2522. if ($iassign_submission) {
  2523. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2524. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2525. $student_answer = $iassign_submission->answer;
  2526. } else {
  2527. // Symbol of "redo activity"
  2528. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2529. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2530. }
  2531. }
  2532. } // elseif ($iassign_statement_activity_item->test == 1)
  2533. elseif ($iassign_statement_activity_item->test == 0)
  2534. $this->view_iassign = false;
  2535. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2536. if ($iassign_submission)
  2537. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2538. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2539. else
  2540. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2541. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2542. $this->activity->view_dates();
  2543. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2544. print $OUTPUT->box_start();
  2545. print '<table width=100% border=0 valign="top">' . "\n";
  2546. print '<tr><td width=60% valign="top">' . "\n";
  2547. $flag_dependency = true;
  2548. if ($iassign_statement_activity_item->type_iassign == 3) {
  2549. if ($iassign_statement_activity_item->dependency == 0) {
  2550. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2551. } else {
  2552. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2553. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2554. foreach ($dependencys as $dependency) {
  2555. if ($dependency) {
  2556. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2557. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2558. if ($dependencysubmissions) {
  2559. if ($dependencysubmissions->status == 3)
  2560. $icon = iassign_icons::insert('correct');
  2561. elseif ($dependencysubmissions->status == 2) {
  2562. $icon = iassign_icons::insert('incorrect');
  2563. $flag_dependency = false;
  2564. } elseif ($dependencysubmissions->status == 1) {
  2565. $icon = iassign_icons::insert('post');
  2566. $flag_dependency = false;
  2567. } elseif ($dependencysubmissions->status == 0) {
  2568. $icon = iassign_icons::insert('not_post');
  2569. $flag_dependency = false;
  2570. }
  2571. } else {
  2572. $icon = iassign_icons::insert('not_post');
  2573. $flag_dependency = false;
  2574. } // if ($dependencysubmissions)
  2575. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2576. } // if ($dependency)
  2577. } // foreach ($dependencys as $dependency)
  2578. } // if ($iassign_statement_activity_item->dependency == 0)
  2579. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2580. if ($flag_dependency == false) {
  2581. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2582. $this->view_iassign = false;
  2583. print '</tr></table>' . "\n";
  2584. }
  2585. else {
  2586. $this->view_iassign = true;
  2587. print '</td>' . "\n";
  2588. } // if ($flag_dependency == false)
  2589. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2590. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2591. // receiver=1 - message to teacher
  2592. // receiver=2 - message to student
  2593. if ($iassign_submission) {
  2594. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2595. if ($verify_message)
  2596. $comment = iassign_icons::insert('comment_unread');
  2597. }
  2598. print '<td width=40% valign="top" align="left">';
  2599. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2600. if ($iassign_statement_activity_item->show_answer == 1) {
  2601. // check status of solution sent by the student
  2602. if ($iassign_submission) {
  2603. switch ($iassign_submission->status) {
  2604. case 3 :
  2605. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2606. break;
  2607. case 2 :
  2608. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2609. break;
  2610. case 1 :
  2611. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2612. break;
  2613. default :
  2614. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2615. $repeat = "";
  2616. $last_iassign = "";
  2617. } // switch ($iassign_submission->status)
  2618. } else {
  2619. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2620. $repeat = "";
  2621. $last_iassign = "";
  2622. }
  2623. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2624. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2625. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2626. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2627. if ($iassign_statement_activity_item->max_experiment == 0)
  2628. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2629. else {
  2630. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2631. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2632. $repeat = "";
  2633. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2634. $this->bottonPost = 0;
  2635. $this->write_solution = 0;
  2636. }
  2637. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2638. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2639. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2640. if ($teacher)
  2641. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2642. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2643. } // if ($iassign_statement_activity_item->show_answer==1)
  2644. else {
  2645. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2646. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2647. $repeat = "";
  2648. $last_iassign = "";
  2649. } elseif ($iassign_submission->status == 1) {
  2650. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2651. }
  2652. }
  2653. print '</td>';
  2654. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2655. print '</tr></table>' . "\n";
  2656. // Presents the iLM
  2657. print '<table width=100% border=0 valign="top">' . "\n";
  2658. print '<td width=80% align="left">';
  2659. 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\".
  2660. print '<td width=20% align="rigth">';
  2661. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2662. print $repeat; // symbol of "redo activity"
  2663. print '</td></tr></table>' . "\n";
  2664. //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)'
  2665. print activity::toggle_columns_script();
  2666. print '<p class="mt-5"><strong>' . get_string('proposition', 'iassign') . '</strong></p>' . "\n";
  2667. print '<div class="proposition">' . $iassign_statement_activity_item->proposition . '</div>' . "\n";
  2668. $output = '';
  2669. if (!$iassign_ilm) {
  2670. $iassign_ilm = new stdClass();
  2671. $iassign_ilm->file_jar = "";
  2672. }
  2673. $output .= $OUTPUT->box_start();
  2674. $USER->iassignEdit = $this->bottonPost;
  2675. // ---
  2676. // Presents the iLM
  2677. // Prepare tags to present the iLM
  2678. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2679. $student_answer = ""; //?
  2680. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2681. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2682. $student_answer = "";
  2683. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2684. } else {
  2685. // When student is redoing his activity
  2686. // ATTENTION: exception used by iGeom (exercise with "script")
  2687. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2688. if (substr($ilm_name, 0, 5)=="igeom") {
  2689. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2690. $loadTeacherActivity = true;
  2691. }
  2692. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2693. }
  2694. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2695. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2696. //1 $history_comment = '';
  2697. //1 if ($iassign_submission) {
  2698. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2699. //1 }
  2700. //1 if (!empty($history_comment)) {
  2701. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2702. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2703. //1 $output .= $history_comment;
  2704. //1 $output .= "</table>\n";
  2705. //1 }
  2706. //1 $output .= "</form></center>\n";
  2707. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2708. //1 }
  2709. $output .= $OUTPUT->box_end();
  2710. print $output;
  2711. } // if ($this->view_iassign)
  2712. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2713. } // if ($this->view_iassign)
  2714. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2715. else
  2716. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2717. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2718. print '<table width=100% border=0 valign="top">' . "\n";
  2719. print '<tr><td width=60% valign="top">' . "\n";
  2720. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2721. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2722. print '</tr></table>' . "\n";
  2723. $student_answer = "";
  2724. $enderecoPOST = "";
  2725. // Prepare tags to present the iLM
  2726. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2727. print $output;
  2728. }
  2729. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2730. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2731. 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
  2732. // Put a block with area to sent/answer comments
  2733. $output = '';
  2734. $history_comment = '';
  2735. $row = optional_param('row', 0, PARAM_INT);
  2736. $column = optional_param('column', 0, PARAM_INT);
  2737. if ($iassign_submission) {
  2738. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2739. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2740. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2741. }
  2742. else {
  2743. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2744. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2745. }
  2746. $output .= $OUTPUT->box_start();
  2747. //if (!empty($history_comment)) {
  2748. $output .= "<a id='comments'></a>";
  2749. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2750. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2751. $output .= "</table>";
  2752. print " <script type='text/javascript'>
  2753. //<![CDATA[
  2754. function submit_comment(url) {
  2755. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2756. var formData = new FormData();
  2757. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2758. var request = new XMLHttpRequest();
  2759. request.open('POST', url);
  2760. document.getElementById('comments_history').innerHTML = '';
  2761. request.onload = function (e) {
  2762. if (request.readyState === 4) {
  2763. if (request.status === 200) {
  2764. document.getElementById('comments_history').innerHTML = request.responseText;
  2765. document.getElementById('check-message-success').style.visibility = 'visible';
  2766. setTimeout(function(){
  2767. document.getElementById('check-message-success').style.visibility = 'hidden';
  2768. }, 3000);
  2769. }
  2770. }
  2771. };
  2772. document.formEnvioComment.submission_comment.value = '';
  2773. request.send(formData);
  2774. }
  2775. function event_text_area (event) {
  2776. if (event.ctrlKey && event.keyCode == 13)
  2777. submit_comment('$enderecoPOSTcomment');
  2778. }
  2779. //]]>
  2780. </script>";
  2781. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2782. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment' onkeypress='event_text_area(event)'></textarea></p>\n";
  2783. $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";
  2784. $output .= "</form> </center>\n";
  2785. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2786. // }
  2787. $output .= $OUTPUT->box_end();
  2788. print $output;
  2789. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2790. // final block 'studant'
  2791. print $OUTPUT->footer();
  2792. die();
  2793. } // function view_iassign_current()
  2794. /// Export the data from performance report into CSV file format
  2795. function export_csv () {
  2796. global $USER, $CFG, $DB, $OUTPUT;
  2797. $str = "";
  2798. $fields = "student_id, student_name";
  2799. // Finding all iassign activities for the iassign:
  2800. $id = $this->cm->id;
  2801. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2802. $c = 1;
  2803. foreach ($iassign_list as $iassign) {
  2804. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2805. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2806. $c ++;
  2807. }
  2808. // Finding enrolled students:
  2809. $params_temp = array('shortname' => 'student');
  2810. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params_temp);
  2811. $context = context_course::instance($this->course->id);
  2812. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2813. $students = $DB->get_records_sql(
  2814. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2815. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2816. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2817. foreach ($students as $student) {
  2818. $str .= $student->userid . ',';
  2819. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2820. foreach ($iassign_list as $iassign) {
  2821. $str .= ',' . $iassign->id . ',';
  2822. $str .= '"' . $iassign->name . '",';
  2823. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2824. if ($student_submissions) {
  2825. $str .= $student_submissions->experiment . ',';
  2826. $str .= $student_submissions->grade . ',';
  2827. switch ($student_submissions->status) {
  2828. case 3:
  2829. $str .= '"correct",';
  2830. break;
  2831. case 2:
  2832. $str .= '"incorrect",';
  2833. break;
  2834. case 1:
  2835. $str .= '"post",';
  2836. break;
  2837. case 0:
  2838. $str .= '"not_post",';
  2839. break;
  2840. }
  2841. }
  2842. else {
  2843. $str .= ',,"not_post",';
  2844. }
  2845. $str .= $iassign->iassign_ilmid . ',';
  2846. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2847. $str .= '"' . $ilm_activity->name . '"';
  2848. }
  2849. $str .= "\n";
  2850. }
  2851. $str = $fields . "\n" . $str;
  2852. header("Content-type: text/csv");
  2853. header("Content-disposition: attachment; filename=report.csv");
  2854. header("Pragma: no-cache");
  2855. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2856. header('Content-Length: ' . strlen($str));
  2857. header('Connection: close');
  2858. print $str;
  2859. flush();
  2860. } // function export_csv()
  2861. /// Display report of performance
  2862. function report () {
  2863. global $USER, $CFG, $DB, $OUTPUT;
  2864. $id = $this->cm->id;
  2865. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2866. if ($this->action != 'print') {
  2867. $title = get_string('report', 'iassign');
  2868. print $OUTPUT->header();
  2869. } // if ($this->action != 'print')
  2870. $this->print_main_menu();
  2871. print $OUTPUT->box_start();
  2872. $this->view_legend_icons();
  2873. print $OUTPUT->box_end();
  2874. if ($this->action == 'print')
  2875. print '<table border=1 width="100%">' . "\n";
  2876. else
  2877. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped mt-5" width="100%">' . "\n";
  2878. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2879. // $num = array();
  2880. $i = 1;
  2881. $num = array();
  2882. $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;";
  2883. foreach ($iassign_list as $iassign) { // for all exercise in this block
  2884. $test_exercise = "";
  2885. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2886. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2887. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2888. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2889. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2890. $num[$i] = new stdClass();
  2891. $num[$i]->name = $iassign->name;
  2892. $num[$i]->id = $i;
  2893. $num[$i]->iassignid = $iassign->id;
  2894. print ' <tr >' . "\n";
  2895. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2896. print "<td class=\"cell c0 actvity\">";
  2897. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2898. print ' </tr>' . "\n";
  2899. $i++;
  2900. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2901. } // foreach ($iassign_list as $iassign)
  2902. $num_exerc = $i; // total of exercises
  2903. print "</table>";
  2904. print "<p></p>";
  2905. if ($this->action == 'print')
  2906. print '<table border=1 width="100%">' . "\n";
  2907. else // ./theme/boost/style/moodle.css: .generaltable
  2908. print '<table id="outlinetable" class="generaltable boxaligncenter table table-hover table-striped table-bordered" cellpadding="5" width="100%">' . "\n";
  2909. $context = context_course::instance($this->course->id);
  2910. if ($num_exerc > 1) {
  2911. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2912. $params_temp = array('shortname' => 'student');
  2913. $role = $DB->get_record_sql(
  2914. "SELECT s.id, s.shortname FROM {role} s " .
  2915. " WHERE s.shortname = :shortname", $params_temp);
  2916. // $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");
  2917. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  2918. $students = $DB->get_records_sql(
  2919. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2920. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2921. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  2922. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2923. $width = 90/$num_exerc;
  2924. for ($j=1; $j<$num_exerc; $j++) { // all exercises on this block
  2925. $sum_iassign_correct[$j] = 0;
  2926. print '<th class="header c1" scope="col" style="width:'.$width.'%; text-align: center;">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2927. }
  2928. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2929. $sum_iassign = $j - 1;
  2930. print '</tr>' . "\n";
  2931. $total = 0;
  2932. $sum_student = 0;
  2933. $comment = iassign_icons::insert('comment_read');
  2934. $sum_comment = 0;
  2935. $sum_correct_iassign = array();
  2936. $sum_correct_student = array();
  2937. $USER->matrix_iassign = array();
  2938. if ($students) {
  2939. $w = 0;
  2940. foreach ($students as $tmp) { // count students
  2941. $users_array[$w] = $tmp;
  2942. $w++;
  2943. }
  2944. for ($x=0; $x<$w; $x++) { // for all students
  2945. print '<tr>' . "\n";
  2946. $sum_student ++;
  2947. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2948. print ' <td style="vertical-align: middle;">' . $name . '</td>' . "\n";
  2949. $total_student = 0;
  2950. $tentativas = 0;
  2951. for ($j=1; $j<$num_exerc; $j++) { // for all exercise
  2952. $sum_comment = $sum_verify_message = 0;
  2953. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2954. if ($student_submissions) {
  2955. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2956. $tentativas = $student_submissions->experiment;
  2957. // Get student comments
  2958. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2959. $params_temp = array('iassign_submissionid' => $student_submissions->id);
  2960. $student_submissions_comment = $DB->get_record_sql(
  2961. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2962. "WHERE iassign_submissionid = :iassign_submissionid", $params_temp);
  2963. if ($student_submissions_comment) // student has comment
  2964. foreach ($student_submissions_comment as $tmp)
  2965. $sum_comment = $tmp;
  2966. // informations to previous activities
  2967. if ($j - 1 < 1 || $j == $num_exerc) $iassign_previous = "-1";
  2968. else $iassign_previous = $num[$j - 1]->iassignid;
  2969. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  2970. else $user_previous = $users_array[$x - 1]->userid;
  2971. // next
  2972. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  2973. else $iassign_next = "-1";
  2974. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  2975. else $user_next = "-1";
  2976. $position = "&row= $x&column=$j";
  2977. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2978. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2979. $url .= $position;
  2980. // receiver=1 - message to teacher
  2981. // receiver=2 - message to student
  2982. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2983. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2984. $params_temp = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2985. $verify_message = $DB->get_record_sql(
  2986. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2987. "WHERE iassign_submissionid = :iassign_submissionid " .
  2988. " AND return_status= :return_status " .
  2989. " AND receiver= :receiver", $params_temp);
  2990. if ($verify_message)
  2991. foreach ($verify_message as $tmp)
  2992. $sum_verify_message = $tmp;
  2993. if ($sum_verify_message > 0)
  2994. $comment = '<i class="fa fa-comments" style="color: #658af7; font-size: 1.4rem;" aria-hidden="true"></i>';
  2995. else
  2996. $comment = '<i class="fa fa-comments" style="color: gray; font-size: 1.3rem;" aria-hidden="true"></i>';
  2997. if ($student_submissions->status == 3) {
  2998. $sum_iassign_correct[$j] ++;
  2999. $total_student ++;
  3000. $feedback = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true"></i>';
  3001. }
  3002. elseif ($student_submissions->status == 2) {
  3003. $feedback = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true"></i>';
  3004. }
  3005. elseif ($student_submissions->status == 1) {
  3006. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3007. }
  3008. elseif ($student_submissions->status == 0) {
  3009. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3010. }
  3011. if ($this->action != 'print') {
  3012. if ($tentativas > 0)
  3013. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3014. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3015. . $feedback
  3016. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3017. . $tentativas
  3018. . '</span> </button>'
  3019. . '</a>' . "\n";
  3020. else
  3021. print '<td style="text-align: center;"> <a href="' . $url . '" ' . $last_solution_submission . '>'
  3022. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3023. . $feedback
  3024. .'</button>'
  3025. . '</a>' . "\n";
  3026. if ($sum_comment > 0 && $sum_verify_message > 0)
  3027. print '<a href="' . $url . '"> '
  3028. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3029. . $comment
  3030. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3031. . $sum_verify_message . '/' . $sum_comment
  3032. . '</span> </button>'
  3033. . '</a>';
  3034. else if ($sum_comment > 0)
  3035. print '<a href="' . $url . '"> '
  3036. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'"> '
  3037. . $comment
  3038. .'<span class="badge badge-light" style="font-size: 1rem; margin-left: .5rem;">'
  3039. . $sum_comment
  3040. . '</span> </button>'
  3041. . '</a>';
  3042. print '</td>' . "\n";
  3043. }
  3044. if ($this->action == 'print')
  3045. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3046. } // if ($student_submissions)
  3047. else { // if ($student_submissions)
  3048. // Student does not have any submission
  3049. // informations to browse previous activities
  3050. if ($j - 1 < 1 || $j == $i) $iassign_previous = "-1";
  3051. else $iassign_previous = $num[$j - 1]->iassignid;
  3052. if ($x - 1 < 0 || $x == $w) $user_previous = "-1";
  3053. else $user_previous = $users_array[$x - 1]->userid;
  3054. // next
  3055. if ($i - 1 > $j) $iassign_next = $num[$j + 1]->iassignid;
  3056. else $iassign_next = "-1";
  3057. if ($w - 1 > $x) $user_next = $users_array[$x + 1]->userid;
  3058. else $user_next = "-1";
  3059. $position = "&row= $x&column=$j";
  3060. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  3061. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  3062. $url .= $position;
  3063. $feedback = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true"></i>';
  3064. if ($this->action == 'print')
  3065. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  3066. else {
  3067. print '<td style="text-align: center;"> <a href="' . $url . '">'
  3068. . '<button type="button" class="btn btn-secondary" style="'.$stylebutton.'">'
  3069. . $feedback
  3070. .'</button>'
  3071. . '</a>' . "\n";
  3072. // print '<td> &nbsp;</td>';
  3073. if ($sum_comment > 0)
  3074. print '<a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') ' . "\n";
  3075. // else print '<td> &nbsp;</td>';
  3076. print '</td>';
  3077. }
  3078. } // else if ($student_submissions)
  3079. $USER->matrix_iassign[$x][$j] = new stdClass();
  3080. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  3081. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  3082. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  3083. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  3084. if ($student_submissions)
  3085. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  3086. else
  3087. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  3088. //print '</td>' . "\n";
  3089. } // for ($j=1; $j<$num_exerc; $j++)
  3090. $total = $total + $total_student;
  3091. $porcentagem = ($total_student / ($j - 1)) * 100;
  3092. if ($tentativas != 0 && $tentativas != null) {
  3093. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  3094. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  3095. }
  3096. else {
  3097. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  3098. }
  3099. print '</tr>' . "\n";
  3100. $sum_correct_student[$sum_student] = new stdClass();
  3101. $sum_correct_student[$sum_student]->name = $name;
  3102. $sum_correct_student[$sum_student]->sum = $total_student;
  3103. } // for ($x = 0; $x < $w; $x ++)
  3104. for ($i = 1; $i < $j; $i ++) {
  3105. if (is_null($sum_iassign_correct[$i]))
  3106. $sum_iassign_correct[$i] = 0;
  3107. $sum_correct_iassign[$i] = new stdClass();
  3108. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3109. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3110. }
  3111. // print '</tr></table>' . "\n";
  3112. }
  3113. } // if ($i>1)
  3114. else {
  3115. print_string('no_activity', 'iassign');
  3116. }
  3117. print "</table>\n";
  3118. print '<p class="mt-5">' . get_string('ps_experiment', 'iassign') . '</p>';
  3119. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  3120. if ($this->action != 'print')
  3121. print $OUTPUT->footer();
  3122. die();
  3123. } // function report()
  3124. /// Display graphics of performance
  3125. function stats () {
  3126. global $USER, $CFG, $DB, $OUTPUT;
  3127. $id = $this->cm->id;
  3128. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  3129. if ($this->action != 'printstats')
  3130. $title = get_string('graphic', 'iassign');
  3131. $num = array();
  3132. $sum_correct_iassign = array();
  3133. $sum_correct_student = array();
  3134. $sum_student = 0;
  3135. $i = 1;
  3136. foreach ($iassign_list as $iassign) {
  3137. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  3138. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  3139. $sum_iassign_correct[$i] = 0;
  3140. $num[$i] = new stdClass();
  3141. $num[$i]->name = $iassign->name;
  3142. $num[$i]->id = $i;
  3143. $num[$i]->iassignid = $iassign->id;
  3144. $i ++;
  3145. } // if ($iassign->type_iassign == 3)
  3146. } // foreach ($iassign_list as $iassign)
  3147. $sum_iassign = $i - 1;
  3148. $context = context_course::instance($this->course->id);
  3149. if ($i > 1) {
  3150. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  3151. $params_temp = array('shortname' => 'student');
  3152. $role = $DB->get_record_sql(
  3153. "SELECT s.id, s.shortname FROM {role} s " .
  3154. " WHERE s.shortname = :shortname", $params_temp);
  3155. // $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");
  3156. $params_temp = array('contextid' => $context->id, 'roleid' => $role->id);
  3157. $students = $DB->get_records_sql(
  3158. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  3159. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  3160. " ORDER BY a.firstname ASC,a.lastname ASC", $params_temp);
  3161. $total = 0;
  3162. $sum_student = 0;
  3163. $j = 0;
  3164. $sum_correct_iassign = array();
  3165. $sum_correct_student = array();
  3166. $sum_experiment = array();
  3167. if ($students) {
  3168. foreach ($students as $users) {
  3169. $sum_student ++;
  3170. $name = $users->firstname . '&nbsp;' . $users->lastname;
  3171. // rows
  3172. $total_student = 0;
  3173. for ($j = 1; $j < $i; $j ++) {
  3174. $total_experiment = 0;
  3175. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  3176. if ($student_submissions) {
  3177. if ($student_submissions->status == 3) {
  3178. $sum_iassign_correct[$j] ++;
  3179. $total_student ++;
  3180. } // if ($student_submissions->status == 3)
  3181. $total_experiment += $student_submissions->experiment;
  3182. }
  3183. $sum_experiment[$j] = $total_experiment;
  3184. } // for ($j=1; $j<$i; $j++)
  3185. $total = $total + $total_student;
  3186. $sum_correct_student[$sum_student] = new stdClass();
  3187. $sum_correct_student[$sum_student]->name = $name;
  3188. $sum_correct_student[$sum_student]->sum = $total_student;
  3189. } // foreach ($students as $users)
  3190. }
  3191. for ($i = 1; $i < $j; $i ++) {
  3192. if (is_null($sum_iassign_correct[$i]))
  3193. $sum_iassign_correct[$i] = 0;
  3194. $sum_correct_iassign[$i] = new stdClass();
  3195. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  3196. $sum_correct_iassign[$i]->name = $num[$i]->name;
  3197. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  3198. } // for ($i = 1; $i < $j; $i++)
  3199. } // if ($i > 1)
  3200. print $OUTPUT->header();
  3201. $this->print_main_menu();
  3202. if ($this->action != 'printstats') {
  3203. $title = get_string('graphic', 'iassign');
  3204. $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>";
  3205. $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>";
  3206. print '<table width=100%><tr>';
  3207. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  3208. print '<td width=15% align="right">' . $link_report . '</td>';
  3209. print '</td></tr></table>' . "\n";
  3210. print "<br><br>";
  3211. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3212. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  3213. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3214. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3215. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  3216. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  3217. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  3218. print '</tr>' . "\n";
  3219. $sum_correct = 0;
  3220. if ($sum_correct_iassign) {
  3221. foreach ($sum_correct_iassign as $iassign) {
  3222. if (is_null($iassign->experiment))
  3223. $iassign->experiment = 0;
  3224. $bar = "";
  3225. $sum = $iassign->sum;
  3226. $percent = ($sum / $sum_student) * 100;
  3227. $text = number_format($percent, 1) . '%';
  3228. $sum_correct += $sum;
  3229. if ($sum > 0) {
  3230. for ($i = 1; $i < $percent * 2; $i ++)
  3231. $bar .= iassign_icons::insert('hbar_blue');
  3232. $bar .= iassign_icons::insert('hbar_blue_r');
  3233. } // if ($sum > 0)
  3234. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3235. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3236. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3237. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3238. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3239. print '</tr>' . "\n";
  3240. } // foreach ($sum_correct_iassign as $iassign)
  3241. }
  3242. print "</table>";
  3243. print "<br><br>";
  3244. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3245. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3246. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3247. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3248. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3249. print '</tr>' . "\n";
  3250. $sum_correct = 0;
  3251. foreach ($sum_correct_student as $student) {
  3252. $bar = "";
  3253. $sum = $student->sum;
  3254. $percent = ($sum / $sum_iassign) * 100;
  3255. $text = number_format($percent, 1) . '%';
  3256. $sum_correct += $sum;
  3257. if ($sum > 0) {
  3258. for ($i = 1; $i < $percent * 2; $i ++)
  3259. $bar .= iassign_icons::insert('hbar_blue');
  3260. $bar .= iassign_icons::insert('hbar_blue_r');
  3261. } // if ($sum > 0)
  3262. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3263. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3264. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3265. print '</tr>' . "\n";
  3266. } // foreach ($sum_correct_student as $student)
  3267. print "</table>\n";
  3268. print "<br><br>\n";
  3269. $var = 0;
  3270. $cv = 0;
  3271. $dv = 0;
  3272. $avg = 0;
  3273. if ($sum_correct_student) {
  3274. $avg = $sum_correct / $sum_student;
  3275. if ($avg > 0) {
  3276. foreach ($sum_correct_student as $student)
  3277. $var += pow($student->sum - $avg, 2);
  3278. $var = $var / $sum_student;
  3279. $dv = sqrt($var);
  3280. $cv = ($dv / $avg) * 100;
  3281. }
  3282. }
  3283. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3284. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3285. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3286. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3287. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3288. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3289. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3290. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3291. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3292. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3293. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3294. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3295. print "</table>\n";
  3296. print $OUTPUT->footer();
  3297. } else {
  3298. print "<STYLE TYPE='text/css'>
  3299. <!--
  3300. .boldtable {
  3301. font-family:sans-serif;
  3302. font-size:10pt;
  3303. }
  3304. -->
  3305. </STYLE>\n";
  3306. print '<table border=1 width=100%>' . "\n";
  3307. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3308. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3309. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3310. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3311. print '</tr>' . "\n";
  3312. $sum_correct = 0;
  3313. foreach ($sum_correct_iassign as $iassign) {
  3314. $bar = "";
  3315. $sum = $iassign->sum;
  3316. $percent = ($sum / $sum_student) * 100;
  3317. $text = number_format($percent, 1) . '%';
  3318. $sum_correct += $sum;
  3319. if ($sum > 0) {
  3320. for ($i = 1; $i < $percent * 2; $i ++)
  3321. $bar .= iassign_icons::insert('hbar_blue');
  3322. $bar .= iassign_icons::insert('hbar_blue_r');
  3323. } // if ($sum > 0)
  3324. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3325. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3326. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3327. print '</tr>' . "\n";
  3328. } // foreach ($sum_correct_iassign as $iassign)
  3329. print "</table>";
  3330. print "<br><br>";
  3331. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3332. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3333. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3334. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3335. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3336. print '</tr>' . "\n";
  3337. $sum_correct = 0;
  3338. foreach ($sum_correct_student as $student) {
  3339. $bar = "";
  3340. $sum = $student->sum;
  3341. $percent = ($sum / $sum_iassign) * 100;
  3342. $text = number_format($percent, 1) . '%';
  3343. $sum_correct += $sum;
  3344. if ($sum > 0) {
  3345. for ($i = 1; $i < $percent * 2; $i ++)
  3346. $bar .= iassign_icons::insert('hbar_blue');
  3347. $bar .= iassign_icons::insert('hbar_blue_r');
  3348. } // if ($sum > 0)
  3349. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3350. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3351. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3352. print '</tr>' . "\n";
  3353. } // foreach ($sum_correct_student as $student)
  3354. print "</table>\n";
  3355. print "<br/><br/>\n";
  3356. $var = 0;
  3357. $cv = 0;
  3358. $dv = 0;
  3359. $avg = 0;
  3360. if ($sum_correct_student) {
  3361. $avg = $sum_correct / $sum_student;
  3362. if ($avg > 0) {
  3363. foreach ($sum_correct_student as $student)
  3364. $var += pow($student->sum - $avg, 2);
  3365. $var = $var / $sum_student;
  3366. $dv = sqrt($var);
  3367. $cv = ($dv / $avg) * 100;
  3368. }
  3369. }
  3370. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3371. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3372. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3373. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3374. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3375. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3376. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3377. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3378. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3379. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3380. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3381. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3382. print "</table>\n";
  3383. } // if ($this->action != 'printstats')
  3384. die();
  3385. }
  3386. /// Display graphics of performance for students
  3387. function stats_students () {
  3388. global $USER, $CFG, $DB, $OUTPUT;
  3389. $id = $this->cm->id;
  3390. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3391. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3392. $title = get_string('results', 'iassign');
  3393. $sum_correct = 0;
  3394. $sum_incorrect = 0;
  3395. $sum_post = 0;
  3396. $sum_nopost = 0;
  3397. $sum_iassign = count($iassign_statement_list);
  3398. $bar_nopost = "";
  3399. $bar_correct = "";
  3400. $bar_incorrect = "";
  3401. $bar_post = "";
  3402. $text_nopost = "";
  3403. $text_correct = "";
  3404. $text_incorrect = "";
  3405. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3406. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3407. if ($iassign_submission) {
  3408. if ($iassign_submission->status == 3)
  3409. $sum_correct ++;
  3410. elseif ($iassign_submission->status == 2)
  3411. $sum_incorrect ++;
  3412. elseif ($iassign_submission->status == 1)
  3413. $sum_post ++;
  3414. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3415. $sum_nopost ++;
  3416. } // if ($iassign_submission)
  3417. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3418. if ($sum_iassign > 0) {
  3419. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3420. $text_correct = number_format($percent_correct, 1) . '%';
  3421. }
  3422. if ($sum_correct > 0) {
  3423. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3424. $bar_correct .= iassign_icons::insert('hbar_green');
  3425. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3426. } // if ($sum_correct > 0)
  3427. if ($sum_iassign > 0) {
  3428. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3429. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3430. }
  3431. if ($sum_incorrect > 0) {
  3432. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3433. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3434. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3435. } // if ($sum_incorrect > 0)
  3436. if ($sum_iassign > 0) {
  3437. $percent_post = ($sum_post / $sum_iassign) * 100;
  3438. $text_post = number_format($percent_post, 1) . '%';
  3439. }
  3440. if ($sum_post > 0) {
  3441. for ($i = 1; $i < $percent_post * 2; $i ++)
  3442. $bar_post .= iassign_icons::insert('hbar_blue');
  3443. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3444. } // if ($sum_post > 0)
  3445. if ($sum_iassign > 0) {
  3446. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3447. $text_nopost = number_format($percent_nopost, 1) . '%';
  3448. }
  3449. if ($sum_nopost > 0) {
  3450. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3451. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3452. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3453. } // if ($sum_nopost > 0)
  3454. print $OUTPUT->header();
  3455. $this->print_main_menu();
  3456. print "<br/><br/>\n";
  3457. print '<table id="outlinetable" class="generaltable box aligncenter mt-5" cellpadding="5" width="100%">' . "\n";
  3458. print '<tr><th colspan=3 class="header c1">' . "\n";
  3459. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3460. // $imagetext = '');
  3461. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3462. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3463. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3464. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3465. print '</tr>' . "\n";
  3466. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3467. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3468. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3469. print '</tr>' . "\n";
  3470. if ($sum_post) {
  3471. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3472. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3473. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3474. print '</tr>' . "\n";
  3475. } // if ($sum_post)
  3476. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3477. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3478. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3479. print '</tr>' . "\n";
  3480. print "</table>";
  3481. print "<br><br>";
  3482. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3483. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3484. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3485. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3486. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3487. $sum_grade = 0;
  3488. $sum_grade_student = 0;
  3489. $avg = 0;
  3490. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3491. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3492. if (!$iassign_submission) {
  3493. $iassign_submission = new stdClass();
  3494. $iassign_submission->grade = 0;
  3495. }
  3496. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3497. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3498. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3499. print '</tr>' . "\n";
  3500. $sum_grade += $iassign_statement_activity_item->grade;
  3501. $sum_grade_student += $iassign_submission->grade;
  3502. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3503. if ($sum_grade > 0)
  3504. $avg = $sum_grade_student / $sum_grade * 100;
  3505. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3506. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3507. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3508. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3509. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3510. print "</table>";
  3511. print $OUTPUT->footer();
  3512. die();
  3513. } // function stats_students()
  3514. function get_total_notifications () {
  3515. global $DB, $USER, $COURSE;
  3516. $total_messages = 0;
  3517. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3518. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3519. $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 "
  3520. . " 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);
  3521. }
  3522. else {
  3523. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3524. $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 "
  3525. . " 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);
  3526. }
  3527. return $total_messages->total;
  3528. }
  3529. function get_iassign_statement_messages () {
  3530. global $DB, $USER, $COURSE;
  3531. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3532. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '1');
  3533. $totais = array();
  3534. $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 "
  3535. . " 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);
  3536. foreach($messages as $item) {
  3537. if (isset($totais[$item->subid])) {
  3538. $totais[$item->subid]->total ++;
  3539. }
  3540. else {
  3541. $totais[$item->subid] = new stdclass();
  3542. $item->total = 1;
  3543. $totais[$item->subid] = $item;
  3544. }
  3545. }
  3546. return $totais;
  3547. }
  3548. else {
  3549. $params = array('userid' => $USER->id, 'course' => $COURSE->id, 'receiver' => '2');
  3550. $totais = array();
  3551. $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 "
  3552. . " 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);
  3553. foreach($messages as $item) {
  3554. if (isset($totais[$item->subid])) {
  3555. $totais[$item->subid]->total ++;
  3556. }
  3557. else {
  3558. $totais[$item->subid] = new stdclass();
  3559. $item->total = 1;
  3560. $totais[$item->subid] = $item;
  3561. }
  3562. }
  3563. return $totais;
  3564. }
  3565. }
  3566. function view_notifications_teachers () {
  3567. global $OUTPUT, $USER, $DB;
  3568. $messages = $this->get_iassign_statement_messages();
  3569. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3570. // 1º. listar as mensagens recebidas no bloco atual:
  3571. $actual_block = $this->iassign->id;
  3572. $id = $this->cm->id;
  3573. $total_include = 0;
  3574. $activities_actual_block = array();
  3575. if ($messages)
  3576. foreach ($messages as $item)
  3577. if ($item->iasid == $actual_block)
  3578. if (!in_array($item->stid, $activities_actual_block))
  3579. array_push($activities_actual_block, $item->stid);
  3580. if ($activities_actual_block)
  3581. foreach ($activities_actual_block as $activity_id) {
  3582. $printed = false;
  3583. foreach ($messages as $item) {
  3584. if ($item->stid == $activity_id) {
  3585. if (!$printed) {
  3586. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid";
  3587. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3588. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3589. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3590. $printed = true;
  3591. }
  3592. $submission_url = "view.php?id=$id&userid_iassign=$item->user&action=viewsubmission&iassign_current=$item->stid";
  3593. $user = $DB->get_record('user', array('id' => $item->user));
  3594. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3595. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3596. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3597. '<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>'
  3598. .'</tr>';
  3599. $total_include++;
  3600. }
  3601. }
  3602. print '</td></tr></table>';
  3603. }
  3604. print '</table>';
  3605. if (count($activities_actual_block) == 0) {
  3606. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3607. print '<hr class="my-4">';
  3608. }
  3609. if ($messages && $total_include == count($messages)) {
  3610. print $OUTPUT->footer();
  3611. return;
  3612. }
  3613. 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>';
  3614. $iassign_ids = array();
  3615. if ($messages)
  3616. foreach ($messages as $item)
  3617. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3618. array_push($iassign_ids, $item->iasid);
  3619. foreach ($iassign_ids as $id_iassign) {
  3620. $printed = false;
  3621. $activities_in_block = array();
  3622. foreach ($messages as $subitem)
  3623. if ($subitem->iasid == $id_iassign)
  3624. if (!in_array($item->stid, $activities_in_block))
  3625. array_push($activities_in_block, $item->stid);
  3626. foreach ($messages as $item) {
  3627. if ($item->iasid == $id_iassign) {
  3628. if (!$printed) {
  3629. $printed = true;
  3630. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3631. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3632. }
  3633. foreach ($activities_in_block as $id_activity) {
  3634. $print = false;
  3635. foreach ($messages as $subitem) {
  3636. if ($subitem->stid == $id_activity) {
  3637. if (!$print) {
  3638. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$subitem->stid";
  3639. $link_student = "<a href='$student_url'>" . $subitem->stname . "</a>";
  3640. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle">' . $link_student . '';
  3641. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3642. $print = true;
  3643. }
  3644. foreach ($messages as $comment_student) {
  3645. if ($comment_student->stid == $id_activity) {
  3646. $submission_url = "view.php?id=$id&userid_iassign=$comment_student->user&action=viewsubmission&iassign_current=$comment_student->stid";
  3647. $user = $DB->get_record('user', array('id' => $comment_student->user));
  3648. $label = $comment_student->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3649. print '<tr><td style="white-space: nowrap; width: 1%; padding-right: 2rem;" class="align-middle"><i class="fa fa-user" aria-hidden="true"></i> '
  3650. . $user->firstname . ' ' . $user->lastname . ' </td>'.
  3651. '<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>'
  3652. .'</tr>';
  3653. }
  3654. }
  3655. break;
  3656. }
  3657. }
  3658. }
  3659. print '</table></td></tr></table>';
  3660. break;
  3661. }
  3662. }
  3663. }
  3664. print $OUTPUT->footer();
  3665. }
  3666. function view_notifications () {
  3667. global $OUTPUT, $USER;
  3668. print $OUTPUT->header();
  3669. $this->print_main_menu();
  3670. print '<h4 class="mt-4 ml-2"><i class="fa fa-comments-o" aria-hidden="true"></i> '.get_string('new_messages', 'iassign').'</h4>';
  3671. if ($this->get_total_notifications() == 0) {
  3672. print '<h6 class="mt-3 ml-5">'.get_string('empty_new_messages', 'iassign').'</h6>';
  3673. print '<hr class="my-4">';
  3674. print $OUTPUT->footer();
  3675. return;
  3676. }
  3677. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3678. $this->view_notifications_teachers();
  3679. return;
  3680. }
  3681. $messages = $this->get_iassign_statement_messages();
  3682. print '<table class="table table-hover ml-4 mb-4 w-75 mt-3" style="border-bottom: 1px solid #dee2e6;">';
  3683. // 1º. listar as mensagens recebidas no bloco atual:
  3684. $actual_block = $this->iassign->id;
  3685. $id = $this->cm->id;
  3686. $total_include = 0;
  3687. if ($messages)
  3688. foreach ($messages as $item) {
  3689. if ($item->iasid == $actual_block) {
  3690. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3691. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3692. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3693. 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>';
  3694. $total_include ++;
  3695. }
  3696. }
  3697. print '</table>';
  3698. if ($total_include == 0) {
  3699. print '<h6 class="ml-5">'.get_string('empty_new_messages_block', 'iassign').'</h6>';
  3700. print '<hr class="my-4">';
  3701. }
  3702. if ($messages && $total_include == count($messages)) {
  3703. print $OUTPUT->footer();
  3704. return;
  3705. }
  3706. 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>';
  3707. // 2º. listar as mensagens recebidas nos demais blocos do curso:
  3708. $iassign_ids = array();
  3709. if ($messages)
  3710. foreach ($messages as $item)
  3711. if (!in_array($item->iasid, $iassign_ids) && $item->iasid != $actual_block)
  3712. array_push($iassign_ids, $item->iasid);
  3713. foreach ($iassign_ids as $id_iassign) {
  3714. $printed = false;
  3715. foreach ($messages as $item) {
  3716. if ($item->iasid == $id_iassign) {
  3717. if (!$printed) {
  3718. $printed = true;
  3719. print '<i class="fa fa-th-large ml-4 mb-3 mt-2" aria-hidden="true"></i> ' . $item->iasname . '<br>';
  3720. print '<table class="table table-hover ml-5 w-75" style="border-bottom: 1px solid #dee2e6;">';
  3721. }
  3722. $student_url = "view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$item->stid#comments";
  3723. $link_student = "<a href='$student_url'>" . $item->stname . "</a>";
  3724. $label = $item->total > 1 ? get_string('comment_unread', 'iassign') : get_string('comment_unread_one', 'iassign');
  3725. 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>';
  3726. }
  3727. }
  3728. print '</table>';
  3729. }
  3730. print $OUTPUT->footer();
  3731. }
  3732. function print_main_menu () {
  3733. global $USER;
  3734. $id = $this->cm->id;
  3735. $actual_action = optional_param('action', '', PARAM_TEXT);
  3736. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3737. $url_report = new moodle_url('/mod/iassign/view.php', array('action' => 'report', 'id' => $id, 'iassignid' => $this->iassign->id));
  3738. $url_add = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'add', 'iassignid' => $this->iassign->id));
  3739. $url_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats_student', 'iassignid' => $this->iassign->id));
  3740. $url_home = new moodle_url('/mod/iassign/view.php', array('id' => $id));
  3741. $url_notifications = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'notifications', 'iassignid' => $this->iassign->id));
  3742. $url_auto_evaluate = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'auto_evaluate', 'iassignid' => $this->iassign->id));
  3743. $url_sub_stats = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'stats', 'iassignid' => $this->iassign->id));
  3744. $url_all_submissions = new moodle_url('/mod/iassign/view.php', array('id' => $id, 'action' => 'all_submissions', 'iassignid' => $this->iassign->id));
  3745. print '<div class="btn-group" role="group" aria-label="">';
  3746. print '<a href="'.$url_home.'" class="btn btn-outline-primary '.($actual_action == '' ? 'active' : '').'">
  3747. <i class="fa fa-home" aria-hidden="true"></i> '.get_string('activities_page', 'iassign').'
  3748. </a>';
  3749. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3750. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3751. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3752. // Has capability to see "report": teacher or up
  3753. 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>';
  3754. print '<div class="btn-group">
  3755. <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">
  3756. <i class="fa fa-bar-chart" aria-hidden="true"></i> '.get_string('report', 'iassign').'</a>
  3757. <div class="dropdown-menu">
  3758. <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>
  3759. <div class="dropdown-divider"></div>
  3760. <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>
  3761. <div class="dropdown-divider"></div>
  3762. <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>
  3763. </div>
  3764. </div>
  3765. ';
  3766. 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>';
  3767. 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>';
  3768. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3769. $notifications = $this->get_total_notifications();
  3770. print '<a href="'.$url_notifications.'" class="btn btn-outline-primary '.($actual_action == 'notifications' ? 'active' : '').'">
  3771. <i class="fa fa-bell" aria-hidden="true"></i> '.get_string('notifications', 'iassign');
  3772. if ($notifications > 0)
  3773. print ' <span class="badge bg-danger rounded-pill" style="color: white; font-size: .9rem;">'.$notifications.'</span>';
  3774. print '</a>';
  3775. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3776. print '<a href="'.$url_add.'" class="btn btn-success"><i class="fa fa-plus" aria-hidden="true"></i> '.get_string('add_iassign', 'iassign').'</a>';
  3777. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3778. print '</div>' . "\n";
  3779. }
  3780. /// Display page of iAssign's activity
  3781. function view_iassigns () {
  3782. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3783. $id = $this->cm->id;
  3784. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3785. $notice = optional_param('notice', '', PARAM_TEXT);
  3786. if (strpos($notice, 'error'))
  3787. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3788. else if ($notice != '')
  3789. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3790. $this->print_main_menu();
  3791. print $OUTPUT->box_start();
  3792. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3793. print '<div class="border float-right">';
  3794. if ($iassign_list) {
  3795. // $USER->iassignEdit == 0 view 'Turn editing off'
  3796. // $USER->iassignEdit == 1 view 'Turn editing on'
  3797. if (!isset($USER->iassignEdit))
  3798. $USER->iassignEdit = 0;
  3799. if ($USER->iassignEdit == 0) {
  3800. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3801. $botton = 1;
  3802. } // if ($USER->iassignEdit == 0)
  3803. elseif ($USER->iassignEdit == 1) {
  3804. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3805. $botton = 0;
  3806. } // elseif ($USER->iassignEdit == 1)
  3807. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3808. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3809. print " <input class='btn btn-primary' type=submit value='$bottonEdit_message'/>\n";
  3810. print "</form>\n";
  3811. } // if ($iassign_list)
  3812. print '</div>';
  3813. }
  3814. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3815. // $this->view_legend_icons();
  3816. print $OUTPUT->box_end();
  3817. $iassign_array_exercise = array();
  3818. $i_exercise = 0;
  3819. $iassign_array_test = array();
  3820. $i_test = 0;
  3821. $iassign_array_example = array();
  3822. $i_example = 0;
  3823. $iassign_array_general = array();
  3824. $i_general = 0;
  3825. if ($iassign_list) {
  3826. if ($this->iassign->activity_group == 0) {
  3827. foreach ($iassign_list as $iassign) {
  3828. $iassign_array_general[$i_general] = $iassign;
  3829. $i_general ++;
  3830. }
  3831. } // if ($this->iassign->activity_group == 0)
  3832. else {
  3833. foreach ($iassign_list as $iassign) {
  3834. if ($iassign->type_iassign == 3) {
  3835. $iassign_array_exercise[$i_exercise] = $iassign;
  3836. $i_exercise ++;
  3837. } // if ($iassign->type_iassign == 3)
  3838. if ($iassign->type_iassign == 2) {
  3839. $iassign_array_test[$i_test] = $iassign;
  3840. $i_test ++;
  3841. } // if ($iassign->type_iassign == 2)
  3842. if ($iassign->type_iassign == 1) {
  3843. $iassign_array_example[$i_example] = $iassign;
  3844. $i_example ++;
  3845. } // if ($iassign->type_iassign == 1)
  3846. }
  3847. }
  3848. if ($iassign_array_exercise) {
  3849. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3850. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3851. }
  3852. if ($iassign_array_test) {
  3853. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3854. $this->show_iassign($title, $iassign_array_test, $i_test);
  3855. }
  3856. if ($iassign_array_example) {
  3857. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3858. $this->show_iassign($title, $iassign_array_example, $i_example);
  3859. }
  3860. if ($iassign_array_general) {
  3861. $title = "";
  3862. $this->show_iassign($title, $iassign_array_general, $i_general);
  3863. }
  3864. } else { // if ($iassign_list)
  3865. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3866. }
  3867. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3868. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3869. print $OUTPUT->box_start();
  3870. print '<table width=100% border=0><tr>' . "\n";
  3871. print '<td width=10% align="left">' . "\n";
  3872. print $link_report;
  3873. print '</td>' . "\n";
  3874. print '</tr></table>' . "\n";
  3875. print $OUTPUT->box_end();
  3876. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3877. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3878. print $OUTPUT->box_start();
  3879. print '<table width=100% border=0><tr>' . "\n";
  3880. print '<td align="left">' . "\n";
  3881. print $link_add;
  3882. print '</td>' . "\n";
  3883. print '</tr></table>' . "\n";
  3884. print $OUTPUT->box_end();
  3885. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3886. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3887. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3888. // $this->view_legend_icons();
  3889. } // function view_iassigns()
  3890. /// Display all iAssigns
  3891. function show_iassign ($title, $iassign_array, $i) {
  3892. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3893. $id = $this->cm->id;
  3894. print $OUTPUT->box_start();
  3895. print " <script type='text/javascript'>
  3896. //<![CDATA[
  3897. function validate_move () {
  3898. var radios = document.getElementsByName('iassign_destiny');
  3899. var formValid = false;
  3900. //alert('aqui validate_move()');
  3901. var i = 0;
  3902. while (!formValid && i < radios.length) {
  3903. if (radios[i].checked) formValid = true;
  3904. i++;
  3905. }
  3906. if (!formValid) {
  3907. document.getElementById('move_dest').classList.add('alert-danger');
  3908. }
  3909. return formValid;
  3910. }
  3911. var modal;
  3912. function load_move(id_ias) {
  3913. document.form_move_activity.iassign_current.value = id_ias;
  3914. modal.style.display = 'block';
  3915. var radios = document.getElementsByName('iassign_destiny');
  3916. var i = 0;
  3917. while (i < radios.length) {
  3918. radios[i].checked = false;
  3919. i++;
  3920. }
  3921. document.getElementById('move_dest').classList.remove('alert-danger');
  3922. }
  3923. function closeModal() {
  3924. modal.style.display = 'none';
  3925. }
  3926. function load_modal_elements() {
  3927. modal = document.getElementById('myModal');
  3928. var span = document.getElementById('close_modal');
  3929. span.onclick = function() {
  3930. modal.style.display = 'none';
  3931. }
  3932. window.onclick = function(event) {
  3933. if (event.target == modal) {
  3934. modal.style.display = 'none';
  3935. }
  3936. }
  3937. }
  3938. window.onload = load_modal_elements;
  3939. //]]>
  3940. </script>\n";
  3941. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3942. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3943. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3944. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3945. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3946. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "'>
  3947. <input type='hidden' name='iassign_current' value='' />";
  3948. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3949. $section = $course_sections[0];
  3950. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3951. for ($k = 0; $k < count($ids_sections); $k++) {
  3952. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3953. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3954. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3955. if ($c_cm) {
  3956. if ($ccm->instance == $c_cm->instance) {
  3957. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3958. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3959. }
  3960. else {
  3961. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3962. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3963. }
  3964. }
  3965. }
  3966. $radio_buttons .= "</ul>";
  3967. }
  3968. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3969. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='closeModal()' data-bs-dismiss='modal' /></center>
  3970. </form>
  3971. </div></div> </div></div>\n";
  3972. print " <style>.modal {
  3973. display: none;
  3974. position: fixed;
  3975. z-index: 1;
  3976. left: 0;
  3977. top: 0;
  3978. width: 100%;
  3979. height: 100%;
  3980. overflow: scroll;
  3981. background-color: rgb(0,0,0);
  3982. background-color: rgba(0,0,0,0.4);
  3983. }
  3984. .modal-content {
  3985. background-color: #fefefe;
  3986. margin: 15% auto;
  3987. padding: 10px 10px;
  3988. border: 1px solid #888;
  3989. width: 50%;
  3990. }
  3991. #close_modal {
  3992. color: #aaa;
  3993. float: right;
  3994. font-size: 28px;
  3995. font-weight: bold;
  3996. margin-top: -15px;
  3997. margin-right: -3px;
  3998. }
  3999. #close_modal:hover,
  4000. #close_modal:focus {
  4001. color: black;
  4002. text-decoration: none;
  4003. cursor: pointer;
  4004. }
  4005. #modal_title {
  4006. min-height: 3rem;
  4007. color: initial;
  4008. background: initial;
  4009. font-size: 1.5rem;
  4010. line-height: 1.5;
  4011. padding: 15px;
  4012. border-bottom: 1px solid #e5e5e5;
  4013. }
  4014. .input_move {
  4015. width: 90%;
  4016. padding: 2px;
  4017. }
  4018. .input_move:hover {
  4019. background: #eff0ef;
  4020. }
  4021. </style>";
  4022. $action_links = "";
  4023. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  4024. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>";
  4025. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">';
  4026. for ($j = 0; $j < $i; $j ++) {
  4027. $iassign_current = $iassign_array[$j]->id;
  4028. // receiver=1 - message to teacher
  4029. // receiver=2 - message to student
  4030. $sum_comment = 0;
  4031. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  4032. foreach ($iassign_submissions as $iassign_submission) {
  4033. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  4034. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4035. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4036. if ($verify_message)
  4037. foreach ($verify_message as $tmp)
  4038. $sum_comment += $tmp;
  4039. } // foreach ($iassign_submissions as $iassign_submission)
  4040. if ($sum_comment == 0)
  4041. $comment_unread = "";
  4042. else {
  4043. $comment_unread_message = get_string('comment_unread', 'iassign');
  4044. if ($sum_comment == 1)
  4045. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4046. $comment_unread = ' <a href="' . $CFG->wwwroot . '/mod/iassign/view.php?id=' . $id . '&action=report&iassignid=' . $this->iassign->id . '"><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 . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$sum_comment.'</span> </span></a>';
  4047. }
  4048. if ($j == $i - 1)
  4049. $iassign_down = $iassign_array[$j]->id;
  4050. else
  4051. $iassign_down = $iassign_array[$j + 1]->id;
  4052. if ($j > 0)
  4053. $iassign_up = $iassign_array[$j - 1]->id;
  4054. else
  4055. $iassign_up = $iassign_array[$j]->id;
  4056. if ($iassign_array[$j]->visible == 0)
  4057. $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>";
  4058. else
  4059. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  4060. $links .= $comment_unread;
  4061. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  4062. $action_links = "<nav aria-label='Action links'><ul class='pagination pagination-sm mb-0 my-1 text-success'>";
  4063. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  4064. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  4065. $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>";
  4066. if ($j==0) // first activity
  4067. $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>";
  4068. else
  4069. $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>";
  4070. $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>";
  4071. $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>";
  4072. $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>";
  4073. $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>";
  4074. $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>";
  4075. $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>";
  4076. if (count($iassign_array) > 1) {
  4077. if ($j == 0)
  4078. $action_links .= $link_down;
  4079. elseif ($j == $i - 1)
  4080. $action_links .= $link_up;
  4081. else
  4082. $action_links .= $link_up . $link_down;
  4083. } // if (count($iassign_array) > 1)
  4084. $action_links .= $link_edit . $link_delete;
  4085. if ($iassign_array[$j]->visible == 0)
  4086. $action_links .= $link_visible_show;
  4087. else
  4088. $action_links .= $link_visible_hide;
  4089. $action_links .= $link_duplicate_activity . $link_move_activity;
  4090. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  4091. $action_links .= '</ul></nav>';
  4092. 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";
  4093. }
  4094. print '</tbody></table>';
  4095. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  4096. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  4097. print '<h5 class="fw-bold" style="font-weight: 400; margin: -1rem 0 1.5rem 0;">' . $title . "</h5>";
  4098. print '<table class="table table-hover" style="border-bottom: 1px solid #dee2e6;">';
  4099. for ($j = 0; $j < $i; $j ++) {
  4100. $icon_status = "";
  4101. $icon_comment = "";
  4102. if ($iassign_array[$j]->visible == 1) {
  4103. $iassign_current = $iassign_array[$j]->id;
  4104. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  4105. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  4106. $icon_status = "";
  4107. $icon_comment = "";
  4108. if ($iassign_submission) {
  4109. // receiver=1 - message to teacher
  4110. // receiver=2 - message to student
  4111. // $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");
  4112. $params_temp = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  4113. $verify_message = $DB->get_record_sql(
  4114. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4115. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params_temp);
  4116. if ($verify_message)
  4117. foreach ($verify_message as $tmp)
  4118. $sum_comment = $tmp;
  4119. if ($sum_comment > 0) {
  4120. $comment_unread_message = get_string('comment_unread', 'iassign');
  4121. if ($sum_comment == 1)
  4122. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  4123. $icon_comment = "<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current#comments'>" . '<span class="badge bg-danger" style="color:white; font-size: .9em;"><i class="fa fa-envelope" aria-hidden="true"></i> ' . $comment_unread_message . ' <span class="badge rounded-pill bg-light text-dark" style="font-size: .8em;">'.$sum_comment.'</span> </span></a>';
  4124. }
  4125. // $icon_comment = iassign_icons::insert('comment_unread');
  4126. if ($iassign_array[$j]->type_iassign == 3) {
  4127. if ($iassign_array[$j]->show_answer == 1) {
  4128. if ($iassign_submission->status == 3)
  4129. $icon_status = '<i class="fa fa-check" style="color: green; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('correct', 'iassign').'"></i>';
  4130. elseif ($iassign_submission->status == 2)
  4131. $icon_status = '<i class="fa fa-times" style="color: red; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('incorrect', 'iassign').'"></i>';
  4132. elseif ($iassign_submission->status == 1)
  4133. $icon_status = iassign_icons::insert('post');
  4134. elseif ($iassign_submission->status == 0)
  4135. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('not_post', 'iassign').'"></i>';
  4136. } // if ($iassign_array[$j]->show_answer==1)
  4137. else {
  4138. if ($iassign_submission->status == 0)
  4139. $icon_status = iassign_icons::insert('not_post');
  4140. else
  4141. $icon_status = iassign_icons::insert('post');
  4142. }
  4143. } // if ($iassign_array[$j]->type_iassign == 3)
  4144. } // if ($iassign_submission)
  4145. elseif ($iassign_array[$j]->type_iassign == 3) {
  4146. $icon_status = '<i class="fa fa-question" style="color: #77229c; font-size: 1.2rem;" aria-hidden="true" title="'.get_string('not_post', 'iassign').'"></i>';
  4147. } // if ($iassign_array[$j]->type_iassign == 3)
  4148. 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;">' . $links . '</td><td>'. $icon_comment.'</td></tr>' . "\n";
  4149. //print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  4150. } // if ($iassign_array[$j]->visible == 1)
  4151. } // for ($j = 0; $j < $i; $j++)
  4152. } else if (isguestuser()) {
  4153. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  4154. print '<table width=100% ><tr>' . "\n";
  4155. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  4156. print '</tr></table>' . "\n";
  4157. for ($j = 0; $j < $i; $j ++) {
  4158. $icon_status = "";
  4159. $icon_comment = "";
  4160. if ($iassign_array[$j]->visible == 1) {
  4161. $iassign_current = $iassign_array[$j]->id;
  4162. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  4163. print '<p>' . $links . '</p>' . "\n";
  4164. } // if ($iassign_array[$j]->visible == 1)
  4165. }
  4166. }
  4167. print '</table>';
  4168. print $OUTPUT->box_end();
  4169. } // function show_iassign($title, $iassign_array, $i)
  4170. /// Show message of return
  4171. function return_home_course ($message) {
  4172. //D global $DB, $OUTPUT;
  4173. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4174. //D echo $OUTPUT->box_start();
  4175. //D echo '<table width=100% border=0 valign="top">' . "\n";
  4176. //D echo '<tr><td align="left"><strong>' . "\n";
  4177. //D print_string($message, 'iassign');
  4178. //D echo '</strong></td>' . "\n";
  4179. //D echo '<td width=20% align="right">' . "\n";
  4180. //D echo $link_return;
  4181. //D echo '</td></tr></table>' . "\n";
  4182. //D echo $OUTPUT->box_end();
  4183. //D // echo $OUTPUT->footer();
  4184. redirect(new moodle_url($this->return . '&notice=' . $message));
  4185. exit;
  4186. }
  4187. /// Search comment of activity
  4188. function search_comment_submission ($iassign_submissionid) {
  4189. global $USER, $DB, $OUTPUT, $COURSE;
  4190. // $context = context_course::instance($COURSE->id);
  4191. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  4192. $colorEdit2 = "#d2e5fc";
  4193. $has_capability = 0;
  4194. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  4195. $text = "";
  4196. if ($comments) {
  4197. $even = 1;
  4198. foreach ($comments as $tmp) {
  4199. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  4200. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  4201. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  4202. // $text .= $tmp->comment . "</td></tr>";
  4203. //} else {
  4204. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  4205. $avatar = new user_picture($user_data);
  4206. $avatar->courseid = $COURSE->id;
  4207. $avatar->link = true;
  4208. $user_picture = $OUTPUT->render($avatar);
  4209. $user_picture = str_replace('"35"', '"45"', $user_picture);
  4210. if ($even) {
  4211. $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";
  4212. $even = 0;
  4213. } else {
  4214. $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";
  4215. $even = 1;
  4216. }
  4217. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  4218. } // foreach ($comments as $tmp)
  4219. }
  4220. return $text;
  4221. }
  4222. /// Update comment of activity
  4223. function update_comment ($iassign_submissionid) {
  4224. global $USER, $DB, $OUTPUT;
  4225. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  4226. $receiver = 1; // student message to teacher
  4227. else
  4228. $receiver = 2; // teacher message to student
  4229. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  4230. if ($verify_message) {
  4231. foreach ($verify_message as $message) {
  4232. if ($message->receiver == $receiver) {
  4233. $newentry = new stdClass();
  4234. $newentry->id = $message->id;
  4235. $newentry->return_status = 1;
  4236. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  4237. print_error('error_update', 'iassign');
  4238. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  4239. } // if ($message->receiver == $receiver)
  4240. // Trigger module viewed event.
  4241. $event = \mod_iassign\event\submission_comment_updated::create(array(
  4242. 'objectid' => $this->iassign->id,
  4243. 'context' => $this->context
  4244. ));
  4245. $event->add_record_snapshot('course', $this->course);
  4246. $event->trigger();
  4247. } // foreach ($verify_message as $message)
  4248. }
  4249. }
  4250. /// Record comment of activity
  4251. function write_comment_submission () {
  4252. global $USER, $CFG, $DB;
  4253. $id = $this->cm->id;
  4254. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  4255. $row = optional_param('row', 0, PARAM_INT);
  4256. $column = optional_param('column', 0, PARAM_INT);
  4257. $sum_comment = 0;
  4258. $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);
  4259. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  4260. $str1 = trim($submission_comment);
  4261. $str2 = trim(get_string('box_comment_message', 'iassign'));
  4262. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  4263. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  4264. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  4265. $receiver = 1; // student message to teacher
  4266. $this->action = 'view';
  4267. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  4268. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  4269. } else {
  4270. $receiver = 2; // teacher message to student
  4271. $this->action = 'viewsubmission';
  4272. //D $tousers = array(); //MOOC 2016
  4273. //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
  4274. }
  4275. //MOOC 2016: foi p/ 15 linhas acima:
  4276. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  4277. // verificar se existe uma submissão para o exercício e aluno informados
  4278. if (!$iassign_submission) {
  4279. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  4280. }
  4281. if (!$iassign_submission) {
  4282. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  4283. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  4284. $this->iassign_submission_current = $id_submission;
  4285. }
  4286. else {
  4287. $id_submission = $iassign_submission->id;
  4288. } // if (!$iassign_submission)
  4289. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  4290. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  4291. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  4292. $params_temp = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  4293. $comments = $DB->get_record_sql(
  4294. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  4295. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params_temp);
  4296. if ($comments)
  4297. foreach ($comments as $tmp)
  4298. $sum_comment = $tmp;
  4299. if ($sum_comment == 0) {
  4300. $newentry = new stdClass();
  4301. $newentry->iassign_submissionid = $id_submission;
  4302. $newentry->comment_authorid = $USER->id;
  4303. $newentry->timecreated = time();
  4304. $newentry->comment = $submission_comment;
  4305. $newentry->receiver = $receiver;
  4306. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  4307. $event = \mod_iassign\event\submission_comment_created::create(array(
  4308. 'objectid' => $this->iassign->id,
  4309. 'context' => $this->context
  4310. ));
  4311. $event->add_record_snapshot('course', $this->course);
  4312. $event->trigger();
  4313. }
  4314. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  4315. // if ($this->action=='viewsubmission') {
  4316. // echo $OUTPUT->header();
  4317. // $this->return_last('confirm_add_comment', $link_return);
  4318. // die;
  4319. // }
  4320. return true;
  4321. } // function write_comment_submission()
  4322. /// Writes a new submission
  4323. // The first student answer is under 'function get_answer()'
  4324. function new_submission ($iassignid, $id_user, $receiver) {
  4325. global $USER, $DB, $OUTPUT;
  4326. $newentry = new stdClass();
  4327. $newentry->iassign_statementid = $iassignid;
  4328. $newentry->userid = $id_user;
  4329. $newentry->timecreated = time();
  4330. $newentry->timemodified = time();
  4331. $newentry->answer = 0; // student only submit message
  4332. if ($receiver == 2) // teacher message to student (write id teacher)
  4333. $newentry->teacher = $USER->id;
  4334. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  4335. return_home_course('error_insert_submissions');
  4336. else {
  4337. // Trigger module view event
  4338. $event = \mod_iassign\event\submission_created::create(array(
  4339. 'objectid' => $this->iassign->id,
  4340. 'context' => $this->context
  4341. ));
  4342. $event->add_record_snapshot('course', $this->course);
  4343. $event->trigger();
  4344. }
  4345. return $newentry->id;
  4346. }
  4347. /// Return to a specific address of page
  4348. function return_last ($message, $link_return) {
  4349. global $DB, $OUTPUT;
  4350. print $OUTPUT->box_start();
  4351. print '<table width=100% border=0 valign="top">' . "\n";
  4352. print '<tr><td align="left"><strong>' . "\n";
  4353. print_string($message, 'iassign');
  4354. print '</strong></td>' . "\n";
  4355. print '<td width=20% align="right">' . "\n";
  4356. print $link_return;
  4357. print '</td></tr></table>' . "\n";
  4358. print $OUTPUT->box_end();
  4359. print $OUTPUT->footer();
  4360. die();
  4361. } // function return_last($message, $link_return)
  4362. } // class iassign
  4363. /// Class for manage activities
  4364. class activity {
  4365. var $activity;
  4366. /// Constructor of class.
  4367. // @param int $id Id of activity
  4368. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4369. //D public function activity($id) { self::__construct($id); }
  4370. function __construct ($id) {
  4371. global $DB;
  4372. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  4373. if (empty($this->activity))
  4374. $this->activity = null;
  4375. }
  4376. /// Get an activity
  4377. // @return NULL
  4378. function get_activity () {
  4379. if ($this->activity != null)
  4380. return $this->activity;
  4381. else
  4382. return null;
  4383. }
  4384. /// Delete interactive activities
  4385. function delete ($return) {
  4386. global $USER, $CFG, $DB, $OUTPUT;
  4387. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4388. print $OUTPUT->header();
  4389. $output .= $OUTPUT->box_start();
  4390. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  4391. if ($iassign_submission_currents) {
  4392. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  4393. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  4394. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  4395. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  4396. $output .= $OUTPUT->box_end();
  4397. $output .= $OUTPUT->footer();
  4398. print $output;
  4399. die();
  4400. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  4401. } // if ($iassign_submission_currents)
  4402. else
  4403. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  4404. $output .= '<table width=50% border=0>';
  4405. $output .= '<tr valign="top"><td>';
  4406. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  4407. $output .= '</td><td>';
  4408. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  4409. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  4410. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  4411. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  4412. $output .= "</form>\n";
  4413. $output .= '</td><td>';
  4414. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  4415. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  4416. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  4417. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  4418. $output .= "</form>\n";
  4419. $output .= '</td></tr></table>' . "\n";
  4420. $output .= $OUTPUT->box_end();
  4421. $output .= $OUTPUT->footer();
  4422. print $output;
  4423. } // function delete($return)
  4424. /// Function for confirm the delete of activity
  4425. // @param String $return Url of return
  4426. // @param Object $iassign Object content an activity
  4427. function deleteyes ($return, $iassign) {
  4428. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  4429. $msg = '';
  4430. if (!empty($this->activity->id)) {
  4431. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  4432. if ($iassign_submission_currents) {
  4433. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  4434. foreach ($iassign_submission_currents as $iassign_submission)
  4435. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  4436. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  4437. } // if ($iassign_submission_currents)
  4438. }
  4439. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  4440. // Remove all files associated to this activity:
  4441. $fs = get_file_storage();
  4442. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  4443. $this->delete_calendar($this->activity->id);
  4444. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  4445. iassign::update_grade_iassign($this->activity->iassignid);
  4446. if ($delete_iassign_current) {
  4447. $iassign->return_home_course('confirm_delete_iassign');
  4448. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  4449. } else {
  4450. $iassign->return_home_course('error_confirm_delete_iassign');
  4451. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4452. }
  4453. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4454. }
  4455. }
  4456. /// Changes position of activities (between those inside a group of interactive activities)
  4457. // @param $move_action = must be "up" or "down"
  4458. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4459. function move_iassign ($move_action, $target, $return) {
  4460. global $DB, $OUTPUT;
  4461. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4462. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4463. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4464. if ($move_action=="firstdown") {
  4465. $final_position_source = 2;
  4466. $final_position_target = 1;
  4467. }
  4468. else
  4469. if ($move_action=="down") {
  4470. $final_position_target = $this->activity->position;
  4471. $final_position_source = $final_position_target + 1;
  4472. }
  4473. else
  4474. if ($move_action=="up") {
  4475. $final_position_target = $this->activity->position;
  4476. $final_position_source = $final_position_target - 1;
  4477. }
  4478. else { // error:
  4479. print_error('error_update_move_iassign', 'iassign');
  4480. exit;
  4481. }
  4482. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4483. $newentry->id = $this->activity->id; // ID of the "source activity"
  4484. $newentry->position = $final_position_source;
  4485. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4486. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4487. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4488. print_error('error_update_move_iassign', 'iassign');
  4489. }
  4490. else { // first update performed successfully
  4491. $newentry->id = $iassign_target->id;
  4492. $newentry->position = $final_position_target;
  4493. if (!$DB->update_record('iassign_statement', $newentry))
  4494. print_error('error_update_move_iassign', 'iassign');
  4495. }
  4496. redirect($return);
  4497. }
  4498. /// Enable or disable the display of interactive activities
  4499. function visible_iassign ($return) {
  4500. global $DB;
  4501. $newentry = new stdClass();
  4502. $newentry->id = $this->activity->id;
  4503. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4504. if (!$DB->update_record('iassign_statement', $newentry))
  4505. print_error('error_update_visible_iassign', 'iassign');
  4506. redirect($return);
  4507. }
  4508. /// Add news interactive activities (register in table 'iassign_statement')
  4509. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4510. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4511. function new_iassign ($param) {
  4512. global $DB;
  4513. $newentry = new stdClass();
  4514. $newentry->iassignid = $param->iassignid;
  4515. $newentry->name = $param->name;
  4516. $newentry->type_iassign = $param->type_iassign;
  4517. $newentry->store_all_submissions = $param->store_all_submissions;
  4518. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4519. $proposition = $param->proposition;
  4520. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4521. else $proposition_text = $proposition;
  4522. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4523. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4524. //TODO Then get it directly from the form data $_POST!
  4525. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4526. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4527. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4528. $newentry->author_name = $param->author_name;
  4529. $newentry->author_modified_name = $param->author_modified_name;
  4530. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4531. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4532. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4533. $newentry->grade = $param->grade;
  4534. $newentry->timemodified = time();
  4535. $newentry->timecreated = time();
  4536. if ($param->type_iassign == 1) {
  4537. $newentry->timedue = 0;
  4538. $newentry->timeavailable = 0;
  4539. } // if ($param->type_iassign == 1)
  4540. else {
  4541. $newentry->timedue = $param->timedue;
  4542. $newentry->timeavailable = $param->timeavailable;
  4543. }
  4544. $newentry->preventlate = $param->preventlate;
  4545. $newentry->test = $param->test;
  4546. $newentry->special_param1 = $param->special_param1;
  4547. $newentry->visible = $param->visible;
  4548. $newentry->position = $param->position;
  4549. $newentry->max_experiment = $param->max_experiment;
  4550. $newentry->dependency = $param->dependency;
  4551. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4552. $newentry->show_answer = $param->show_answer;
  4553. $id = $DB->insert_record("iassign_statement", $newentry);
  4554. if ($id) {
  4555. $component = 'mod_iassign';
  4556. $filearea = 'exercise';
  4557. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4558. $file = $fs->get_file_by_id($param->file);
  4559. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4560. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4561. //$itemid = $id;
  4562. // File already inserted in other context!
  4563. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4564. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4565. $updateentry = new stdClass();
  4566. $updateentry->id = $id;
  4567. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4568. $updateentry->filesid = $newfile->get_itemid();
  4569. if (!$DB->update_record("iassign_statement", $updateentry))
  4570. print_error('error_add', 'iassign');
  4571. if ($param->type_iassign == 3)
  4572. iassign::update_grade_iassign($param->iassignid);
  4573. //TODO iLM_HTML5 :: //MOOC2014
  4574. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4575. //D if ($iassign_ilm_configs) {
  4576. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4577. //D if ($iassign_ilm_config->param_type != 'static') {
  4578. //D $newentry = new stdClass();
  4579. //D $newentry->iassign_statementid = $id;
  4580. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4581. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4582. //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});
  4583. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4584. //D print_error('error_add_param', 'iassign');
  4585. //D }
  4586. //D }
  4587. //D }
  4588. // log event --------------------------------------------------------------------------------------
  4589. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4590. // log event --------------------------------------------------------------------------------------
  4591. return $id;
  4592. }
  4593. else
  4594. print_error('error_add', 'iassign');
  4595. } // function new_iassign($param)
  4596. /// Add the calendar entries for this iassign
  4597. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4598. // @return bool
  4599. static function add_calendar ($iassignid) {
  4600. global $DB, $CFG;
  4601. require_once($CFG->dirroot . '/calendar/lib.php');
  4602. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4603. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4604. $event = new stdClass();
  4605. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4606. $event->description = $iassign_statement_activity_item->name;
  4607. $event->courseid = $iassign->course;
  4608. $event->groupid = 0;
  4609. $event->userid = 0;
  4610. $event->modulename = 'iassign';
  4611. $event->instance = $iassign->id;
  4612. $event->eventtype = 'due';
  4613. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4614. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4615. calendar_event::create($event);
  4616. }
  4617. /// Update the calendar entries for this iassign
  4618. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4619. // @return bool
  4620. function update_calendar ($iassignid, $olddescription) {
  4621. global $DB, $CFG;
  4622. require_once($CFG->dirroot . '/calendar/lib.php');
  4623. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4624. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4625. $event = new stdClass();
  4626. $event->id = 0;
  4627. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4628. if ($events) {
  4629. foreach ($events as $value) {
  4630. if ($value->description == $olddescription) {
  4631. $event->id = $value->id;
  4632. }
  4633. }
  4634. }
  4635. if ($event->id != 0) {
  4636. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4637. $event->description = $iassign_statement_activity_item->name;
  4638. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4639. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4640. $calendarevent = calendar_event::load($event->id);
  4641. $calendarevent->update($event);
  4642. } else
  4643. $this->add_calendar($iassignid);
  4644. }
  4645. /// Update the calendar entries for this iassign
  4646. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4647. // @return bool
  4648. function delete_calendar ($iassignid) {
  4649. global $DB, $CFG;
  4650. require_once($CFG->dirroot . '/calendar/lib.php');
  4651. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4652. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4653. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4654. if ($events) {
  4655. foreach ($events as $value) {
  4656. if ($value->description == $iassign_statement_activity_item->name) {
  4657. $DB->delete_records('event', array('id' => $value->id));
  4658. }
  4659. }
  4660. }
  4661. }
  4662. /// Update interactive activities
  4663. function update_iassign ($param) {
  4664. global $DB;
  4665. $component = 'mod_iassign';
  4666. $filearea = 'exercise';
  4667. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4668. $file = $fs->get_file_by_id($param->file);
  4669. $fileold = $fs->get_file_by_id($param->fileold);
  4670. if ($param->file != $param->fileold) {
  4671. if ($fileold) {
  4672. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4673. foreach ($fileoldarea as $value) {
  4674. $value->delete();
  4675. }
  4676. }
  4677. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4678. $itemid = $file->get_itemid() + $param->iassign_id;
  4679. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4680. $param->file = $newfile->get_itemid();
  4681. } else
  4682. $param->file = $file->get_itemid();
  4683. } else {
  4684. $param->file = $file->get_itemid();
  4685. }
  4686. $newentry = new stdClass();
  4687. $newentry->id = $param->iassign_id;
  4688. $newentry->name = $param->name;
  4689. $newentry->type_iassign = $param->type_iassign;
  4690. $newentry->store_all_submissions = $param->store_all_submissions;
  4691. //2019 $newentry->proposition = $param->proposition;
  4692. $proposition = $param->proposition;
  4693. if (is_array($proposition))
  4694. $proposition_text = $proposition['text'];
  4695. else
  4696. $proposition_text = $proposition;
  4697. $newentry->proposition = $proposition_text;
  4698. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4699. $newentry->filesid = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4700. $newentry->grade = $param->grade;
  4701. $newentry->author_modified_name = $param->author_modified_name;
  4702. $newentry->timemodified = time();
  4703. if ($param->type_iassign == 1) {
  4704. $newentry->timedue = 0;
  4705. $newentry->timeavailable = 0;
  4706. } // if ($param->type_iassign == 1)
  4707. else {
  4708. $newentry->timedue = $param->timedue;
  4709. $newentry->timeavailable = $param->timeavailable;
  4710. }
  4711. $newentry->preventlate = $param->preventlate;
  4712. $newentry->test = $param->test;
  4713. if (isset($param->special_param1))
  4714. $newentry->special_param1 = $param->special_param1;
  4715. else
  4716. $newentry->special_param1 = NULL;
  4717. $newentry->visible = $param->visible;
  4718. $newentry->max_experiment = $param->max_experiment;
  4719. $newentry->dependency = $param->dependency;
  4720. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4721. $newentry->show_answer = $param->show_answer;
  4722. if (!$DB->update_record("iassign_statement", $newentry))
  4723. print_error('error_update', 'iassign');
  4724. if ($param->type_iassign == 3) {
  4725. iassign::update_grade_iassign($param->iassignid);
  4726. }
  4727. //$id = $newentry->id; // MOOC 2016 --- inicio
  4728. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4729. //if ($iassign_activity_item_configs) {
  4730. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4731. // $newentry = new stdClass();
  4732. // $newentry->id = $iassign_activity_item_config->id;
  4733. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4734. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4735. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4736. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4737. // print_error('error_edit_param', 'iassign');
  4738. // }
  4739. // } // MOOC 2016 --- final
  4740. // log event --------------------------------------------------------------------------------------
  4741. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4742. // log event --------------------------------------------------------------------------------------
  4743. return $newentry->id;
  4744. // if ($param->type_iassign==3)
  4745. // $this->update_grade_iassign($param->iassignid);
  4746. } // function update_iassign($param)
  4747. /// Show information of activity
  4748. function show_info_iassign () {
  4749. global $DB, $OUTPUT;
  4750. $output = '';
  4751. if ($this->activity->type_iassign == 3) {
  4752. if ($this->activity->dependency == 0) {
  4753. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  4754. } else {
  4755. $dependencys = explode(';', $this->activity->dependency);
  4756. $output .= '<p style="margin-top: -1rem;"><strong>' . get_string('dependency', 'iassign') . '</strong>';
  4757. foreach ($dependencys as $dependency) {
  4758. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4759. if ($dependencyiassign)
  4760. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4761. } // foreach ($dependencys as $dependency)
  4762. } // if ($iassign_statement_activity_item->dependency == 0)
  4763. if ($this->activity->max_experiment == 0)
  4764. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4765. else
  4766. $output .= '<strong style="margin-left: 3rem;">' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4767. $output .= '<strong style="margin-left: 3rem;">' . get_string('grade_iassign', 'iassign') . ':</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4768. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4769. $output .= $this->toggle_columns_script();
  4770. $output .= '<p><strong>' . get_string('proposition', 'iassign') . ':</strong></p>&nbsp;<div class="proposition">' . $this->activity->proposition . '</div>' . "\n";
  4771. print $OUTPUT->box($output);
  4772. } // function show_info_iassign()
  4773. /// Provide script to toggle columns
  4774. static function toggle_columns_script () {
  4775. $output = "";
  4776. $output .= '<script>
  4777. function toLeft () {
  4778. document.getElementsByClassName("proposition")[0].style.cssFloat = "left";
  4779. document.getElementsByClassName("proposition")[0].style.width = "40%";
  4780. document.getElementById("fullscreen").style.marginTop = "-3rem";
  4781. document.getElementById("columnsbutton").style.color = "#1da075";
  4782. }
  4783. function toDefault () {
  4784. document.getElementsByClassName("proposition")[0].style.cssFloat = "none";
  4785. document.getElementsByClassName("proposition")[0].style.width = "100%";
  4786. document.getElementById("fullscreen").style.marginTop = "0";
  4787. document.getElementById("columnsbutton").style.color = "#343a40";
  4788. }
  4789. var activate = false;
  4790. function toggleColumns () {
  4791. if (activate) {
  4792. activate = false;
  4793. toDefault();
  4794. } else {
  4795. activate = true;
  4796. toLeft();
  4797. }
  4798. }
  4799. </script>';
  4800. $output .= '<span tabindex="0" data-toggle="tooltip" title="'.get_string('enable_disable_columns', 'iassign').'" style="float: right"> <i id="columnsbutton" onclick="toggleColumns()" class="fa fa-columns" style="font-size: 1.5rem;" aria-hidden="true" role="button"></i></span>';
  4801. return $output;
  4802. }
  4803. /// Shows date of opening and closing activities
  4804. function view_dates () {
  4805. global $USER, $CFG, $DB, $OUTPUT;
  4806. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4807. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4808. $status_iassign = "";
  4809. $status_iassign1 = "";
  4810. $status_iassign2 = "";
  4811. if ($this->activity->type_iassign == 1) // activity of type example
  4812. $type_iassign = get_string('example_iassign', 'iassign');
  4813. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4814. $type_iassign = get_string('test_iassign', 'iassign');
  4815. if ($this->activity->timeavailable > time()) {
  4816. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4817. } elseif ($this->activity->timedue < time()) {
  4818. $status_iassign = get_string('last_timedue', 'iassign');
  4819. }
  4820. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4821. $type_iassign = get_string('exercise_iassign', 'iassign');
  4822. if ($this->activity->timeavailable > time()) {
  4823. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4824. } elseif ($this->activity->timedue < time()) { // after delivery
  4825. $status_iassign = get_string('last_timedue', 'iassign');
  4826. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4827. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4828. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4829. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4830. if ($this->activity->test == 1) // allowed to test after of deadline
  4831. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4832. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4833. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4834. } // elseif ($iassign_statement_activity_item->test == 0)
  4835. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4836. } // elseif ($iassign_statement_activity_item->timedue < time())
  4837. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4838. $output = '<table width=100% >' . "\n";
  4839. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4840. $output .= '<tr>' . "\n";
  4841. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4842. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4843. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4844. // leo $output .= '<td width=80%>' . $type_iassign;
  4845. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4846. // $output .= '</td>' . "\n";
  4847. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4848. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4849. $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>";
  4850. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4851. } else {
  4852. $link_next = "";
  4853. $link_previous = "";
  4854. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4855. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4856. // previous_activity
  4857. if ($iassign_previous) {
  4858. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4859. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4860. } // next_activity
  4861. if ($iassign_next) {
  4862. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4863. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4864. }
  4865. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4866. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4867. $output .= '</tr></table>' . "\n";
  4868. $output .= '<table width=100% >' . "\n";
  4869. if ($this->activity->type_iassign > 1) {
  4870. if ($this->activity->timeavailable)
  4871. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4872. if ($this->activity->timedue)
  4873. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4874. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4875. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4876. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4877. $output .= '</table>' . "\n";
  4878. print $OUTPUT->box($output);
  4879. } // function view_dates()
  4880. } // class activity
  4881. /// Class to manage Interactive Learning Module (iLM)
  4882. class ilm {
  4883. var $ilm;
  4884. /// Constructor of class
  4885. // @param int $id Id of iLM
  4886. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4887. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4888. function __construct ($id) {
  4889. global $DB;
  4890. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4891. if (empty($this->ilm))
  4892. $this->ilm = null;
  4893. }
  4894. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4895. // @calledby view_iassign_current()
  4896. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4897. global $USER, $CFG, $DB;
  4898. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4899. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4900. $typec = strtolower($iassign_ilm->type);
  4901. require_once 'ilm_handlers/' . $typec . '.php';
  4902. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4903. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4904. return $retorno;
  4905. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4906. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4907. // @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);
  4908. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4909. // @param Object $file File in use in activity
  4910. // @return int Return the id of log
  4911. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4912. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4913. $newentry = new stdClass();
  4914. $newentry->iassign_statementid = $iassign_activity_itemid;
  4915. $newentry->userid = $USER->id;
  4916. $newentry->filesid = $content_or_id_from_ilm_security;
  4917. $newentry->timecreated = time();
  4918. $newentry->view = 1;
  4919. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4920. if (!$id_iLM_security) {
  4921. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4922. } // from (!$DB->insert_record("iassign_security", $newentry))
  4923. return $id_iLM_security;
  4924. }
  4925. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4926. // @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);
  4927. // @param int $userid
  4928. // @param int $iassign_activity_itemid Id of iassign statement
  4929. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4930. global $DB;
  4931. // 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")
  4932. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4933. }
  4934. } // class ilm
  4935. /// Class to manage settings of iLM.
  4936. class ilm_settings {
  4937. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4938. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4939. // @param int $ilm_id Id of iLM
  4940. // @param array $options An array with options for create dynamic tag html APPLET
  4941. // @return string Return with a tag html APPLET created
  4942. static function build_ilm_tags ($ilm_id, $options = array()) {
  4943. global $DB;
  4944. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4945. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4946. $typec = strtolower($iassign_ilm->type);
  4947. require_once 'ilm_handlers/' . $typec . '.php';
  4948. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4949. return $retorno;
  4950. } // static function build_ilm_tags($ilm_id, $options = array())
  4951. /// Function for get modified date of iLM file
  4952. // @param string $file_jar String with Ids of iLM files
  4953. // @return string Return with the filenames and modified date
  4954. static function applet_filetime ($file_jar) {
  4955. $filetime = "";
  4956. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4957. $files_jar = explode(",", $file_jar);
  4958. foreach ($files_jar as $one_file) {
  4959. $file = $fs->get_file_by_id($one_file);
  4960. if ($file)
  4961. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4962. }
  4963. return $filetime;
  4964. }
  4965. /// Function for verify an default applet
  4966. // @param String $file_jar String containing an list de ids of applet files
  4967. // @return boolean Return true or fale if applet is default
  4968. static function applet_default ($file_jar) {
  4969. $is_default = true;
  4970. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4971. $files_jar = explode(",", $file_jar);
  4972. foreach ($files_jar as $one_file) {
  4973. $file = $fs->get_file_by_id($one_file);
  4974. if ($file)
  4975. $is_default &= ($file->get_itemid() == 0);
  4976. }
  4977. return $is_default;
  4978. }
  4979. /// Function for get form variables for add, edit, or copy iLM
  4980. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4981. // @see settings_form.php
  4982. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4983. // @param int $ilm_id Id of iLM
  4984. // @param string $action String with the action
  4985. // @return object Return an object with forms variables
  4986. static function add_edit_copy_ilm ($ilm_id, $action) {
  4987. global $USER, $DB, $CFG;
  4988. require_once('settings_form.php'); // put the form
  4989. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4990. $param = new stdClass();
  4991. //D echo "locallib.php: add_edit_copy_ilm: ilm_id,=$ilm_id, action="; print_r($action); echo "<br/>---------------------------------<br/>";
  4992. $param->action = $action;
  4993. $param->ilm_id = $ilm_id;
  4994. $CFG->action_ilm = $action;
  4995. $CFG->ilm_id = $ilm_id;
  4996. if ($action == 'add') {
  4997. $param->title = get_string('add_ilm', 'iassign');
  4998. $param->name = "";
  4999. $param->version = "";
  5000. $param->url = "";
  5001. $param->description = "";
  5002. $param->extension = "";
  5003. $param->author = $USER->id;
  5004. $param->file_jar = "";
  5005. $param->file_jar_static = "";
  5006. $param->file_class = "";
  5007. $param->width = 800;
  5008. $param->height = 600;
  5009. $param->enable = 0; // 0 - hide / 1 - show
  5010. $param->timecreated = time();
  5011. $param->timemodified = time();
  5012. $param->evaluate = 0;
  5013. $param->parent = 0;
  5014. }
  5015. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  5016. if ($iassign_ilm) {
  5017. $description = json_decode($iassign_ilm->description);
  5018. $param->title = get_string('edit_ilm', 'iassign');
  5019. $param->id = $iassign_ilm->id;
  5020. $param->name_ilm = $iassign_ilm->name;
  5021. $param->name = $iassign_ilm->name;
  5022. $param->version = $iassign_ilm->version;
  5023. $param->ilm_type = $iassign_ilm->type;
  5024. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5025. $param->url = $iassign_ilm->url; // iLM official URL
  5026. // 'iassign_ilm.submissionbehavior'=1 => this iLM does not have submission button
  5027. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  5028. $param->editingbehavior = $iassign_ilm->editingbehavior;
  5029. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  5030. if (!isset($description->{current_language()})) {
  5031. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  5032. else
  5033. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  5034. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  5035. }
  5036. else
  5037. $param->description = $description->{current_language()};
  5038. $param->description_lang = $iassign_ilm->description;
  5039. $param->extension = $iassign_ilm->extension;
  5040. $param->author = $iassign_ilm->author;
  5041. $param->file_jar = $iassign_ilm->file_jar;
  5042. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  5043. $param->file_class = $iassign_ilm->file_class;
  5044. $param->width = $iassign_ilm->width;
  5045. $param->height = $iassign_ilm->height;
  5046. $param->enable = $iassign_ilm->enable;
  5047. $param->timecreated = $iassign_ilm->timecreated;
  5048. $param->timemodified = time();
  5049. $param->evaluate = $iassign_ilm->evaluate;
  5050. $param->parent = $iassign_ilm->parent;
  5051. }
  5052. }
  5053. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  5054. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  5055. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5056. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  5057. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  5058. // echo "Sem dados<br/>"; exit;
  5059. return;
  5060. }
  5061. $description = json_decode($iassign_ilm->description);
  5062. if ($iassign_ilm) {
  5063. if ($iassign_ilm->parent == 0)
  5064. $iassign_ilm->parent = $ilm_id;
  5065. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  5066. $param->title = get_string('new_version_ilm', 'iassign');
  5067. $param->name_ilm = $iassign_ilm->name;
  5068. $param->name = $iassign_ilm->name;
  5069. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  5070. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  5071. $param->version = $iassign_ilm->version; // do not erase field 'version'
  5072. $param->ilm_type = $iassign_ilm->type;
  5073. $param->url = $iassign_ilm->url;
  5074. $param->description = $description->{current_language()};
  5075. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  5076. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5077. $param->extension = $iassign_ilm->extension;
  5078. $param->author = $USER->id;
  5079. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  5080. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  5081. $param->file_jar_static = '';
  5082. $param->file_class = $iassign_ilm->file_class;
  5083. $param->width = $iassign_ilm->width;
  5084. $param->height = $iassign_ilm->height;
  5085. $param->enable = 0;
  5086. $param->timecreated = time();
  5087. $param->timemodified = time();
  5088. $param->evaluate = $iassign_ilm->evaluate;
  5089. $param->parent = $iassign_ilm->parent;
  5090. }
  5091. }
  5092. elseif ($action == 'copy') {
  5093. $description = json_decode($iassign_ilm->description);
  5094. if ($iassign_ilm) {
  5095. if ($iassign_ilm->parent == 0)
  5096. $iassign_ilm->parent = $ilm_id;
  5097. $param->title = get_string('copy_ilm', 'iassign');
  5098. $param->id = $iassign_ilm->id;
  5099. $param->name_ilm = $iassign_ilm->name;
  5100. $param->name = $iassign_ilm->name;
  5101. $param->version = "";
  5102. $param->ilm_type = $iassign_ilm->type;
  5103. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  5104. $param->url = $iassign_ilm->url;
  5105. $param->description = $description->{current_language()};
  5106. $param->description_lang = $iassign_ilm->description;
  5107. $param->extension = $iassign_ilm->extension;
  5108. $param->author = $USER->id;
  5109. $param->file_jar = '';
  5110. $param->file_jar_static = '';
  5111. $param->file_class = $iassign_ilm->file_class;
  5112. $param->width = $iassign_ilm->width;
  5113. $param->height = $iassign_ilm->height;
  5114. $param->enable = 0;
  5115. $param->timecreated = time();
  5116. $param->timemodified = time();
  5117. $param->evaluate = $iassign_ilm->evaluate;
  5118. $param->parent = $iassign_ilm->parent;
  5119. }
  5120. }
  5121. //D echo "Fim: action=" . $param->action . "<br/>---------------------------------<br/>";
  5122. //D var_dump(debug_backtrace());
  5123. //D print_r(debug_backtrace());
  5124. return $param;
  5125. } // static function add_edit_copy_ilm($ilm_id, $action)
  5126. /// Function for save iLM file in moodledata
  5127. // @param int $itemid Itemid of file save in draft (upload file)
  5128. // @param int $ilm_id Id of iLM
  5129. // @return string Return an string with ids of iLM files
  5130. static function new_file_ilm ($itemid, $iassign_ilm) {
  5131. global $CFG, $USER, $DB;
  5132. $return = null;
  5133. $file_jar = array();
  5134. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5135. $contextuser = context_user::instance($USER->id);
  5136. $contextsystem = context_system::instance();
  5137. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  5138. if ($files_ilm) {
  5139. foreach ($files_ilm as $value) {
  5140. // CHECK IF file is HTML type
  5141. if ($iassign_ilm->type == 1) {
  5142. // Check if the file extension is ZIP
  5143. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  5144. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  5145. if ((strtolower($ext) == 'zip')) {
  5146. // Coping...:
  5147. $destination = 'ilm_debug/' . $value->get_filename();
  5148. $value->copy_content_to($destination);
  5149. // Extracting content...:
  5150. $zip = new ZipArchive();
  5151. $extracted = './ilm';
  5152. $dir = "";
  5153. if ($zip->open($destination) === TRUE) {
  5154. $dir = './ilm/' . trim($zip->getNameIndex(0));
  5155. if (is_dir($dir)) {
  5156. $i = 1;
  5157. $previous = str_replace("/", "", $zip->getNameIndex(0));
  5158. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  5159. $i ++;
  5160. }
  5161. $name = $previous . "_" . $i;
  5162. $dir = './ilm/' . $name . "/";
  5163. $j = 0;
  5164. while ($item_name = $zip->getNameIndex($j)) {
  5165. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  5166. $j++;
  5167. }
  5168. $zip->close();
  5169. }
  5170. $zip->open($destination);
  5171. $zip->extractTo($extracted);
  5172. $zip->close();
  5173. // After the extraction, remove it from DEBUG
  5174. unlink($destination);
  5175. } else { // Error trying to open destination...
  5176. // After the extraction error, also remove it from DEBUG
  5177. unlink($destination);
  5178. print_error('error_add_ilm_zip', 'iassign');
  5179. }
  5180. return $dir;
  5181. }
  5182. } // if ($iassign_ilm->type == 1)
  5183. if ($value->get_filename() != '.') {
  5184. $file_ilm = array(
  5185. 'userid' => $USER->id,
  5186. 'contextid' => $contextsystem->id,
  5187. 'component' => 'mod_iassign',
  5188. 'filearea' => 'ilm',
  5189. 'itemid' => rand(1, 999999999),
  5190. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  5191. 'filename' => $value->get_filename());
  5192. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  5193. array_push($file_jar, $file_ilm->get_id());
  5194. }
  5195. }
  5196. if (!empty($file_jar)) {
  5197. $return = implode(",", $file_jar);
  5198. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  5199. foreach ($old_file_jar as $value) {
  5200. $file = $fs->get_file_by_id($value);
  5201. if ($file)
  5202. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  5203. }
  5204. }
  5205. }
  5206. else // if ($files_ilm)
  5207. $return = $iassign_ilm->file_jar;
  5208. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  5209. return $return;
  5210. } // static function new_file_ilm($itemid, $iassign_ilm)
  5211. /// Function for save in database an new iLM
  5212. // @param object $param An object with iLM params
  5213. static function new_ilm ($itemid) {
  5214. global $CFG, $USER, $OUTPUT;
  5215. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5216. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5217. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5218. }
  5219. $pathtemp = $CFG->dataroot . '/temp/';
  5220. $contextuser = context_user::instance($USER->id);
  5221. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5222. $zip = new zip_packer();
  5223. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5224. foreach ($files as $file) {
  5225. if (!$file->is_directory())
  5226. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5227. }
  5228. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5229. // Verifica se o pacote possui o XML
  5230. if (!$application_xml) {
  5231. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5232. return;
  5233. } else {
  5234. $missing = "";
  5235. if (!isset($application_xml->name)) {
  5236. $missing .= "name";
  5237. }
  5238. if (!isset($application_xml->version)) {
  5239. $missing .= ", version";
  5240. }
  5241. if (!isset($application_xml->type)) {
  5242. $missing .= ", type";
  5243. }
  5244. if (!isset($application_xml->extension)) {
  5245. $missing .= ", extension";
  5246. }
  5247. if (!isset($application_xml->file_jar)) {
  5248. $missing .= ", file_jar";
  5249. }
  5250. if (!isset($application_xml->file_class)) {
  5251. $missing .= ", file_class";
  5252. }
  5253. if (!isset($application_xml->width)) {
  5254. $missing .= ", width";
  5255. }
  5256. if (!isset($application_xml->height)) {
  5257. $missing .= ", height";
  5258. }
  5259. if (!isset($application_xml->evaluate)) {
  5260. $missing .= ", evaluate";
  5261. }
  5262. if (strlen($missing) > 2) {
  5263. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5264. return;
  5265. }
  5266. }
  5267. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5268. $typec = strtolower($application_xml->type);
  5269. require_once 'ilm_handlers/' . $typec . '.php';
  5270. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5271. return $retorno;
  5272. } // static function new_ilm($itemid)
  5273. /// Function for save in database an iLM edit
  5274. // @param object $param An object with iLM params
  5275. static function edit_ilm ($param, $itemid) {
  5276. // Descobrir o tipo de iLM:
  5277. global $DB, $USER, $CFG;
  5278. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  5279. $pathtemp = $CFG->dataroot . '/temp/';
  5280. $contextuser = context_user::instance($USER->id);
  5281. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5282. $zip = new zip_packer();
  5283. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5284. $files_extract = null;
  5285. foreach ($files as $file) {
  5286. if (!$file->is_directory())
  5287. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5288. }
  5289. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  5290. $typec = strtolower($iassign_t->type);
  5291. require_once 'ilm_handlers/' . $typec . '.php';
  5292. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  5293. }
  5294. /// Function for register the new iLM (in database and in the directory)
  5295. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  5296. // @param object $param An object with iLM params
  5297. static function copy_new_version_ilm ($param) {
  5298. global $DB, $CFG, $USER;
  5299. $itemid = $param->file;
  5300. $pathtemp = $CFG->dataroot . '/temp/';
  5301. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  5302. //D echo "pathtemp=$pathtemp<br/>";
  5303. $contextuser = context_user::instance($USER->id);
  5304. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5305. $zip = new zip_packer();
  5306. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5307. $files_extract = null;
  5308. foreach ($files as $file) {
  5309. if (!$file->is_directory())
  5310. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5311. }
  5312. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5313. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  5314. $typec = strtolower($iassign_t->type);
  5315. require_once 'ilm_handlers/' . $typec . '.php';
  5316. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  5317. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  5318. } // static function copy_new_version_ilm($param)
  5319. //VER::
  5320. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  5321. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  5322. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  5323. /// Function for change visibility of iLM
  5324. // @param int $ilm_id Id of iLM
  5325. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5326. static function visible_ilm ($ilm_id, $status) {
  5327. global $DB;
  5328. if ($status == 0)
  5329. $visible = 1;
  5330. else
  5331. $visible = 0;
  5332. $newentry = new stdClass();
  5333. $newentry->id = $ilm_id;
  5334. $newentry->enable = $visible;
  5335. if (!$DB->update_record("iassign_ilm", $newentry))
  5336. error(get_string('error_edit_ilm', 'iassign'));
  5337. }
  5338. /// Function for confirm change default iLM
  5339. // @param int $ilm_id Id of iLM
  5340. // @param int $ilm_parent Id of parent iLM
  5341. // @return string Return with an string for create default page confirmation
  5342. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  5343. global $OUTPUT, $DB;
  5344. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5345. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5346. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5347. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  5348. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  5349. return $return;
  5350. }
  5351. /// Function for change the default iLM
  5352. // @see settings_ilm.php
  5353. // @param int $ilm_id Id of iLM
  5354. // @return int Return Id of default iLM
  5355. static function default_ilm ($ilm_id) {
  5356. global $DB;
  5357. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  5358. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  5359. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  5360. $iassign_ilm_default->id = $iassign_ilm->id;
  5361. $iassign_ilm_default->parent = 0;
  5362. $iassign_ilm->parent = $iassign_ilm_default->id;
  5363. $iassign_ilm->id = 0;
  5364. $iassign_ilm_default->enable = 1;
  5365. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  5366. print_error('error_edit_ilm', 'iassign');
  5367. }
  5368. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  5369. if (!$inserted) {
  5370. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  5371. print_error($msg_error);
  5372. //xx print_error('error_add_ilm', 'iassign');
  5373. }
  5374. return $iassign_ilm_default->id;
  5375. } // static function default_ilm ($ilm_id)
  5376. /// Function for confirm delete iLM
  5377. // @param int $ilm_id Id of iLM
  5378. // @param int $ilm_parent Id of parent iLM
  5379. // @return string Return with an string for create delete page confirmation
  5380. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  5381. global $OUTPUT, $DB;
  5382. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5383. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  5384. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  5385. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  5386. }
  5387. /// Function for delete directory where the iLM is allocated.
  5388. // @param string $dirPath
  5389. // @throws InvalidArgumentException
  5390. public static function delete_dir ($dirPath) {
  5391. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  5392. $dirPath .= '/';
  5393. }
  5394. $files = glob($dirPath . '*', GLOB_MARK);
  5395. foreach ($files as $file) {
  5396. if (is_dir($file)) {
  5397. ilm_settings::delete_dir($file);
  5398. } else {
  5399. unlink($file);
  5400. }
  5401. }
  5402. rmdir($dirPath);
  5403. }
  5404. /// Function for delete iLM
  5405. // @param int $ilm_id Id of iLM
  5406. // @return int Return Id of parent iLM
  5407. static function delete_ilm ($ilm_id) {
  5408. global $DB;
  5409. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5410. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5411. $typec = strtolower($iassign_ilm->type);
  5412. require_once 'ilm_handlers/' . $typec . '.php';
  5413. $retorno = $typec::delete_ilm($ilm_id);
  5414. return $retorno;
  5415. }
  5416. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  5417. // @param int $ilm_id Id of iLM
  5418. static function export_ilm ($ilm_id) {
  5419. global $DB;
  5420. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5421. if (!$iassign_ilm) return; // security debug...
  5422. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  5423. $typec = strtolower($iassign_ilm->type);
  5424. if (!$typec) $typec = "html5"; // security debug...
  5425. require_once 'ilm_handlers/' . $typec . '.php';
  5426. $typec::export_ilm($ilm_id);
  5427. } // static function export_ilm($ilm_id)
  5428. //TODO iLM_HTML5 :: //MOOC 2016
  5429. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  5430. // @param int $ilm_id Id of iLM
  5431. static function export_update_ilm ($ilm_id) {
  5432. global $DB, $CFG;
  5433. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5434. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  5435. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  5436. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  5437. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  5438. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  5439. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  5440. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  5441. $upgrade_descriptor .= '</upgrade>' . "\n";
  5442. file_put_contents($xml_filename, $upgrade_descriptor);
  5443. header("Pragma: public");
  5444. header("Expires: 0");
  5445. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5446. header("Cache-Control: private", false);
  5447. header('Content-Type: application/xml; charset=utf-8');
  5448. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  5449. header("Content-Length: " . @filesize($xml_filename));
  5450. set_time_limit(0);
  5451. @readfile("$xml_filename") || die("File not found.");
  5452. unlink($xml_filename);
  5453. exit;
  5454. } // static function export_update_ilm($ilm_id) //MOOC 2016
  5455. /// Function for save iLM from XML descriptor
  5456. // @param array $application_xml Data of XML descriptor
  5457. // @param array $files_extract Filenames of extract files
  5458. // @return array Return an array content id of JAR files
  5459. static function save_ilm_by_xml ($application_xml, $files_extract) {
  5460. global $CFG, $USER;
  5461. // Tratamento diferenciado se for do tipo HTML5:
  5462. $source = "";
  5463. $diretorio = "";
  5464. if (strtolower($application_xml->type) == 'html5') {
  5465. $i = 0;
  5466. foreach ($files_extract as $key => $value) {
  5467. $file = $CFG->dataroot . '/temp/' . $key;
  5468. // Verifica se já existe a pasta no diretório dos iLM:
  5469. if ($i == 0) {
  5470. $source = $file;
  5471. if (file_exists("ilm/" . basename($file))) {
  5472. $j = 1;
  5473. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  5474. $j ++;
  5475. }
  5476. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  5477. // mkdir($diretorio, 0777, true);
  5478. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  5479. }
  5480. else {
  5481. $diretorio = 'ilm/' . basename($file);
  5482. // mkdir($diretorio, 0777, true);
  5483. mkdir($diretorio, 0755, true);
  5484. }
  5485. break;
  5486. }
  5487. $i ++;
  5488. }
  5489. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  5490. if ($item->isDir()) {
  5491. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5492. }
  5493. else {
  5494. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5495. }
  5496. }
  5497. ilm_settings::delete_dir($source);
  5498. return "./" . $diretorio;
  5499. }
  5500. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5501. $file_jar = array();
  5502. $files_ilm = explode(",", $application_xml->file_jar);
  5503. $contextsystem = context_system::instance();
  5504. foreach ($files_ilm as $value) {
  5505. $file_ilm = array(
  5506. 'userid' => $USER->id,
  5507. 'contextid' => $contextsystem->id,
  5508. 'component' => 'mod_iassign',
  5509. 'filearea' => 'ilm',
  5510. 'itemid' => rand(1, 999999999),
  5511. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5512. 'filename' => $value);
  5513. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5514. array_push($file_jar, $file_ilm->get_id());
  5515. }
  5516. foreach ($files_extract as $key => $value) {
  5517. $file = $CFG->dataroot . '/temp/' . $key;
  5518. if (file_exists($file))
  5519. unlink($file);
  5520. }
  5521. return $file_jar;
  5522. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5523. /// Function for import the iLM from an package
  5524. // @param int $itemid Itemid of zip file
  5525. static function import_ilm ($itemid) {
  5526. global $CFG, $USER, $OUTPUT;
  5527. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5528. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5529. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5530. }
  5531. $pathtemp = $CFG->dataroot . '/temp/';
  5532. $contextuser = context_user::instance($USER->id);
  5533. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5534. $zip = new zip_packer();
  5535. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5536. foreach ($files as $file) {
  5537. if (!$file->is_directory())
  5538. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5539. }
  5540. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5541. // Verifica se o pacote possui o XML
  5542. if (!$application_xml) {
  5543. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5544. return;
  5545. } else {
  5546. $missing = "";
  5547. if (!isset($application_xml->name)) {
  5548. $missing .= "name";
  5549. }
  5550. if (!isset($application_xml->version)) {
  5551. $missing .= ", version";
  5552. }
  5553. if (!isset($application_xml->type)) {
  5554. $missing .= ", type";
  5555. }
  5556. if (!isset($application_xml->extension)) {
  5557. $missing .= ", extension";
  5558. }
  5559. if (!isset($application_xml->file_jar)) {
  5560. $missing .= ", file_jar";
  5561. }
  5562. if (!isset($application_xml->file_class)) {
  5563. $missing .= ", file_class";
  5564. }
  5565. if (!isset($application_xml->width)) {
  5566. $missing .= ", width";
  5567. }
  5568. if (!isset($application_xml->height)) {
  5569. $missing .= ", height";
  5570. }
  5571. if (!isset($application_xml->evaluate)) {
  5572. $missing .= ", evaluate";
  5573. }
  5574. if (strlen($missing) > 2) {
  5575. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5576. return;
  5577. }
  5578. }
  5579. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5580. $typec = strtolower($application_xml->type);
  5581. require_once 'ilm_handlers/' . $typec . '.php';
  5582. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5583. } // static function import_ilm($itemid)
  5584. /// Function for list iLM defaults
  5585. // @return string Return an string with a table of iLM
  5586. static function list_ilm () {
  5587. global $DB, $OUTPUT;
  5588. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5589. $str = '';
  5590. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5591. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5592. if ($iassign_ilm) {
  5593. foreach ($iassign_ilm as $ilm) {
  5594. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5595. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5596. $str .= '<tr><td>';
  5597. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5598. $str .= '<tr>';
  5599. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5600. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5601. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5602. $str .= '</tr>';
  5603. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5604. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5605. $str .= '</table>';
  5606. $str .= '</td></tr>';
  5607. }
  5608. }
  5609. $str .= '</table>';
  5610. return $str;
  5611. }
  5612. /// Function for download and install an upgrade of an iLM
  5613. // @param int $ilm_id Id of iLM
  5614. static function upgrade_ilm ($ilm_id) {
  5615. global $DB, $CFG, $USER;
  5616. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5617. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5618. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5619. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5620. if (!$result)
  5621. print_error('error_upgrade_ilm', 'iassign');
  5622. else {
  5623. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5624. $extension = explode(".", $zip_filename);
  5625. if ($extension[count($extension) - 1] != 'ipz') {
  5626. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5627. die;
  5628. }
  5629. $zip = new zip_packer();
  5630. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5631. $contextuser = context_user::instance($USER->id);
  5632. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5633. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5634. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5635. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5636. if (file_exists($zip_filename))
  5637. unlink($zip_filename);
  5638. if (empty($file_jar)) {
  5639. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5640. print_error($msg_error);
  5641. //xx print_error('error_add_ilm', 'iassign');
  5642. }
  5643. else {
  5644. $newentry = new stdClass();
  5645. $newentry->name = (String) $application_xml->name;
  5646. $newentry->version = (String) $application_xml->version;
  5647. $newentry->url = (String) $application_xml->url;
  5648. $newentry->description = $description_str;
  5649. $newentry->extension = strtolower((String) $application_xml->extension);
  5650. $newentry->file_jar = implode(",", $file_jar);
  5651. $newentry->file_class = (String) $application_xml->file_class;
  5652. $newentry->width = (String) $application_xml->width;
  5653. $newentry->height = (String) $application_xml->height;
  5654. $newentry->enable = 0;
  5655. $newentry->timemodified = time();
  5656. $newentry->author = $USER->id;
  5657. $newentry->timecreated = time();
  5658. $newentry->evaluate = (String) $application_xml->evaluate;
  5659. $newentry->parent = $ilm_id;
  5660. }
  5661. }
  5662. return $iassign_ilm->id;
  5663. } // static function upgrade_ilm($ilm_id)
  5664. //MOOC2014 -- inicio
  5665. //TODO: REVIEW
  5666. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5667. // static function move_iassign($ilm_id)
  5668. //MOOC2014 -- final
  5669. /// Function for list iLM versions with all informations
  5670. // @return string Return an string with a table of iLM
  5671. static function view_ilm ($ilmid, $from) {
  5672. global $DB;
  5673. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5674. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5675. $typec = strtolower($iassign_ilm->type);
  5676. require_once 'ilm_handlers/' . $typec . '.php';
  5677. $retorno = $typec::view_ilm($ilmid, $from);
  5678. return $retorno;
  5679. }
  5680. /// Function for get form variables for add, edit, or copy iLM params
  5681. // @param int $ilm_param_id Id of iLM param
  5682. // @param string $action String with the action
  5683. // @return object Return an object with forms variables
  5684. static function add_edit_copy_param ($ilm_param_id, $action) {
  5685. global $DB;
  5686. require_once('params_form.php');
  5687. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5688. $param = new stdClass();
  5689. $param->action = $action;
  5690. $param->ilm_param_id = $ilm_param_id;
  5691. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5692. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5693. $type = $iassign_ilm_config->param_type;
  5694. if ($action == 'add') {
  5695. $param->title = get_string('add_ilm', 'iassign');
  5696. $param->iassign_ilmid = $ilm_param_id;
  5697. $param->param_name = "";
  5698. $param->param_value = "";
  5699. $param->description = "";
  5700. $param->visible = 1;
  5701. }
  5702. elseif ($action == 'edit') {
  5703. if ($iassign_ilm_config) {
  5704. $param->title = get_string('edit_ilm', 'iassign');
  5705. $param->id = $iassign_ilm_config->id;
  5706. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5707. $param->param_type = $type; //MOOC2014
  5708. $param->param_name = $iassign_ilm_config->param_name;
  5709. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5710. $param->param_value = $iassign_ilm_config->param_value;
  5711. else //MOOC2014
  5712. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5713. $param->param_value = $iassign_ilm_config->param_value;
  5714. $param->description = $iassign_ilm_config->description;
  5715. $param->visible = $iassign_ilm_config->visible;
  5716. }
  5717. }
  5718. elseif ($action == 'copy') {
  5719. if ($iassign_ilm_config) {
  5720. $param->title = get_string('copy_ilm', 'iassign');
  5721. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5722. $param->param_type = $type; //MOOC2014
  5723. $param->param_name = $iassign_ilm_config->param_name;
  5724. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5725. $param->param_value = $iassign_ilm_config->param_value;
  5726. else //MOOC2014
  5727. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5728. $param->description = $iassign_ilm_config->description;
  5729. $param->visible = $iassign_ilm_config->visible;
  5730. }
  5731. }
  5732. return $param;
  5733. } // static function add_edit_copy_param($ilm_param_id, $action)
  5734. /// Function for change visibility of iLM param
  5735. // @param int $ilm_param_id Id of iLM param
  5736. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5737. static function visible_param ($ilm_param_id, $status) {
  5738. global $DB, $CFG;
  5739. if ($status == 0)
  5740. $visible = 1;
  5741. else
  5742. $visible = 0;
  5743. $newentry = new stdClass();
  5744. $newentry->id = $ilm_param_id;
  5745. $newentry->visible = $visible;
  5746. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5747. error(get_string('error_edit_param', 'iassign'));
  5748. }
  5749. /// Function for save in database an new iLM param
  5750. // @param object $param An object with iLM params
  5751. static function add_param ($param) {
  5752. global $DB;
  5753. $newentry = new stdClass();
  5754. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5755. //MOOC2014 $newentry->param_name = $param->param_name;
  5756. $newentry->param_type = $param->param_type; //MOOC2014
  5757. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5758. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5759. $newentry->param_value = $param->param_value;
  5760. else //MOOC2014
  5761. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5762. $newentry->description = $param->description;
  5763. $newentry->visible = $param->visible;
  5764. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5765. if (!$newentry->id) {
  5766. print_error('error_add_param', 'iassign');
  5767. }
  5768. }
  5769. /// Function for save in database a iLM param edit
  5770. // @param object $param An object with iLM params
  5771. static function edit_param ($param) {
  5772. global $DB;
  5773. $updentry = new stdClass();
  5774. $updentry->id = $param->id;
  5775. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5776. $updentry->param_type = $param->param_type; //MOOC2014
  5777. // $updentry->param_name = $param->param_name;
  5778. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5779. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5780. $updentry->param_value = $param->param_value;
  5781. else //MOOC2014
  5782. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5783. $updentry->description = $param->description;
  5784. $updentry->visible = $param->visible;
  5785. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5786. error(get_string('error_edit_param', 'iassign'));
  5787. }
  5788. }
  5789. /// Function for save in database a iLM param copy
  5790. // @param object $param An object with iLM params
  5791. static function copy_param ($param) {
  5792. global $DB;
  5793. $newentry = new stdClass();
  5794. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5795. //$newentry->param_name = $param->param_name;
  5796. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5797. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5798. $newentry->param_value = $param->param_value;
  5799. else //MOOC2014
  5800. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5801. $newentry->description = $param->description;
  5802. $newentry->visible = $param->visible;
  5803. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5804. if (!$newentry->id) {
  5805. print_error('error_add_param', 'iassign');
  5806. }
  5807. }
  5808. /// Function for delete iLM param of database
  5809. // @param int $param_id Id of iLM param
  5810. static function delete_param ($param_id) {
  5811. global $DB;
  5812. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5813. print_error('error_delete_param', 'iassign');
  5814. }
  5815. }
  5816. } // class ilm_settings
  5817. /// Class for manage iLM files (editor).
  5818. class ilm_manager {
  5819. var $id; // course id
  5820. var $url;
  5821. var $from;
  5822. /// Constructor for the base ilm_manager class
  5823. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5824. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5825. function __construct ($id, $url, $from) {
  5826. $this->id = $id; // course id
  5827. $this->url = $url;
  5828. $this->from = $from;
  5829. }
  5830. /// Function to get iAssign content file in Moodle data (exercise)
  5831. // @calledby x function preview_ilm($iassign_ilm) :
  5832. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5833. function get_file_ilm () {
  5834. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5835. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5836. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5837. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5838. $md_file = $fs->get_file_by_id($fileid);
  5839. $ilm_content_file = $md_file->get_content();
  5840. return $ilm_content_file;
  5841. }
  5842. /// Function for creating a new file from the iLM online editor
  5843. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5844. function ilm_editor_new () {
  5845. global $CFG, $DB, $OUTPUT, $PAGE;
  5846. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5847. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5848. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5849. $context = context_course::instance($this->id);
  5850. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5851. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5852. if (!$iassign) {
  5853. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5854. die();
  5855. }
  5856. $temp = explode(",", $iassign->extension);
  5857. $extension = $temp[0]; // default extension for this iLM
  5858. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5859. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5860. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5861. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5862. if ($stringArchiveContent != NULL) {
  5863. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5864. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5865. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5866. $filename = optional_param('filename', NULL, PARAM_RAW);
  5867. //Leo $filename = iassign_utils::format_filename($filename); //
  5868. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5869. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5870. //2019/02 $arrayfilename = explode(".", $filename);
  5871. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5872. //2019/02 $count_dots = count($arrayfilename);
  5873. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5874. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5875. //2019/02 if ($last_name != $extension)
  5876. //2019/02 $filename = $filename . '.' . $extension;
  5877. //2019/02 }
  5878. //2019/02 else { // no extension...
  5879. //2019/02 $filename = $filename . '.' . $extension;
  5880. //2019/02 }
  5881. // Store the name of recent created file
  5882. $_SESSION['file_name'] = $filename;
  5883. //$this->write_file_iassign($string, $filename);
  5884. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5885. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5886. die();
  5887. }
  5888. else { // if ($stringArchiveContent != NULL)
  5889. // iLM On-line editor
  5890. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5891. $str_get_iLM = "window.frames.iLM";
  5892. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5893. }
  5894. else { // otherwise it is JAR named 'iLM'
  5895. $str_get_iLM = "document.iLM";
  5896. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5897. }
  5898. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5899. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5900. $files_array = '';
  5901. foreach ($files as $value) {
  5902. if ($value->get_filename() != ".")
  5903. $files_array .= "'" . $value->get_filename() . "',";
  5904. }
  5905. $files_array .= "''";
  5906. $file = null;
  5907. $ia_content = "";
  5908. $filename = "";
  5909. $error_files_exists = get_string('error_file_exists', 'iassign');
  5910. $output = "<script type='text/javascript'>
  5911. //<![CDATA[
  5912. //D alert('locallib.php: ilm_editor_new');
  5913. function submit_iLM_Answer () {
  5914. var docFormOnLineEditor = document.formEnvio;
  5915. var resposta_exerc = new Array(3);
  5916. var valor_resposta = new Array(3);
  5917. var sessao = new Array(3);
  5918. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5919. resposta_exerc[0] = doc_iLM.getAnswer();
  5920. valor_resposta[0] = doc_iLM.getEvaluation();
  5921. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5922. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5923. var files = new Array(" . $files_array . ");
  5924. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5925. if (docFormOnLineEditor.filename.value=='') {
  5926. // ERROR: the file name is empty
  5927. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5928. return false;
  5929. }
  5930. // }
  5931. for (i=0; i<files.length; i++) {
  5932. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5933. alert('" . $error_files_exists . "');
  5934. return false;
  5935. }
  5936. }
  5937. docFormOnLineEditor.submit();
  5938. return true;
  5939. }
  5940. //]]>
  5941. </script>\n";
  5942. $output .= "
  5943. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5944. $output .= $OUTPUT->box_start();
  5945. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5946. $output .= "
  5947. <table width='100%' cellpadding='20'>
  5948. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5949. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5950. </tr>
  5951. </table>\n";
  5952. $output .= $OUTPUT->box_end();
  5953. $output .= "<center>\n";
  5954. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5955. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5956. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5957. $output .= $output_ilm;
  5958. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5959. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5960. </center>
  5961. </form>\n";
  5962. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5963. $PAGE->navbar->add($title);
  5964. $PAGE->set_title($title);
  5965. $PAGE->set_heading($title); // insert title above the navigation bar
  5966. print $OUTPUT->header();
  5967. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5968. print $output;
  5969. print $OUTPUT->footer();
  5970. }
  5971. die();
  5972. } // function ilm_editor_new()
  5973. /// Function for editing an file in online editor
  5974. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5975. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5976. global $CFG, $DB, $OUTPUT, $PAGE;
  5977. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5978. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5979. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5980. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5981. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5982. // If iLM is not registered, error!
  5983. if (!$iassign) {
  5984. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5985. die;
  5986. }
  5987. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5988. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5989. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5990. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5991. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5992. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5993. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5994. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5995. if ($stringArchiveContent != NULL) {
  5996. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5997. die();
  5998. } else { // if ($stringArchiveContent != NULL)
  5999. $end_file = '';
  6000. if ($content_file) {
  6001. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  6002. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  6003. }
  6004. $temp = explode(",", $iassign->extension);
  6005. $extension = $temp[0]; // default extension for this iLM
  6006. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  6007. $str_get_iLM = "window.frames.iLM";
  6008. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  6009. } else { // otherwise it is JAR named 'iLM'
  6010. $str_get_iLM = "document.iLM";
  6011. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  6012. }
  6013. $output = "<script type='text/javascript'>
  6014. //<![CDATA[
  6015. function submit_iLM_Answer () {
  6016. var docFormEditor = document.formEnvio;
  6017. var activityAnswer; // to get activity answer (text)
  6018. var activityValue; // to get activity answer value (float)
  6019. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  6020. //activityAnswer = doc_iLM.getAnswer();
  6021. //activityValue = doc_iLM.getEvaluation();
  6022. activityAnswer = " . $str_get_iLM . ".getAnswer();
  6023. activityValue = " . $str_get_iLM . ".getEvaluation();
  6024. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  6025. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  6026. docFormEditor.submit();
  6027. return true;
  6028. }
  6029. //]]>
  6030. </script>\n";
  6031. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  6032. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  6033. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  6034. // return true;
  6035. // }
  6036. $output .= "
  6037. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  6038. $output .= $OUTPUT->box_start();
  6039. $output .= "
  6040. <table width='100%' cellpadding='20'>
  6041. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  6042. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  6043. <input type='hidden' name='filename' value='$filename'/></td>
  6044. <td>
  6045. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  6046. </tr>
  6047. </table>\n";
  6048. $output .= $OUTPUT->box_end();
  6049. $output .= " <center>\n";
  6050. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  6051. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  6052. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  6053. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  6054. </center>
  6055. </form>\n";
  6056. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  6057. $PAGE->navbar->add($title);
  6058. $PAGE->set_title($title);
  6059. $PAGE->set_heading($title); // insert title above the navigation bar
  6060. print $OUTPUT->header();
  6061. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  6062. print $output;
  6063. print $OUTPUT->footer();
  6064. } // else if ($stringArchiveContent != NULL)
  6065. die();
  6066. } // function ilm_editor_update()
  6067. /// Function for write iAssign file in Moodle data (exercise)
  6068. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  6069. // @param string $stringArchiveContent Content of iassign file
  6070. // @param string $filename Filename of iassign file
  6071. function write_file_iassign ($stringArchiveContent, $filename) {
  6072. global $USER;
  6073. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6074. $context = context_course::instance($this->id);
  6075. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6076. $dirid = $this->get_dir_ilm('dirid');
  6077. $dir = $fs->get_file_by_id($dirid);
  6078. $fileinfo = array('contextid' => $context->id, // ID of course
  6079. 'component' => 'mod_iassign', // usually = table name
  6080. 'filearea' => 'activity', // usually = table name
  6081. 'itemid' => 0, // usually = ID of row in table
  6082. 'filepath' => '/', // any path beginning and ending whith '/'
  6083. 'userid' => $USER->id,
  6084. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6085. 'filename' => $filename); // any filename
  6086. // Create file containing text. '$stringArchiveContent'
  6087. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6088. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  6089. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  6090. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  6091. // 'Activité interactive enregistrée avec succès sous le nom:';
  6092. // 'Atividade interativa gravada com sucesso sob o nome:'
  6093. $output = "
  6094. <script type='text/javascript'>
  6095. //<![CDATA[
  6096. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  6097. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6098. //]]>
  6099. </script>";
  6100. print $output;
  6101. die();
  6102. }
  6103. /// Function for write iAssign file in Moodle data (exercise)
  6104. // @param string $stringArchiveContent Content of iassign file
  6105. // @param string $filename Filename of iassign file
  6106. // @param int $itemid Itemid of iassign file
  6107. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  6108. global $OUTPUT, $USER;
  6109. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6110. $context = context_course::instance($this->id);
  6111. $dirid = $this->get_dir_ilm('dirid');
  6112. if ($stringArchiveContent != (-1)) {
  6113. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6114. $file = $fs->get_file_by_id($fileid);
  6115. if (!$file) {
  6116. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  6117. die;
  6118. }
  6119. $fileinfo = array('contextid' => $context->id, // ID of context
  6120. 'component' => 'mod_iassign', // usually = table name
  6121. 'filearea' => 'activity', // usually = table name
  6122. 'itemid' => 0, // usually = ID of row in table
  6123. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  6124. 'userid' => $USER->id,
  6125. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6126. 'license' => 'allrightsreserved', // allrightsreserved
  6127. 'timecreated' => $file->get_timecreated(),
  6128. 'filename' => $file->get_filename()); // any filename
  6129. $file->delete();
  6130. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  6131. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  6132. }
  6133. $output = "<script type='text/javascript'>
  6134. //<![CDATA[
  6135. alert('" . get_string('sucess_update', 'iassign') . "');\n
  6136. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  6137. //]]>
  6138. </script>";
  6139. print $output;
  6140. die();
  6141. }
  6142. /// Function for create an tag for iAssign filter
  6143. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  6144. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6145. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  6146. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  6147. // @param int $fileid Id of file
  6148. // @return string Return an string with an tag of iassign filter
  6149. function tag_ilm ($fileid) {
  6150. global $DB;
  6151. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6152. $width = '600';
  6153. $height = '400';
  6154. $file = $fs->get_file_by_id($fileid);
  6155. $filetype = explode(".", $file->get_filename());
  6156. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  6157. foreach ($iassign_ilm as $value) {
  6158. $extensions = explode(",", $value->extension);
  6159. if (in_array($filetype[1], $extensions)) {
  6160. $width = $value->width;
  6161. $height = $value->height;
  6162. }
  6163. }
  6164. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  6165. }
  6166. /// Function for delete iAssign file in Moodle data (exercise)
  6167. function delete_file_ilm () {
  6168. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6169. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6170. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  6171. $file = $fs->get_file_by_id($fileid);
  6172. if ($file)
  6173. $file->delete();
  6174. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6175. die();
  6176. }
  6177. /// Function for delete selected iAssign file in Moodle data (exercise)
  6178. function delete_selected_ilm () {
  6179. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6180. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6181. $context = context_course::instance($this->id);
  6182. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6183. $dirid = $this->get_dir_ilm('dirid');
  6184. foreach ($files_id as $file_id) {
  6185. $file = $fs->get_file_by_id($file_id);
  6186. if ($file) {
  6187. if (!$file->is_directory())
  6188. $file->delete();
  6189. else {
  6190. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6191. foreach ($files_delete as $value)
  6192. $value->delete();
  6193. $file->delete();
  6194. }
  6195. }
  6196. }
  6197. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6198. die();
  6199. }
  6200. /// Function for duplicate iAssign file from "online" edition
  6201. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  6202. function duplicate_file_ilm () {
  6203. global $USER, $COURSE;
  6204. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6205. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6206. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6207. $filename = optional_param('filename', NULL, PARAM_RAW);
  6208. $file = $fs->get_file_by_id($fileid);
  6209. $context = context_course::instance($this->id);
  6210. $fileinfo = array(
  6211. 'contextid' => $context->id, // ID of context
  6212. 'component' => 'mod_iassign', // usually = table name
  6213. 'filearea' => 'activity', // usually = table name
  6214. 'itemid' => 0, // usually = ID of row in table
  6215. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  6216. 'userid' => $USER->id,
  6217. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  6218. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  6219. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  6220. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  6221. die();
  6222. }
  6223. /// Function for rename iAssign file
  6224. function rename_file_ilm () {
  6225. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6226. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6227. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6228. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6229. $file = $fs->get_file_by_id($fileid);
  6230. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  6231. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  6232. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6233. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  6234. die();
  6235. }
  6236. /// Function for get iassign file for iassign form
  6237. function add_ilm () {
  6238. $fileid = optional_param('fileid', NULL, PARAM_INT);
  6239. $filename = optional_param('filename', NULL, PARAM_TEXT);
  6240. $output = "
  6241. <script type='text/javascript'>
  6242. //<![CDATA[
  6243. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  6244. iassign_file_link.innerHTML = '$filename';
  6245. window.opener.document.forms['mform1'].file.value='$fileid';
  6246. window.opener.document.forms['mform1'].filename.value='$filename';
  6247. window.close();
  6248. //]]>
  6249. </script>";
  6250. print $output;
  6251. die();
  6252. }
  6253. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  6254. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  6255. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  6256. function preview_ilm ($courseid, $iassign_ilm) {
  6257. global $OUTPUT, $CFG, $USER;
  6258. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6259. $title = get_string('modulename', 'iassign'); // iAssign
  6260. print $OUTPUT->header();
  6261. print $OUTPUT->box_start();
  6262. $javascript = "
  6263. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  6264. <script type='text/javascript'>
  6265. //<![CDATA[
  6266. function submit_close () {
  6267. window.opener.location.reload();
  6268. window.close();
  6269. }
  6270. //]]>
  6271. </script>\n";
  6272. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  6273. // to the complete "applet" tag
  6274. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  6275. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  6276. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  6277. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  6278. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  6279. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  6280. if ($ilm_name != "ivprog") {
  6281. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  6282. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  6283. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  6284. } else {
  6285. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  6286. $content_or_id_from_ilm_security = $this->get_file_ilm();
  6287. $timecreated = time();
  6288. $token = md5($timecreated);
  6289. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  6290. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  6291. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  6292. $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)
  6293. }
  6294. $html = "
  6295. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6296. <table border='1'>
  6297. <tr><td>
  6298. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  6299. <!-- iLM calls : end -->
  6300. </td></tr>
  6301. </table>
  6302. <table>
  6303. <tr>
  6304. <td align='center'>
  6305. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  6306. </td></tr>
  6307. </table>
  6308. </form>\n";
  6309. print $javascript . $html;
  6310. print $OUTPUT->box_end();
  6311. //NAO echo format_string($html); // Moodle 3.X
  6312. die();
  6313. } // function preview_ilm($courseid, $iassign_ilm)
  6314. //r_ function preview_ilm ($iassign_ilm)
  6315. //r_ /// Function for preview iassign file from iassign filter.
  6316. //r_ function preview_ilm() {
  6317. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  6318. //r_ $tag_filter = $this->tag_ilm($fileid);
  6319. //r_ $javascript = "<script type='text/javascript'>
  6320. //r_ //<![CDATA[
  6321. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  6322. //r_ //]]>
  6323. //r_ </script>";
  6324. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  6325. //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>
  6326. //r_ </table></form></body></html>";
  6327. //r_ echo $javascript . format_text($html);
  6328. //r_ die;
  6329. //r_ }
  6330. /// Function for export an package (zip) of iassign files
  6331. function export_files_ilm () {
  6332. global $CFG;
  6333. $context = context_course::instance($this->id);
  6334. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6335. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  6336. $zip = new zip_archive();
  6337. $zip->open($zip_filename);
  6338. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6339. foreach ($files_id as $file_id) {
  6340. $file = $fs->get_file_by_id($file_id);
  6341. if (!$file->is_directory())
  6342. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  6343. else {
  6344. $zip->add_directory($file->get_filepath());
  6345. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6346. foreach ($files_zip as $value) {
  6347. if (!$value->is_directory())
  6348. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  6349. else
  6350. $zip->add_directory($value->get_filepath());
  6351. }
  6352. }
  6353. }
  6354. $zip->close();
  6355. header("Pragma: public");
  6356. header("Expires: 0");
  6357. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6358. header("Cache-Control: private", false);
  6359. header("Content-Type: application/zip");
  6360. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6361. header("Content-Transfer-Encoding: binary");
  6362. header("Content-Length: " . @filesize($zip_filename));
  6363. set_time_limit(0);
  6364. @readfile("$zip_filename") || die("File not found.");
  6365. unlink($zip_filename);
  6366. exit;
  6367. }
  6368. /// Function of execute a command in button editor tinymce
  6369. // @param int $fileid Id of file
  6370. function tinymce_ilm ($fileid) {
  6371. $tag_filter = $this->tag_ilm($fileid);
  6372. $output = "<script type='text/javascript'>
  6373. //<![CDATA[
  6374. var tag_filter = '$tag_filter';
  6375. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  6376. // all right, insert it
  6377. } else {
  6378. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  6379. }
  6380. // window.close();
  6381. //]]>
  6382. </script>\n";
  6383. print $output;
  6384. die();
  6385. }
  6386. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  6387. /// Function to add content to the Editor Window
  6388. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6389. // @param int $fileid Id of file
  6390. function editor_ilm ($fileid, $editor) {
  6391. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  6392. $output1 = "<script type='text/javascript'>
  6393. //<![CDATA[
  6394. var tag_filter = '$tag_filter';\n";
  6395. if ($editor == 'atto') {
  6396. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  6397. } elseif ($editor == 'tinyMCE') {
  6398. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  6399. } else
  6400. $output2 = "";
  6401. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  6402. window.close();
  6403. //]]>
  6404. </script>\n";
  6405. //D var_dump($output);
  6406. print $output1 . $output2 . $output3;
  6407. die();
  6408. }
  6409. /// Function to add content to the Atto Editor Window
  6410. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  6411. // @param int $fileid Id of file
  6412. function atto_ilm ($fileid) {
  6413. global $CFG, $DB;
  6414. $tag_filter = $this->tag_ilm($fileid);
  6415. $output = "<script type='text/javascript'>
  6416. //<![CDATA[
  6417. var tag_filter = '$tag_filter';
  6418. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  6419. // all right, insert iLM tag to this editor
  6420. } else {
  6421. // error trying to insert
  6422. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  6423. }
  6424. //window.close();
  6425. //]]>
  6426. </script>\n";
  6427. print $output;
  6428. die();
  6429. }
  6430. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  6431. // @param string $key Key for return information
  6432. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  6433. function get_dir_ilm ($key) {
  6434. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6435. $context = context_course::instance($this->id);
  6436. $dirid = optional_param('dirid', 0, PARAM_INT);
  6437. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  6438. if ($dirid == 0) {
  6439. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  6440. $dirid = $dir->get_id();
  6441. }
  6442. else {
  6443. $dir = $fs->get_file_by_id($dirid);
  6444. $dir_base = $dir->get_filepath();
  6445. }
  6446. $dir_parent = $dir->get_parent_directory();
  6447. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  6448. return $data[$key];
  6449. }
  6450. /// Function for create an new dir
  6451. function new_dir_ilm () {
  6452. global $USER;
  6453. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6454. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6455. $dir_base = $this->get_dir_ilm('dir_base');
  6456. $context = context_course::instance($this->id);
  6457. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6458. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  6459. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  6460. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  6461. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  6462. }
  6463. /// Function for delete an dir
  6464. function delete_dir_ilm () { //
  6465. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6466. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6467. $context = context_course::instance($this->id);
  6468. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6469. $dir_parent = $this->get_dir_ilm('dir_parent');
  6470. if ($dir) {
  6471. if ($dir->is_directory()) {
  6472. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6473. foreach ($files_delete as $value)
  6474. $value->delete();
  6475. $dir->delete();
  6476. }
  6477. }
  6478. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6479. die();
  6480. }
  6481. /// Function for rename an dir
  6482. function rename_dir_ilm () {
  6483. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6484. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6485. $context = context_course::instance($this->id);
  6486. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  6487. $dir_parent = $this->get_dir_ilm('dir_parent');
  6488. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  6489. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  6490. if ($dir->is_directory()) {
  6491. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6492. foreach ($files_rename_path as $value)
  6493. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6494. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6495. }
  6496. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6497. die();
  6498. }
  6499. /// Function for move an dir and your content for other dir
  6500. function selected_move_ilm () {
  6501. global $PAGE, $OUTPUT, $CFG;
  6502. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6503. $context = context_course::instance($this->id);
  6504. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6505. $dirid = $this->get_dir_ilm('dirid');
  6506. $dir_base = $this->get_dir_ilm('dir_base');
  6507. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6508. $code_javascript_ilm = "
  6509. <script type='text/javascript'>
  6510. //<![CDATA[
  6511. function getRadiobutton () {
  6512. var radioButtons = document.getElementsByTagName('input');
  6513. var param = '';
  6514. for (var counter=0; counter < radioButtons.length; counter++) {
  6515. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6516. param = radioButtons[counter].value;
  6517. }
  6518. return param;
  6519. }
  6520. function move_selected_ilm () {
  6521. var msgAnswer;
  6522. if (getRadiobutton() != '') {
  6523. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6524. if (msgAnswer)
  6525. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6526. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6527. }
  6528. else
  6529. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6530. }
  6531. function cancel_selected_ilm () {
  6532. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6533. }
  6534. //]]>
  6535. </script>\n";
  6536. $title = get_string('move_files', 'iassign');
  6537. $PAGE->set_title($title);
  6538. $PAGE->set_pagelayout('base');
  6539. print $OUTPUT->header();
  6540. print $OUTPUT->heading($title);
  6541. $dir_paths = array();
  6542. print $OUTPUT->box_start();
  6543. print "<center>";
  6544. foreach ($files_id as $file_id) {
  6545. $file = $fs->get_file_by_id($file_id);
  6546. if ($file) {
  6547. if (!$file->is_directory())
  6548. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6549. else {
  6550. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6551. array_push($dir_paths, $file->get_filepath());
  6552. }
  6553. }
  6554. }
  6555. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6556. if ($dir_base != '/') {
  6557. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6558. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6559. }
  6560. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6561. foreach ($files_tree as $file) {
  6562. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6563. $is_parent = false;
  6564. foreach ($dir_paths as $dir) {
  6565. $path = explode("/", $dir);
  6566. array_pop($path);
  6567. $path[count($path) - 1] = '';
  6568. $path = implode("/", $path);
  6569. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6570. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6571. }
  6572. if ($is_parent == false) {
  6573. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6574. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6575. }
  6576. }
  6577. }
  6578. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6579. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6580. print "</center>";
  6581. print $OUTPUT->box_end();
  6582. print $OUTPUT->footer();
  6583. print $code_javascript_ilm;
  6584. die;
  6585. }
  6586. /// Function for move files for an dir
  6587. function move_files_ilm () {
  6588. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6589. $context = context_course::instance($this->id);
  6590. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6591. $dirid = $this->get_dir_ilm('dirid');
  6592. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6593. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6594. foreach ($files_id as $file_id) {
  6595. $file = $fs->get_file_by_id($file_id);
  6596. if ($file) {
  6597. if ($file->is_directory()) {
  6598. $pathname = explode("/", $file->get_filepath());
  6599. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6600. foreach ($files_move_path as $value) {
  6601. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6602. $value->rename($path_move, $value->get_filename());
  6603. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6604. }
  6605. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6606. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6607. $file->rename($path_move, $file->get_filename());
  6608. } else {
  6609. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6610. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6611. }
  6612. }
  6613. }
  6614. //die;
  6615. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6616. die();
  6617. } // function move_files_ilm()
  6618. /// Function for recover files in use on all activities of a course
  6619. function recover_files_ilm () {
  6620. global $DB, $USER;
  6621. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6622. $courseid = optional_param('id', NULL, PARAM_INT);
  6623. $dirid = $this->get_dir_ilm('dirid');
  6624. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6625. $contextfile = context_course::instance($this->id);
  6626. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6627. foreach ($iassigns as $iassign) {
  6628. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6629. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6630. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6631. $context = context_module::instance($cm->id);
  6632. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->id);
  6633. if ($files) {
  6634. foreach ($files as $value) {
  6635. $extension = explode(".", $value->get_filename());
  6636. if (!$value->is_directory()) {
  6637. $fileinfo = array('contextid' => $contextfile->id,
  6638. 'component' => 'mod_iassign',
  6639. 'filearea' => 'activity',
  6640. 'itemid' => 0,
  6641. 'filepath' => $this->get_dir_ilm('dir_base'),
  6642. 'userid' => $USER->id,
  6643. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6644. 'license' => 'allrightsreserved',
  6645. 'timecreated' => time(),
  6646. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6647. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6648. }
  6649. }
  6650. } // if ($files)
  6651. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6652. } // foreach ($iassigns as $iassign)
  6653. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6654. die();
  6655. } // function recover_files_ilm()
  6656. /// Auxiliary function the get all files in a given context
  6657. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6658. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6659. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6660. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6661. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6662. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6663. // (NAO s_iassign_statement.file = s_files.id)
  6664. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6665. $dir_base = $this->get_dir_ilm('dir_base');
  6666. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6667. $countf = 0;
  6668. $array_files_id = array(); // all files from this context
  6669. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6670. //$filename = $item_fc->get_filename();
  6671. //$filepath = $item_fc->get_filepath();
  6672. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6673. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6674. // $array_files_aux[] = $item_fc;
  6675. $itemid = $item_fc->get_id();
  6676. if (!in_array($itemid, $array_files_id)) {
  6677. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6678. if ($fileuserid == $userid)
  6679. $filesfrommine[] = $item_fc;
  6680. else
  6681. $filesfromothers[] = $item_fc;
  6682. $array_files_id[] = $itemid;
  6683. $countf++;
  6684. }
  6685. }
  6686. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6687. return $countf;
  6688. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6689. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6690. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6691. function get_all_ilm_files_by_fileid ($fileid) {
  6692. global $DB, $USER;
  6693. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6694. //TODO Criar coluna 'authorid'
  6695. $str_query = "SELECT * FROM {iassign_statement} " .
  6696. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6697. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6698. return $array_iassign_ilm;
  6699. }
  6700. //NN
  6701. //NN
  6702. // Build string with JavaScript code with function to edit/remove/double iLM files
  6703. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6704. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6705. global $CFG;
  6706. $error_files_exists = get_string('error_file_exists', 'iassign');
  6707. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6708. $code_javascript_ilm = "
  6709. <script type='text/javascript'>
  6710. //<![CDATA[
  6711. function preview_ilm (fileid, ilmid) { //JavaScript function
  6712. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6713. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6714. }
  6715. function update_ilm (ilmid, fileid) { //JavaScript function
  6716. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6717. }
  6718. function delete_ilm (ilmid, fileid) { //JavaScript function
  6719. var msgAnswer;
  6720. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6721. if (msgAnswer) {
  6722. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6723. }
  6724. }
  6725. function delete_selected_ilm () { //JavaScript function
  6726. var msgAnswer;
  6727. var param = getCheckbox();
  6728. if (param.join() != '') {
  6729. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6730. if (msgAnswer)
  6731. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6732. }
  6733. else
  6734. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6735. }
  6736. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6737. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6738. }
  6739. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6740. var filenamecopy;
  6741. var i;
  6742. var files = new Array(" . $files_array . ");
  6743. do {
  6744. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6745. } while (filenamecopy == '');
  6746. if (filenamecopy == null)
  6747. return false;\n
  6748. else {
  6749. for (i=0;i<files.length;i++) {
  6750. if (files[i]==filenamecopy) {
  6751. alert('" . $error_files_exists . "');
  6752. return false;\n
  6753. }
  6754. }\n" .
  6755. // @see: function 'duplicate_file_ilm()' above
  6756. "
  6757. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6758. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6759. } // else
  6760. }
  6761. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6762. var filenamecopy;
  6763. var i;
  6764. var files = new Array($files_array);
  6765. do {
  6766. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6767. } while (filenamecopy == '');
  6768. if (filenamecopy == null)
  6769. return false;
  6770. else {
  6771. for (i=0;i<files.length;i++) {
  6772. if (files[i]==filenamecopy) {
  6773. alert('" . $error_files_exists . "');
  6774. return false;
  6775. }
  6776. }
  6777. 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;
  6778. }
  6779. }
  6780. function export_files_ilm () { //JavaScript function
  6781. var param = getCheckbox();
  6782. if (param.join() != '')
  6783. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6784. else
  6785. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6786. }
  6787. function select_all_ilm () { //JavaScript function
  6788. var checkBoxes = document.getElementsByTagName('input');
  6789. var selectAll = document.getElementById('select_all');
  6790. for (var counter=0; counter < checkBoxes.length; counter++) {
  6791. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6792. checkBoxes[counter].checked = selectAll.checked;
  6793. }
  6794. }
  6795. function getCheckbox () { //JavaScript function
  6796. var checkBoxes = document.getElementsByTagName('input');
  6797. var param = new Array();
  6798. for (var counter=0; counter < checkBoxes.length; counter++) {
  6799. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6800. param.push(checkBoxes[counter].value);
  6801. }
  6802. return param;
  6803. }
  6804. function new_dir_ilm () { //JavaScript function
  6805. var dirname = '';
  6806. var i;
  6807. var dirs = new Array(" . $dirs_array . ");
  6808. do {
  6809. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6810. } while (dirname == '');
  6811. if (dirname == null)
  6812. return false;\n
  6813. else {
  6814. for (i=0;i<dirs.length;i++) {
  6815. if (dirs[i]==dirname) {
  6816. alert('" . $error_dir_exists . "');
  6817. return false;\n
  6818. }
  6819. }
  6820. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6821. }
  6822. }
  6823. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6824. var msgAnswer;
  6825. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6826. if (msgAnswer) {
  6827. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6828. }
  6829. }
  6830. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6831. var dirnamecopy;
  6832. var i;
  6833. var dirs = new Array($dirs_array);
  6834. do {
  6835. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6836. } while (dirnamecopy == '');
  6837. if (dirnamecopy == null)
  6838. return false;\n
  6839. else {
  6840. for (i=0;i<dirs.length;i++) {
  6841. if (dirs[i]==dirnamecopy) {
  6842. alert('" . $error_dir_exists . "');
  6843. return false;\n
  6844. }
  6845. }
  6846. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6847. }
  6848. }
  6849. function move_selected_ilm (ilmid) { //JavaScript function
  6850. var param = getCheckbox();
  6851. if (param.join() != '')
  6852. 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();
  6853. else
  6854. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6855. }
  6856. function recover_files_ilm () { //JavaScript function
  6857. var msgAnswer;
  6858. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6859. if (msgAnswer) {
  6860. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6861. }
  6862. }
  6863. window.onload = function() { //JavaScript function
  6864. var xPosition = 0;
  6865. var yPosition = 0;
  6866. element=document.getElementById('new_file');
  6867. while(element) {
  6868. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6869. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6870. element = element.offsetParent;
  6871. }
  6872. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6873. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6874. location.hash = '#new_file';
  6875. };
  6876. //]]>
  6877. </script>\n"; // end of $code_javascript_ilm
  6878. return $code_javascript_ilm;
  6879. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6880. /// List iassign files from course directory
  6881. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6882. function view_files_ilm ($iassign_ilm_class, $extension) {
  6883. global $CFG, $DB, $USER, $OUTPUT;
  6884. $fs = get_file_storage();
  6885. $context = context_course::instance($this->id);
  6886. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6887. $dirid = $this->get_dir_ilm('dirid');
  6888. $dir_base = $this->get_dir_ilm('dir_base');
  6889. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6890. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6891. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6892. $files_array = '';
  6893. foreach ($files_course as $value) {
  6894. if (!$value->is_directory())
  6895. $files_array .= "'" . $value->get_filename() . "',";
  6896. }
  6897. $files_array .= "''";
  6898. $error_files_exists = get_string('error_file_exists', 'iassign');
  6899. $dirs_array = '';
  6900. foreach ($files_course as $value) {
  6901. if ($value->is_directory()) {
  6902. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6903. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6904. }
  6905. }
  6906. $dirs_array .= "''";
  6907. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6908. // TODO Rever o preview pois só deixar ver uma vez.
  6909. $code_javascript_ilm = "
  6910. <script type='text/javascript'>
  6911. //<![CDATA[
  6912. function preview_ilm (fileid, ilmid) {
  6913. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6914. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6915. }
  6916. function update_ilm (ilmid, fileid) {
  6917. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6918. }
  6919. function delete_ilm (ilmid, fileid) {
  6920. var msgAnswer;
  6921. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6922. if (msgAnswer) {
  6923. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6924. }
  6925. }
  6926. function delete_selected_ilm () {
  6927. var msgAnswer;
  6928. var param = getCheckbox();
  6929. if (param.join() != '') {
  6930. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6931. if (msgAnswer)
  6932. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6933. }
  6934. else
  6935. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6936. }
  6937. function add_ilm_iassign (ilmid, filename, fileid) {
  6938. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6939. }
  6940. function duplicate_ilm (ilmid, filename, fileid) {
  6941. var filenamecopy;
  6942. var i;
  6943. var files = new Array($files_array);
  6944. do {
  6945. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6946. } while (filenamecopy == '');
  6947. if (filenamecopy == null)
  6948. return false;\n
  6949. else {
  6950. for (i=0;i<files.length;i++) {
  6951. if (files[i]==filenamecopy) {
  6952. alert('$error_files_exists');
  6953. return false;\n
  6954. }
  6955. }\n" .
  6956. // @see: function 'duplicate_file_ilm()' above
  6957. "
  6958. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6959. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6960. } // else
  6961. }
  6962. function rename_ilm (ilmid, filename, fileid) {
  6963. var filenamecopy;
  6964. var i;
  6965. var files = new Array($files_array);
  6966. do {
  6967. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6968. } while (filenamecopy == '');
  6969. if (filenamecopy == null)
  6970. return false;
  6971. else {
  6972. for (i=0;i<files.length;i++) {
  6973. if (files[i]==filenamecopy) {
  6974. alert('$error_files_exists');
  6975. return false;
  6976. }
  6977. }
  6978. 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;
  6979. }
  6980. }
  6981. function export_files_ilm () {
  6982. var param = getCheckbox();
  6983. if (param.join() != '')
  6984. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6985. else
  6986. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6987. }
  6988. function select_all_ilm () {
  6989. var checkBoxes = document.getElementsByTagName('input');
  6990. var selectAll = document.getElementById('select_all');
  6991. for (var counter=0; counter < checkBoxes.length; counter++) {
  6992. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6993. checkBoxes[counter].checked = selectAll.checked;
  6994. }
  6995. }
  6996. function getCheckbox () {
  6997. var checkBoxes = document.getElementsByTagName('input');
  6998. var param = new Array();
  6999. for (var counter=0; counter < checkBoxes.length; counter++) {
  7000. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  7001. param.push(checkBoxes[counter].value);
  7002. }
  7003. return param;
  7004. }
  7005. function new_dir_ilm () {
  7006. var dirname = '';
  7007. var i;
  7008. var dirs = new Array($dirs_array);
  7009. do {
  7010. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  7011. } while (dirname == '');
  7012. if (dirname == null)
  7013. return false;\n
  7014. else {
  7015. for (i=0;i<dirs.length;i++) {
  7016. if (dirs[i]==dirname) {
  7017. alert('$error_dir_exists');
  7018. return false;\n
  7019. }
  7020. }
  7021. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  7022. }
  7023. }
  7024. function delete_dir_ilm (ilmid, dirid) {
  7025. var msgAnswer;
  7026. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  7027. if (msgAnswer) {
  7028. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  7029. }
  7030. }
  7031. function rename_dir_ilm (ilmid, dirname, dirid) {
  7032. var dirnamecopy;
  7033. var i;
  7034. var dirs = new Array($dirs_array);
  7035. do {
  7036. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  7037. } while (dirnamecopy == '');
  7038. if (dirnamecopy == null)
  7039. return false;\n
  7040. else {
  7041. for (i=0;i<dirs.length;i++) {
  7042. if (dirs[i]==dirnamecopy) {
  7043. alert('$error_dir_exists');
  7044. return false;\n
  7045. }
  7046. }
  7047. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  7048. }
  7049. }
  7050. function move_selected_ilm (ilmid) {
  7051. var param = getCheckbox();
  7052. if (param.join() != '')
  7053. 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();
  7054. else
  7055. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  7056. }
  7057. function recover_files_ilm () {
  7058. var msgAnswer;
  7059. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  7060. if (msgAnswer) {
  7061. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  7062. }
  7063. }
  7064. window.onload = function() {
  7065. var xPosition = 0;
  7066. var yPosition = 0;
  7067. element=document.getElementById('new_file');
  7068. while(element) {
  7069. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  7070. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  7071. element = element.offsetParent;
  7072. }
  7073. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  7074. document.getElementById('new_file').style.right = '' + 0 + 'px';
  7075. location.hash = '#new_file';
  7076. };
  7077. //]]>
  7078. </script>\n";
  7079. $output = "";
  7080. $select_all = "";
  7081. $count_files = 0;
  7082. $extensions_allow = array();
  7083. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  7084. foreach ($iassign_ilm as $item_iassign_ilm)
  7085. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  7086. foreach ($files_course as $value) {
  7087. $filename = $value->get_filename();
  7088. $filepath = $value->get_filepath();
  7089. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  7090. $pathname = $pathname[count($pathname) - 1];
  7091. $fileid = $value->get_id();
  7092. $tmp = explode(".", $filename);
  7093. if (count($tmp)>1) // avoid error if the file has no extension
  7094. $filetype = $tmp[1];
  7095. else // probably error...
  7096. $filetype = '';
  7097. $author = $value->get_author();
  7098. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  7099. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  7100. $extensions = explode(",", $extension);
  7101. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  7102. $count_files ++;
  7103. // buscar fileid nas tabelas do iassign
  7104. $list_filein_use = "";
  7105. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  7106. if ($iassign_statement_activity_list) {
  7107. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  7108. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  7109. }
  7110. }
  7111. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  7112. if (!$iassign_ilm) {
  7113. $iassign_ilm = new stdClass();
  7114. $iassign_ilm->id = $ilmid;
  7115. }
  7116. // Do not use $var inside "..." - problem with some "unusual" operational system
  7117. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  7118. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  7119. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  7120. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  7121. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7122. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7123. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  7124. $check_select = "";
  7125. $link_rename = "";
  7126. $link_delete = "";
  7127. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7128. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7129. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7130. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  7131. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  7132. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  7133. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  7134. if ($value->get_userid() == $USER->id) {
  7135. if ($iassign_statement_activity_list) {
  7136. $check_select = "";
  7137. $link_edit = iassign_icons::insert('edit_iassign_disable');
  7138. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  7139. $link_rename = "";
  7140. } else {
  7141. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  7142. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  7143. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  7144. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  7145. }
  7146. }
  7147. if (!in_array($filetype, $extensions_allow)) {
  7148. $link_edit = "";
  7149. $link_add_ilm_iassign = "";
  7150. $link_add_ilm_tinymce = "";
  7151. $link_add_ilm_atto = "";
  7152. $link_filter = "";
  7153. }
  7154. if ($value->is_directory()) {
  7155. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  7156. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  7157. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  7158. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  7159. <td><center>$author</center></td>
  7160. <td><center>$timecreated</center></td>
  7161. <td><center>$timemodified</center></td></tr>\n";
  7162. }
  7163. else if ($this->from == 'iassign') {
  7164. $new_id = "";
  7165. $new_class = "";
  7166. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  7167. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  7168. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  7169. }
  7170. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  7171. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7172. <td><center>$author</center></td>
  7173. <td><center>$timecreated</center></td>
  7174. <td><center>$timemodified</center></td></tr>\n";
  7175. }
  7176. else if ($this->from == 'block') {
  7177. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  7178. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7179. <td><center>$author</center></td>
  7180. <td><center>$timecreated</center></td>
  7181. <td><center>$timemodified</center></td></tr>\n";
  7182. }
  7183. else if ($this->from == 'tinymce') {
  7184. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  7185. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7186. <td><center>$author</center></td>
  7187. <td><center>$timecreated</center></td>
  7188. <td><center>$timemodified</center></td></tr>\n";
  7189. }
  7190. else if ($this->from == 'atto') {
  7191. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  7192. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  7193. <td><center>$author</center></td>
  7194. <td><center>$timecreated</center></td>
  7195. <td><center>$timemodified</center></td></tr>\n";
  7196. }
  7197. }
  7198. }
  7199. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  7200. $dir_base = "";
  7201. $header = "";
  7202. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  7203. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  7204. foreach ($basename as $value) {
  7205. $dir_base .= $value . "/";
  7206. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  7207. if ($dir_id) {
  7208. if ($value == "") {
  7209. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7210. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  7211. } else {
  7212. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  7213. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  7214. }
  7215. }
  7216. } // foreach ($basename as $value)
  7217. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  7218. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  7219. $html .= "
  7220. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  7221. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  7222. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  7223. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  7224. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  7225. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  7226. </table>\n";
  7227. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  7228. $html .= "<table width='100%'><tr>\n";
  7229. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  7230. if ($count_files != 0) {
  7231. $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";
  7232. $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";
  7233. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  7234. }
  7235. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  7236. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  7237. $html .= "</form>\n";
  7238. print $code_javascript_ilm;
  7239. print $html;
  7240. } // function view_files_ilm($extension)
  7241. } // class ilm_manager
  7242. /// Class to insert of icons
  7243. class iassign_icons {
  7244. static function insert ($icon) {
  7245. global $CFG;
  7246. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  7247. return $string;
  7248. }
  7249. }
  7250. /// Class with util functions for plugin manage
  7251. class iassign_utils {
  7252. /// Function to return the filename extension
  7253. // @param string The $filename as an string
  7254. // @return string Return an string (last group after '.')
  7255. static function filename_extension ($filename) {
  7256. if ($filename == null || $filename == '') {
  7257. return null;
  7258. }
  7259. $itens = explode('.', $filename);
  7260. $num = count($itens);
  7261. if ($num < 2) {
  7262. return null;
  7263. }
  7264. return $itens[$num - 1];
  7265. }
  7266. /// Use the PHP class/package ZipArchive to create a Zip file
  7267. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  7268. // 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
  7269. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  7270. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  7271. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  7272. $zip = new zip_archive(); //2
  7273. $res = $zip->open($full_path_zip_filename);
  7274. $total_vet = count($vet_student_filename);
  7275. for ($ii=0; $ii<$total_vet; $ii++) {
  7276. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  7277. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  7278. }
  7279. $ret = $zip->close();
  7280. iassign_utils::download_file($full_path_zip_filename);
  7281. $filenameZip = $zip->filename;
  7282. return array($ret, $zip);
  7283. }
  7284. static function download_file ($zip_filename) {
  7285. header("Pragma: public");
  7286. header("Expires: 0");
  7287. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  7288. header("Cache-Control: private", false);
  7289. header("Content-Type: application/zip");
  7290. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  7291. header("Content-Transfer-Encoding: binary");
  7292. header("Content-Length: " . @filesize($zip_filename));
  7293. set_time_limit(0);
  7294. @readfile("$zip_filename") || die("File not found.");
  7295. unlink($zip_filename);
  7296. }
  7297. /// Function for format filename remove special caracters
  7298. // @param string $text String for clean
  7299. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  7300. // @return string Return an string in clean format
  7301. static function format_filename ($text) {
  7302. if ($text != '.') {
  7303. //D $text = htmlspecialchars(urldecode($text));
  7304. //D echo "locallib.php: format_filename: $text<br/>";
  7305. if (is_object($text)) // with iAssign did not filtered text from JSON format
  7306. $text = json_decode($text)->{current_language()};
  7307. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  7308. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ", ":",
  7309. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  7310. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  7311. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_", "-",
  7312. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  7313. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  7314. // E.g. text = "exerc_midpoint.course.geo"
  7315. // 0123456789012345678901234
  7316. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  7317. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  7318. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  7319. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  7320. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  7321. //$ext = strrpos($text, ".");
  7322. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  7323. //$text = str_replace($array1, $array2, $text);
  7324. }
  7325. return $text;
  7326. }
  7327. /// Function to filter characters to the file name to iLM content
  7328. // @param string $text String for clean
  7329. // @param string $ext String ot the extension of the iLM
  7330. // @return string Return an string in clean format
  7331. static function filter_filename_extension ($filename, $ext) {
  7332. if ($filename != '.') {
  7333. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  7334. $arrTo = array("_","","","","","","","","","","","","");
  7335. $filename = str_replace($arrFrom, $arrTo, $filename);
  7336. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  7337. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  7338. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  7339. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  7340. $index_lastposition = strlen($filenameF);
  7341. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  7342. $text = str_replace(".", "_", $text); // erase all other "."
  7343. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  7344. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  7345. }
  7346. else
  7347. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  7348. return $filenameF;
  7349. }
  7350. /// Function for format pathname remove special caracters
  7351. // @param string $text String for clean
  7352. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7353. // @return string Return an string in clean format
  7354. static function format_pathname ($text, $is_lowercase = true) {
  7355. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7356. $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", "-", "_", "", "", "");
  7357. $text = str_replace($array1, $array2, $text);
  7358. if ($is_lowercase)
  7359. $text = strtolower($text);
  7360. return $text;
  7361. }
  7362. /// Function for format file name from iLM original name
  7363. // @param string $text String to build the file neam
  7364. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  7365. // @return string Return an string in clean format
  7366. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  7367. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  7368. $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", "-", "_", "", "", "");
  7369. $index_firstposition_blank = strpos($ilm_name, " ");
  7370. if ($index_firstposition_blank) { // truncate the name!
  7371. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  7372. }
  7373. $index_firstposition_dots = strpos($ilm_name, ":");
  7374. if ($index_firstposition_dots) { // truncate the name!
  7375. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  7376. }
  7377. $namefiltered = str_replace($array1, $array2, $ilm_name);
  7378. if ($is_lowercase)
  7379. $namefiltered = strtolower($namefiltered);
  7380. return $namefiltered;
  7381. }
  7382. /// Function for insert version in the filename
  7383. // @param string $filename Name of file
  7384. // @return string Return the filename with version
  7385. static function version_filename ($filename) {
  7386. $array_filename = explode('.', $filename);
  7387. if (count($array_filename) > 1)
  7388. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  7389. else
  7390. $filename = $array_filename[0] . '-' . date("Ymd-His");
  7391. return $filename;
  7392. }
  7393. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  7394. static function remove_code_message ($string) {
  7395. $array = explode("&lt;ia_uc&gt;", $string);
  7396. return $array[0];
  7397. }
  7398. }
  7399. // class iassign_utils
  7400. /// Class with language functions for plugin manage
  7401. class iassign_language {
  7402. /// Function for return text in language or get default language (en)
  7403. // @param string $lang Code of language
  7404. // @param string $description JSON text content all languages
  7405. // @return string Return an string in the language selected
  7406. static function get_description_lang ($lang, $descriptions) {
  7407. $description_lang = "";
  7408. $description = json_decode($descriptions);
  7409. if ($description == null) {
  7410. $description_lang = $descriptions;
  7411. }
  7412. else {
  7413. if (isset($description->{$lang}))
  7414. $description_lang = $description->{$lang};
  7415. else
  7416. if (isset($description->en)) //MOOC2014
  7417. $description_lang = $description->en;
  7418. else //MOOC2014
  7419. $description_lang = "en"; //MOOC2014
  7420. }
  7421. return $description_lang;
  7422. }
  7423. /// Function for return all language supported by iLM
  7424. // @param string $descriptions JSON text content all languages
  7425. // @return string Return as string with all languages
  7426. static function get_all_lang ($descriptions) {
  7427. $langs = "";
  7428. $description = json_decode($descriptions);
  7429. if ($description) {
  7430. foreach ($description as $key => $value) {
  7431. $langs .= $key . " ; ";
  7432. }
  7433. $langs = substr($langs, 0, strlen($langs) - 3);
  7434. }
  7435. return $langs;
  7436. }
  7437. /// Function for convert json in xml //MOOC2014
  7438. // @param string $json JSON text
  7439. // @return string Return as string with xml tags
  7440. static function json_to_xml ($json) {
  7441. $xml = "";
  7442. $json = json_decode($json);
  7443. foreach ($json as $key => $value) {
  7444. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  7445. }
  7446. return $xml;
  7447. }
  7448. }
  7449. // class iassign_language
  7450. /// Class with log functions for plugin manage.
  7451. class iassign_log {
  7452. /// Function for insert log event
  7453. // @param string $action Code action of event
  7454. // @param string $information Text for describe action of event
  7455. // @param int $cmid Id of context module
  7456. // @param int $ilmid Id of iLM
  7457. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  7458. global $COURSE, $CFG, $USER, $DB;
  7459. $newentry = new stdClass();
  7460. $newentry->time = time();
  7461. $newentry->userid = $USER->id;
  7462. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  7463. $newentry->course = $COURSE->id;
  7464. $newentry->cmid = $cmid;
  7465. $newentry->ilmid = $ilmid;
  7466. $newentry->action = $action;
  7467. $newentry->info = $information;
  7468. $newentry->language = current_language();
  7469. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  7470. if (ini_get("browscap") && function_exists('get_browse')) {
  7471. $browser = get_browse(null, true);
  7472. $newentry->javascript = $browser['javascript'];
  7473. $newentry->java = $browser['javaapplets'];
  7474. }
  7475. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  7476. print_error('error_add_log', 'iassign');
  7477. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  7478. } // class iassign_log