locallib.php 329 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.3 2020/01/16
  7. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  8. *
  9. * - v 4.9.2 2019/03/13
  10. * + Several fixes to allow iLM under HTML stack
  11. *
  12. * - v 4.9.1 2017/11/02
  13. * + 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")
  14. * + 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)'
  15. *
  16. * - v 4.9 2017/03/13
  17. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  18. *
  19. * - v 4.8 2016/05/12
  20. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  21. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  22. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  23. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  24. * replaced by
  25. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  26. * - v 4.7 2016/02/17
  27. * + 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(...)')
  28. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  29. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  30. * + 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)
  31. * + 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'
  32. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  33. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  34. *
  35. * --------------- (code bellow was used at our MOOC 2014)
  36. * - v 4.6 2014/02/25
  37. * + Fix bugs in filter function for open applets.
  38. * - v 4.5 2014/02/24
  39. * + Fix bugs in params.
  40. * + Insert new param type.
  41. * - v 4.4 2014/01/24
  42. * + Allow select type of params.
  43. * + Insert the use of applet params specific for activities.
  44. * - v 4.3 2014/01/23
  45. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  46. * - v 4.2 2016/02/13
  47. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  48. * --------------- (above code used at our MOOC 2014)
  49. *
  50. * - v 4.1 2013/12/13
  51. * + Insert log in iAssign actions.
  52. * + 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).
  53. * + Insert class for Log actions in system.
  54. * - v 4.0 2013/10/31
  55. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  56. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  57. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  58. * - v 3.9 2013/10/25
  59. * + Insert support of upgrade iLM.
  60. * + Insert support for more than one extension in iLM.
  61. * + Fix bugs in verion control.
  62. * - v 3.8 2013/09/19
  63. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  64. * - v 3.7 2013/09/12
  65. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  66. * + 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).
  67. * - v 3.6 2013/09/05
  68. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  69. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  70. * + Change tag APPLET in function ilm_settings::view_ilm.
  71. * - v 3.5 2013/08/26
  72. * + Fix bug in download package iassign without answers (iassign::report).
  73. * - v 3.4 2013/08/23
  74. * + Fix bug in export package iassign.
  75. * - v 3.3 2013/08/22
  76. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  77. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  78. * - v 3.2 2013/08/21
  79. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  80. * + Change functions for import files for ilm_manager.php.
  81. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  82. * - v 3.1 2013/08/15
  83. * + Change return file selected (ilm_manager::add_ilm).
  84. * + 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).
  85. * - v 3.0 2013/08/02
  86. * + 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).
  87. * - v 2.9 2013/08/01
  88. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  89. * - v 2.8 2013/07/25
  90. * + Insert the activity name in header of view (activity::view_dates).
  91. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  92. * - v 2.7 2013/07/24
  93. * + Create link previous and next for student view in one activity (activity::view_dates).
  94. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  95. * - v 2.6 2013/07/23
  96. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  97. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  98. * - v 2.5 2013/07/12
  99. * + 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).
  100. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  101. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  102. *
  103. * @author Patricia Alves Rodrigues
  104. * @author Leônidas O. Brandão
  105. * @contributor Igor Moreira Félix (2018-)
  106. * @contributor Márcio de Lima Passos (2014)
  107. * @version v 4.9.2 2019/03/13
  108. * @version v 4.8 2016/05/12
  109. * @package mod_iassign_lib
  110. * @since 2010/09/27
  111. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  112. *
  113. * <b>License</b>
  114. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  115. */
  116. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  117. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  118. //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"'
  119. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  120. /**
  121. * Standard base class for all iAssign
  122. */
  123. class iassign {
  124. var $cm;
  125. var $course;
  126. var $iassign;
  127. var $striassign;
  128. var $striassigns;
  129. var $context;
  130. var $activity;
  131. var $iassign_up;
  132. var $iassign_down;
  133. var $action;
  134. var $iassign_submission_current;
  135. var $userid_iassign;
  136. var $bottonPost;
  137. var $write_solution;
  138. var $view_iassign;
  139. // 3.1 update PHP 7.0 compatibility for all moodle versions
  140. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  141. /// Constructor for the base iassign class
  142. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  143. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  144. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  145. function __construct ($iassign, $cm, $course) {
  146. global $COURSE, $CFG, $USER, $DB;
  147. $botton = optional_param('botton', NULL, PARAM_TEXT);
  148. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  149. if (!is_null($botton))
  150. $USER->iassignEdit = $botton;
  151. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  152. // 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'
  153. $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"
  154. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  155. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  156. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  157. $this->action = optional_param('action', NULL, PARAM_TEXT);
  158. $this->cm = $cm;
  159. $this->context = context_module::instance($this->cm->id);
  160. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  161. $this->userid_iassign = $USER->id;
  162. if ($course) {
  163. $this->course = $course;
  164. }
  165. else if ($this->cm->course == $COURSE->id) {
  166. $this->course = $COURSE;
  167. }
  168. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  169. print_error('invalidid', 'iassign');
  170. }
  171. $this->coursecontext = context_course::instance($this->course->id);
  172. if ($iassign) {
  173. $this->iassign = $iassign;
  174. }
  175. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  176. print_error('invalidid', 'iassign');
  177. }
  178. $USER->context = context_module::instance($this->cm->id);
  179. $USER->cm = $this->cm->id;
  180. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  181. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  182. $this->context = context_module::instance($this->cm->id);
  183. $this->striassign = get_string('modulename', 'iassign');
  184. $this->striassigns = get_string('modulenameplural', 'iassign');
  185. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  186. $this->bottonPost = 0;
  187. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  188. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  189. $this->view();
  190. } // function __construct($iassign, $cm, $course)
  191. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  192. // This method provides the page to view each iLM with any interactive activity
  193. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  194. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  195. global $USER, $DB, $OUTPUT;
  196. // $iassign_statementid = $this->iassign->iassign_statementid;
  197. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  198. $iassign_statementid = $this->activity->get_activity()->id;
  199. else
  200. $iassign_statementid = "";
  201. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  202. // If this user has no capability to View 'iassign': stop here
  203. require_capability('mod/iassign:view', $this->context);
  204. // Trigger module view event
  205. $event = \mod_iassign\event\course_module_viewed::create(array(
  206. 'objectid' => $this->iassign->id,
  207. 'context' => $this->context
  208. ));
  209. $event->add_record_snapshot('course', $this->course);
  210. $event->trigger();
  211. if ($this->action) { // when student do/redo activity or teacher see student solution
  212. $this->action(); // calls '$this->view_iLM();'
  213. }
  214. else {
  215. print $OUTPUT->header();
  216. $this->view_iassigns(); // show the iLM with the content
  217. print $OUTPUT->footer();
  218. }
  219. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  220. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //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" }
  223. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //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" }
  226. //D else echo "Apagou!<br/>";
  227. die();
  228. } // function view()
  229. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  230. function action () {
  231. global $USER;
  232. // action:
  233. // up - move up activity (mover atividade para cima)
  234. // down - move down activity (mover atividade para baixo)
  235. // visible - view/hide activity (exibir/ocultar atividade)
  236. // delete - delete activity (excluir atividade)
  237. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  238. // deleteno - does not erase activity (não apaga atividade)
  239. // add - add activity (adicionar atividade)
  240. // edit - edit activity (modificar atividade)
  241. $action_iassign = array(
  242. 'newcomment' => '$this->get_answer();',
  243. 'view' => '$this->view_iassign_current();',
  244. 'get_answer' => '$this->get_answer();',
  245. 'repeat' => '$this->view_iassign_current();',
  246. 'overwrite' => '$this->get_answer();',
  247. 'stats_student' => '$this->stats_students();',
  248. 'download_answer' => '$this->export_file_answer();',
  249. 'download_all_answer' => '$this->export_package_answer();');
  250. $action_iassign_limit = array(
  251. 'view' => '$this->view_iassign_current();',
  252. 'newcomment' => '$this->get_answer();',
  253. 'viewsubmission' => '$this->view_iassign_current();',
  254. 'edit_status' => '$this->edit_status();',
  255. 'edit_grade' => '$this->edit_grade();',
  256. 'export_csv' => '$this->export_csv();',
  257. 'report' => '$this->report();',
  258. 'print' => '$this->report();',
  259. 'stats' => '$this->stats();',
  260. 'printstats' => '$this->stats();');
  261. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  262. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  263. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  264. 'visible' => '$this->activity->visible_iassign($this->return);',
  265. 'delete' => '$this->activity->delete($this->return);',
  266. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  267. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  268. 'add' => '$this->add_edit_iassign();',
  269. 'edit' => '$this->add_edit_iassign();',
  270. 'get_answer' => '$this->get_answer();',
  271. 'duplicate_activity' => '$this->duplicate_activity();',
  272. 'move_activity' => '$this->move_activity();',
  273. 'auto_evaluate' => '$this->auto_evaluate();');
  274. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  275. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  276. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  277. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  278. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  279. }
  280. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  281. eval($action_iassign_limit[$this->action]);
  282. }
  283. else { // Student reaches this point
  284. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  285. // Arrive here with: "get_answer"; "view"
  286. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  287. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  288. }
  289. } // function action()
  290. /// This method runs activities auto evaluation in teacher area
  291. function auto_evaluate () {
  292. global $COURSE, $CFG, $USER, $DB, $OUTPUT;
  293. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  294. exit;
  295. print $OUTPUT->header();
  296. print $OUTPUT->footer();
  297. }
  298. /// This method moves an iAssign activity
  299. function move_activity () {
  300. global $USER, $CFG, $DB, $COURSE;
  301. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  302. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  303. $update_entry_new_iassign = new stdClass();
  304. $update_entry_new_iassign->id = $iassign_id;
  305. $update_entry_new_iassign->iassignid = $iassign_destiny;
  306. // Update the iassign_statement
  307. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  308. // Update file context
  309. $c_i = context_module::instance($this->cm->id);
  310. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  311. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  312. $path_module = context_course::instance($COURSE->id);
  313. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  314. if ($context_file) {
  315. $id_context = $context_file->id;
  316. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  317. $fs = get_file_storage(); // Get reference to all files in Moodle data
  318. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  319. foreach ($files as $value) {
  320. if ($value->get_filename() != ".") {
  321. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  322. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  323. $updateentry = new stdClass();
  324. $updateentry->id = $iassign_id;
  325. $updateentry->file = $newfile->get_itemid();
  326. $DB->update_record("iassign_statement", $updateentry);
  327. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  328. break;
  329. }
  330. }
  331. }
  332. $this->return_home_course('moved_activity');
  333. exit;
  334. }
  335. /// This method duplicates an iAssign activity
  336. function duplicate_activity () {
  337. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  338. $id = $this->cm->id;
  339. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  340. $context = context_module::instance($this->cm->id);
  341. $contextuser = context_user::instance($USER->id);
  342. // Get the the iAssign acitivity to be duplicated
  343. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  344. // Remove the current id of activity
  345. $iassign_statement->id=0;
  346. // Get the information about current author, and add this information in author_modified field
  347. $author = $DB->get_record("user", array('id' => $USER->id));
  348. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  349. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  350. // Store the activity in the table
  351. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  352. // Duplicate activity file
  353. $fs = get_file_storage(); // Get reference to all files in Moodle data
  354. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  355. foreach ($files as $value) {
  356. if ($value->get_filename() != ".") {
  357. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  358. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  359. $updateentry = new stdClass();
  360. $updateentry->id = $id_;
  361. $updateentry->file = $newfile->get_itemid();
  362. // Update the duplicated iLM iAssign with new file id
  363. $DB->update_record("iassign_statement", $updateentry);
  364. }
  365. }
  366. }
  367. // log event --------------------------------------------------------------------------------------
  368. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  369. $this->return_home_course('duplicated_activity');
  370. exit;
  371. }
  372. /// This method gets the content from the iLM and register it
  373. // It could be the "exercise template" (teacher) or an answer (student)
  374. function get_answer () {
  375. global $USER, $CFG, $DB, $OUTPUT;
  376. $id = $this->cm->id;
  377. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  378. $comment = false;
  379. if ($submission_comment)
  380. $comment = $this->write_comment_submission();
  381. // receives data of iLM using the current activity
  382. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  383. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  384. // receives data of submission of current activity
  385. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  386. // receives post and get
  387. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  388. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  389. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  390. $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)
  391. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  392. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  393. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  394. $msg = '';
  395. // Feedback
  396. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  397. $str_action = "view"; // repeat
  398. if (strtolower($iassign_ilm->name) == "igeom") {
  399. }
  400. $title = get_string('evaluate_iassign', 'iassign');
  401. print $OUTPUT->header();
  402. print $OUTPUT->box_start();
  403. // Action = { view ; repeat ; viewsubmission }
  404. // * '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")
  405. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  406. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  407. $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;
  408. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  409. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  410. print '<table width=100% >';
  411. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  412. //TODO alterar aqui???
  413. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  414. // empty_answer_post = No solution was posted.
  415. if ($comment)
  416. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  417. else
  418. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  419. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  420. } else {
  421. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  422. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  423. // Correct answer!!
  424. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  425. $this->write_solution = 1; //
  426. $status = 3;
  427. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  428. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  429. // log record
  430. $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;
  431. // Trigger module viewed event.
  432. $event = \mod_iassign\event\submission_created::create(array(
  433. 'objectid' => $this->iassign->id,
  434. 'context' => $this->context,
  435. 'other' => $info
  436. ));
  437. $event->add_record_snapshot('course', $this->course);
  438. $event->trigger();
  439. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  440. // Wrong answer...: get_answer_incorrect
  441. $status = 2;
  442. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  443. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  444. // log record
  445. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  446. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  447. // Trigger module viewed event.
  448. $event = \mod_iassign\event\submission_created::create(array(
  449. 'objectid' => $this->iassign->id,
  450. 'context' => $this->context,
  451. 'other' => $info
  452. ));
  453. $event->add_record_snapshot('course', $this->course);
  454. $event->trigger();
  455. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  456. // Presents to the learner the result of the automatic evaluate?
  457. if ($this->activity->get_activity()->show_answer == 0) { // no...
  458. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  459. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  460. print '<tr>';
  461. // log record
  462. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  463. // Trigger module viewed event.
  464. $event = \mod_iassign\event\submission_created::create(array(
  465. 'objectid' => $this->iassign->id,
  466. 'context' => $this->context,
  467. 'other' => $info
  468. ));
  469. $event->add_record_snapshot('course', $this->course);
  470. $event->trigger();
  471. } else { // yes!!!
  472. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  473. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  474. print '<tr>';
  475. print $msg;
  476. }
  477. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  478. $status = 1;
  479. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  480. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  481. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  482. print '<tr>';
  483. // log record
  484. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  485. $event = \mod_iassign\event\submission_created::create(array(
  486. 'objectid' => $this->iassign->id,
  487. 'context' => $this->context,
  488. 'other' => $info
  489. ));
  490. $event->add_record_snapshot('course', $this->course);
  491. $event->trigger();
  492. } // if ($iassign_ilm->evaluate == 1)
  493. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  494. print '</tr></table>';
  495. print $OUTPUT->box_end();
  496. // add or update evaluate
  497. if ($this->write_solution == 1) {
  498. $timenow = time();
  499. // new record
  500. if (!$iassign_submission) {
  501. $newentry = new stdClass();
  502. $newentry->userid = $this->userid_iassign;
  503. // $newentry->userid = $USER->id;
  504. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  505. $newentry->timecreated = $timenow;
  506. $newentry->timemodified = $timenow;
  507. $newentry->answer = $iLM_PARAM_ArchiveContent;
  508. $newentry->grade = $grade_student;
  509. $newentry->status = $status;
  510. $newentry->experiment = 1;
  511. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  512. print_error('error_insert', 'iassign');
  513. } else {
  514. // Trigger module viewed event.
  515. $event = \mod_iassign\event\submission_created::create(array(
  516. 'objectid' => $this->iassign->id,
  517. 'context' => $this->context
  518. ));
  519. $event->add_record_snapshot('course', $this->course);
  520. $event->trigger();
  521. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  522. }
  523. } elseif ($iassign_submission->status != 3) {
  524. $newentry = new stdClass();
  525. $newentry->id = $iassign_submission->id;
  526. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  527. $newentry->userid = $iassign_submission->userid;
  528. $newentry->timecreated = $iassign_submission->timecreated;
  529. $newentry->timemodified = $timenow;
  530. $newentry->answer = $iLM_PARAM_ArchiveContent;
  531. $newentry->grade = $grade_student;
  532. $newentry->status = $status;
  533. $newentry->experiment = $iassign_submission->experiment + 1;
  534. if (!$DB->update_record("iassign_submission", $newentry)) {
  535. print_error('error_update', 'iassign');
  536. //D depurar...
  537. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  538. //D $fp = fopen("teste1.txt","w");
  539. //D fwrite($fp,$stringAux);
  540. } else {
  541. // Trigger module viewed event.
  542. $event = \mod_iassign\event\submission_updated::create(array(
  543. 'objectid' => $this->iassign->id,
  544. 'context' => $this->context
  545. ));
  546. $event->add_record_snapshot('course', $this->course);
  547. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  548. }
  549. } else {
  550. if ($return_get_answer == 1) {
  551. $newentry = new stdClass();
  552. $newentry->id = $iassign_submission->id;
  553. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  554. $newentry->userid = $iassign_submission->userid;
  555. $newentry->timecreated = $iassign_submission->timecreated;
  556. $newentry->timemodified = $timenow;
  557. $newentry->answer = $iLM_PARAM_ArchiveContent;
  558. $newentry->grade = $grade_student;
  559. $newentry->status = $status;
  560. $newentry->experiment = $iassign_submission->experiment + 1;
  561. if (!$DB->update_record("iassign_submission", $newentry))
  562. print_error('error_update', 'iassign');
  563. else {
  564. $event = \mod_iassign\event\submission_updated::create(array(
  565. 'objectid' => $this->iassign->id,
  566. 'context' => $this->context
  567. ));
  568. $event->add_record_snapshot('course', $this->course);
  569. $event->trigger();
  570. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  571. print $OUTPUT->box_start();
  572. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  573. print $OUTPUT->box_end();
  574. }
  575. } elseif ($return_get_answer == 2) {
  576. print $OUTPUT->box_start();
  577. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  578. print $OUTPUT->box_end();
  579. } else {
  580. print $OUTPUT->box_start();
  581. print "
  582. <script type='text/javascript'>
  583. //<![CDATA[
  584. function overwrite () {
  585. document.formEnvio.return_get_answer.value = 1;
  586. document.formEnvio.submit();
  587. }
  588. function nooverwrite () {
  589. document.formEnvio.return_get_answer.value = 2;
  590. document.formEnvio.submit();
  591. }
  592. //]]>
  593. </script>";
  594. $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;
  595. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  596. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  597. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  598. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  599. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  600. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  601. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  602. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  603. <input type='hidden' name='return_get_answer'/> ";
  604. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  605. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  606. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  607. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  608. print " </form>";
  609. print $OUTPUT->box_end();
  610. }
  611. }
  612. } // if ($this->write_solution == 1)
  613. print $OUTPUT->footer();
  614. die();
  615. } // function get_answer()
  616. /// Export in file the answer of student.
  617. function export_file_answer () {
  618. global $DB;
  619. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  620. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  621. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  622. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  623. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  624. $extensions = explode(",", $iassign_ilm->extension);
  625. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  626. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  627. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  628. header("Pragma: public");
  629. header("Expires: 0");
  630. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  631. header("Cache-Control: private", false);
  632. header("Content-Type: document/unknown");
  633. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  634. set_time_limit(0);
  635. print($iassign_submission->answer);
  636. exit;
  637. } // function export_file_answer()
  638. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  639. // @calledby $this->export_package_answer()
  640. //TODO Precisa terminar! //TODO_HTML
  641. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  642. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  643. <head>
  644. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  645. $str_html .= " </head>
  646. <body>\n";
  647. $tam = sizeof($array_iassign_name);
  648. for ($ii=0; $ii<$tam; $ii++) {
  649. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  650. }
  651. $str_html .= "
  652. </body>\n</html>";
  653. return $str_html;
  654. }
  655. /// Export an package (zip) with all answer of students
  656. // @calledby $this->action()
  657. function export_package_answer () {
  658. global $DB, $CFG, $OUTPUT;
  659. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  660. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  661. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  662. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  663. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  664. $userid = optional_param('userid', NULL, PARAM_INT);
  665. $iassign_user = $DB->get_record("user", array("id" => $userid));
  666. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  667. //TODO_HTML echo "username=$username<br/>"; exit;
  668. $current_date = date('Y_m_d_H');
  669. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  670. // If temporary directory under Moodle data does not exists => create it
  671. if (!is_dir($diretorio)) {
  672. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  673. // created directory with permissions to be seen by everyone
  674. }
  675. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  676. if (!is_writable($diretorio)) { // send a highlighted message!
  677. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  678. exit; // just in case
  679. }
  680. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  681. $zip = new zip_archive(); // create ZIP
  682. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  683. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  684. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  685. $vet_student_filename = array();
  686. $vet_student_content = array();
  687. foreach ($iassign_statements as $iassign_statement) {
  688. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  689. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  690. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  691. $extensions = explode(",", $iassign_ilm->extension);
  692. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  693. if ($iassign_submission) {
  694. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  695. $student_content = $iassign_submission->answer;
  696. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  697. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  698. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  699. if ($resp) {
  700. $vet_student_filename[] = $student_filename;
  701. $vet_student_content[] = $student_content;
  702. }
  703. else { // send a highlighted message!
  704. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  705. exit; // just in case
  706. }
  707. }
  708. }
  709. $zip->close(); // close the ZIP file
  710. if (count($vet_student_filename)>0) {
  711. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  712. $result_tf = $vet_result[0];
  713. $filenameZip = $vet_result[1]->filename;
  714. }
  715. iassign_utils::download_file($zip_filename); // download the ZIP file
  716. exit;
  717. } // function export_package_answer()
  718. /// Editing status of interactive activities
  719. function edit_status () {
  720. global $USER, $DB, $OUTPUT;
  721. $newentry = new stdClass();
  722. $newentry->id = $this->iassign_submission_current;
  723. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  724. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  725. if ($iassign_submission->status != 0 && $newentry->status == 0)
  726. $newentry->status = $iassign_submission->status;
  727. $newentry->teacher = $USER->id;
  728. if (!$DB->update_record('iassign_submission', $newentry))
  729. print_error('error_update', 'iassign');
  730. else {
  731. // Trigger module viewed event.
  732. $event = \mod_iassign\event\submission_updated::create(array(
  733. 'objectid' => $this->iassign->id,
  734. 'context' => $this->context
  735. ));
  736. $event->add_record_snapshot('course', $this->course);
  737. $event->trigger();
  738. $this->action = 'viewsubmission';
  739. $this->view_iassign_current();
  740. } // if (!$DB->update_record('iassign_submission', $newentry))
  741. } // function edit_status()
  742. /// Editing grade of interactive activities
  743. function edit_grade () {
  744. global $USER, $DB, $OUTPUT;
  745. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  746. if ($newgrade && $newgrade >= 0) {
  747. $newentry = new stdClass();
  748. $newentry->id = $this->iassign_submission_current;
  749. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  750. $newentry->teacher = $USER->id;
  751. if (!$DB->update_record('iassign_submission', $newentry))
  752. print_error('error_update', 'iassign');
  753. else {
  754. // Trigger module viewed event.
  755. $event = \mod_iassign\event\submission_updated::create(array(
  756. 'objectid' => $this->iassign->id,
  757. 'context' => $this->context
  758. ));
  759. $event->add_record_snapshot('course', $this->course);
  760. $event->trigger();
  761. }
  762. } // if ($newgrade >= 0)
  763. $this->action = 'viewsubmission';
  764. $this->view_iassign_current();
  765. }
  766. /// Add or Edit interactive activities
  767. // @calledby $this->action()
  768. function add_edit_iassign () {
  769. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  770. require_once('iassign_form.php');
  771. $id = $this->cm->id;
  772. $iassignid = $this->iassign->id;
  773. $param = new stdClass();
  774. $param->action = $this->action; // oculto
  775. $param->id = $id; // oculto
  776. $COURSE->cm = $id;
  777. $COURSE->iassignid = $iassignid;
  778. $COURSE->iassign_file_id = NULL;
  779. $context = context_module::instance($this->cm->id);
  780. $contextuser = context_user::instance($USER->id);
  781. $component = 'mod_iassign';
  782. $filearea = 'exercise';
  783. if (!empty($this->iassign_current))
  784. $COURSE->iassign_id = $this->iassign_current;
  785. else
  786. $COURSE->iassign_id = 0;
  787. $total_of_activities = 0; // get the total number of activities in this iAssign block
  788. if ($this->action == 'add') {
  789. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  790. $total_of_activities = count($iassign_data);
  791. $params = array('iassignid' => $iassignid);
  792. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  793. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  794. $param->iassignid = $iassignid;
  795. $param->name = "";
  796. $param->oldname = "";
  797. $param->type_iassign = 3;
  798. $param->proposition = "";
  799. $author = $DB->get_record("user", array("id" => $USER->id));
  800. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  801. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  802. $param->author = $param->author_name;
  803. $param->author_modified = $param->author_modified_name;
  804. $COURSE->iassign_list = array();
  805. $param->iassign_list = array();
  806. if ($iassign_statement) {
  807. foreach ($iassign_statement as $iassign) {
  808. $iassignid = $iassign->id;
  809. $param->iassign_list[$iassignid] = 0;
  810. $COURSE->iassign_list[$iassignid] = new stdClass();
  811. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  812. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  813. $COURSE->iassign_list[$iassignid]->enable = 1;
  814. } // foreach ($iassign_statement as $iassign)
  815. }
  816. $param->iassign_ilmid = 0;
  817. //echo "locallib.php: add_edit_iassign(): add<br/>";
  818. $param->file = 0;
  819. $param->fileold = 0;
  820. $param->filename = "";
  821. $param->grade = $iassign_data->grade;
  822. $param->timemodified = time();
  823. $param->timecreated = time();
  824. $param->timeavailable = $iassign_data->timeavailable;
  825. $param->timedue = $iassign_data->timedue;
  826. $param->preventlate = $iassign_data->preventlate;
  827. $param->test = $iassign_data->test;
  828. $param->special_param1 = 0;
  829. $param->visible = 1;
  830. $param->max_experiment = $iassign_data->max_experiment;
  831. $param->dependency = 0;
  832. $param->automatic_evaluate = 1;
  833. $param->show_answer = 1;
  834. } // if ($this->action == 'add')
  835. elseif ($this->action == 'edit') {
  836. $COURSE->iassign_list = array();
  837. $this_activity = $this->activity->get_activity();
  838. if ($this_activity != null) {
  839. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  840. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  841. $param->iassign_id = $iassign_statement_current->id; // oculto
  842. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  843. $param->name = $iassign_statement_current->name;
  844. $param->oldname = $iassign_statement_current->name;
  845. $param->type_iassign = $iassign_statement_current->type_iassign;
  846. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  847. //2019 $param->proposition = $iassign_statement_current->proposition;
  848. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  849. $param->author_name = $iassign_statement_current->author_name; // oculto
  850. $param->author = $iassign_statement_current->author_name;
  851. $author = $DB->get_record("user", array('id' => $USER->id));
  852. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  853. $param->author_modified = $param->author_modified_name;
  854. $dependency = explode(';', $iassign_statement_current->dependency);
  855. $param->iassign_list = array();
  856. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  857. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  858. $array_dependency = array();
  859. $subdependency = "";
  860. $sub_subdependency = "";
  861. // dependent on this exercise
  862. if ($iassign_statement_dependency) {
  863. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  864. // to whom this exercise depends
  865. foreach ($inter as $tmp)
  866. $sub_subdependency .= $this->search_sub_dependency($tmp);
  867. $list_dependency = $subdependency . $sub_subdependency;
  868. $array_dependency = explode(";", $list_dependency);
  869. }
  870. // Get all activity with the same iLM - iassignid
  871. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  872. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  873. $total_of_activities = count($all_others_iassign_statement) + 1;
  874. $inter = array();
  875. if ($all_others_iassign_statement) {
  876. foreach ($all_others_iassign_statement as $iassign)
  877. if (in_array($iassign->id, $dependency))
  878. $inter[] = $iassign->id;
  879. }
  880. if ($all_others_iassign_statement) {
  881. foreach ($all_others_iassign_statement as $iassign) {
  882. $iassignid = $iassign->id;
  883. $COURSE->iassign_list[$iassignid] = new stdClass();
  884. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  885. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  886. if (in_array($iassignid, $dependency))
  887. $param->iassign_list[$iassignid] = 1;
  888. else
  889. $param->iassign_list[$iassignid] = 0;
  890. if (in_array($iassignid, $array_dependency))
  891. $COURSE->iassign_list[$iassignid]->enable = 0;
  892. else
  893. $COURSE->iassign_list[$iassignid]->enable = 1;
  894. } // foreach ($all_others_iassign_statement as $iassign)
  895. }
  896. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  897. $param->fileold = 0;
  898. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  899. $param->filename = '';
  900. $param->grade = $iassign_statement_current->grade;
  901. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  902. $param->timeavailable = $iassign_statement_current->timeavailable;
  903. $param->timedue = $iassign_statement_current->timedue;
  904. $param->preventlate = $iassign_statement_current->preventlate;
  905. $param->test = $iassign_statement_current->test;
  906. $param->special_param1 = $iassign_statement_current->special_param1;
  907. $param->position = $iassign_statement_current->position; // oculto
  908. $param->visible = $iassign_statement_current->visible;
  909. $param->max_experiment = $iassign_statement_current->max_experiment;
  910. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  911. $param->show_answer = $iassign_statement_current->show_answer;
  912. $fs = get_file_storage(); // Get reference to all files in Moodle data
  913. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  914. if ($files) {
  915. foreach ($files as $file) {
  916. if ($file->get_filename() != '.') {
  917. $param->filename = $file->get_filename();
  918. $param->file = $file->get_id();
  919. $param->fileold = $file->get_id();
  920. $COURSE->iassign_file_id = $file->get_id();
  921. }
  922. }
  923. }
  924. //TODO //MOOC2014 -- inicio
  925. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  926. //D if ($iassign_ilm_configs) {
  927. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  928. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  929. //D } //MOOC2014 -- fim
  930. } // if ($this_activity != null)
  931. } // elseif ($this->action == 'edit')
  932. // Get all iActivity in the iAssign block with id = $this->iassign->id
  933. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  934. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  935. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  936. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  937. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  938. $param->position = $total_of_activities;
  939. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  940. $mform->set_data($param);
  941. if ($mform->is_cancelled()) {
  942. $this->return_home_course('iassign_cancel');
  943. exit;
  944. }
  945. else { // if ($mform->is_cancelled())
  946. $result = $mform->get_data();
  947. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  948. if ($result) {
  949. $result->context = $context;
  950. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  951. $result->grade = 0;
  952. if ($result->type_iassign == 1) {
  953. $result->automatic_evaluate = 0;
  954. $result->show_answer = 0;
  955. }
  956. elseif ($result->automatic_evaluate == 0)
  957. $result->show_answer = 0;
  958. // $_POST['iassign_list']
  959. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  960. if ($result->iassign_list) {
  961. foreach ($result->iassign_list as $key => $value)
  962. $result->dependency .= $key . ';';
  963. }
  964. else
  965. $result->dependency = 0;
  966. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  967. //TODO Then get it directly from the form data $_POST!
  968. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  969. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  970. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  971. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  972. if ($this->action == 'add') {
  973. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  974. if ($iassign_statement_name) {
  975. $this->return_home_course('error_iassign_name');
  976. die();
  977. }
  978. // Really insert the new iActivity in table '*_iassign_statement'
  979. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  980. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  981. // Trigger module viewed event.
  982. $event = \mod_iassign\event\iassign_created::create(array(
  983. 'objectid' => $iassignid,
  984. 'context' => $context
  985. ));
  986. $event->add_record_snapshot('course', $this->course);
  987. $event->trigger();
  988. $this->return_home_course('iassign_add');
  989. } // if ($this->action == 'add')
  990. elseif ($this->action == 'edit') {
  991. $iassignid = $this->activity->update_iassign($result);
  992. $this->activity->update_calendar($iassignid, $result->oldname);
  993. // Trigger module viewed event.
  994. $event = \mod_iassign\event\iassign_updated::create(array(
  995. 'objectid' => $iassignid,
  996. 'context' => $context
  997. ));
  998. $event->add_record_snapshot('course', $this->course);
  999. $event->trigger();
  1000. $this->return_home_course('iassign_update');
  1001. } // elseif ($this->action == 'edit')
  1002. die();
  1003. } // if ($result)
  1004. } // else if ($mform->is_cancelled())
  1005. print $OUTPUT->header();
  1006. $mform->display();
  1007. print $OUTPUT->footer();
  1008. die();
  1009. } // function add_edit_iassign()
  1010. /// Search for dependencies
  1011. function search_dependency ($search_iassing_id, $iassign_statement) {
  1012. global $DB, $OUTPUT;
  1013. $dependency = "";
  1014. if ($iassign_statement)
  1015. foreach ($iassign_statement as $iassign) {
  1016. $inter_dependency = explode(';', $iassign->dependency);
  1017. if (in_array($search_iassing_id, $inter_dependency)) {
  1018. $dependency .= $iassign->id . ";";
  1019. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1020. } // if (in_array($search_iassing_id, $inter_dependency))
  1021. } // foreach ($iassign_statement as $iassign)
  1022. return $dependency;
  1023. }
  1024. /// Search for "sub"dependency
  1025. function search_sub_dependency ($search_iassing_id) {
  1026. global $DB, $OUTPUT;
  1027. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1028. $dependency = "";
  1029. if ($iassign_statement) {
  1030. $inter_dependency = explode(';', $iassign_statement->dependency);
  1031. foreach ($inter_dependency as $tmp) {
  1032. if ($tmp != 0)
  1033. $dependency .= $tmp . ";";
  1034. $dependency .= $this->search_sub_dependency($tmp);
  1035. } // foreach ($inter_dependency as $tmp)
  1036. } // if ($iassign_statement)
  1037. return $dependency;
  1038. }
  1039. // Warning message
  1040. static function warning_message_iassign ($strcode) {
  1041. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1042. }
  1043. /// Update grade of iAssign
  1044. // Called always any iAssign activity is created
  1045. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1046. static function update_grade_iassign ($iassignid) {
  1047. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1048. require_once($CFG->libdir . '/gradelib.php');
  1049. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1050. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1051. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1052. // Each iAssign item is associated with one item on the "gradebook"
  1053. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1054. //$sum_grade = 0;
  1055. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1056. //foreach($grade as $tmp) {
  1057. // $sum_grade += $tmp->grade;
  1058. // }
  1059. //1 Solution 1
  1060. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1061. //1 $sum_grade = 0; //1
  1062. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1063. //2 Solution 2
  1064. $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
  1065. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1066. if (key($array_sum_grade))
  1067. $sum_grade = key($array_sum_grade); //2
  1068. else
  1069. $sum_grade = 0; //2
  1070. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1071. $grades = NULL;
  1072. $params = array('itemname' => $grade_iassign->name);
  1073. $params['iteminstance'] = $iassignid;
  1074. $params['gradetype'] = GRADE_TYPE_VALUE;
  1075. //2016 if ($sum_grade != 0) {
  1076. $params['grademax'] = $sum_grade;
  1077. $params['rawgrademax'] = $sum_grade;
  1078. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1079. $params['grademin'] = 0;
  1080. // @calls /lib/gradelib.php: call to grade_item->insert()
  1081. //TODO: is there any error here in Moodle version 3.0?
  1082. //TODO: Incorrect property 'grademax' found when inserting grade object
  1083. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1084. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1085. }
  1086. /// Update grade of student
  1087. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1088. global $CFG, $DB, $OUTPUT;
  1089. require_once($CFG->libdir . '/gradelib.php');
  1090. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1091. // Review all the student submission for this iAssign activity
  1092. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1093. $total_grade = 0;
  1094. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1095. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1096. if ($iassign_submission)
  1097. $total_grade += $iassign_submission->grade;
  1098. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1099. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1100. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1101. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1102. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1103. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1104. $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
  1105. if (key($array_sum_grade))
  1106. $sum_grade = key($array_sum_grade); //2
  1107. else
  1108. $sum_grade = 0; //2
  1109. $grades['userid'] = $userid;
  1110. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1111. $params = array('itemname' => $grade_iassign->name);
  1112. $params['iteminstance'] = $iassignid;
  1113. $params['gradetype'] = GRADE_TYPE_VALUE;
  1114. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1115. $params['grademax'] = $sum_grade;
  1116. $params['rawgrademax'] = $sum_grade;
  1117. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1118. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1119. }
  1120. /// Display caption of icons
  1121. function view_legend_icons () {
  1122. global $USER, $CFG, $DB, $OUTPUT;
  1123. $id = $this->cm->id;
  1124. if ($this->action == 'print')
  1125. print '<table border=1 width=100%><tr>';
  1126. else
  1127. print '<table width=100%><tr>';
  1128. print '<td >';
  1129. if ($this->action != 'print')
  1130. print $OUTPUT->help_icon('legend', 'iassign');
  1131. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1132. // $imagetext = '');
  1133. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1134. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1135. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1136. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1137. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1138. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1139. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1140. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1141. print '</td>' . "\n";
  1142. if ($this->action != 'print') {
  1143. $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>";
  1144. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('graphic', 'iassign') . "</a>";
  1145. $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>";
  1146. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1147. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1148. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1149. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1150. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1151. } // if ($this->action != 'print')
  1152. print '</tr></table>' . "\n";
  1153. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1154. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1155. $link_stats = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=stats_student&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('results') . '&nbsp;' . get_string('results', 'iassign') . "</a>";
  1156. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1157. print '</tr></table>' . "\n";
  1158. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1159. else
  1160. print '</td></tr></table>' . "\n";
  1161. } // function view_legend_icons()
  1162. /// Display activity current
  1163. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1164. function view_iassign_current () {
  1165. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1166. $id = $this->cm->id;
  1167. $iassignid = $this->iassign->id;
  1168. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1169. $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
  1170. // 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 ...
  1171. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1172. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1173. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1174. // 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
  1175. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1176. // log record
  1177. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1178. //Trigger module viewed event.
  1179. $event = \mod_iassign\event\submission_viewed::create(array(
  1180. 'objectid' => $iassign->id,
  1181. 'context' => $this->context,
  1182. 'other' => $info
  1183. ));
  1184. $event->add_record_snapshot('course', $this->course);
  1185. $event->trigger();
  1186. print $OUTPUT->header();
  1187. // Search of iLM data used in the current activity
  1188. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1189. if ($this->action == 'viewsubmission') {
  1190. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1191. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1192. else
  1193. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1194. } else {
  1195. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1196. }
  1197. if ($iassign_submission)
  1198. $this->update_comment($iassign_submission->id);
  1199. $file = $iassign_statement_activity_item->file;
  1200. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1201. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1202. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1203. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1204. $this->bottonPost = 0; // hide submit button
  1205. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1206. $this->view_iassign = false; // disable visualization of activity
  1207. $repeat = "";
  1208. $last_iassign = "";
  1209. $student_answer = "";
  1210. $comment = "";
  1211. // *** Teacher access (view learner's submission)
  1212. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1213. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1214. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1215. // ---> access teacher for test
  1216. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1217. $this->bottonPost = 1;
  1218. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1219. $this->activity->view_dates();
  1220. $USER->iassignEdit = $this->bottonPost;
  1221. $this->activity->show_info_iassign();
  1222. if ($iassign_submission) {
  1223. //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;
  1224. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1225. } else {
  1226. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1227. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1228. }
  1229. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1230. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1231. // Prepare tags to present the iLM
  1232. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1233. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1234. // *** (end) Teacher access (view the activity)
  1235. // *** Teacher access (view learner's submission to the activity)
  1236. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1237. // It is teacher or 'nonediting teacher' that can evaluate
  1238. // ----> area teacher evaluate
  1239. $row = optional_param('row', 0, PARAM_INT);
  1240. $column = optional_param('column', 0, PARAM_INT);
  1241. $link_next = iassign_icons::insert('right_disable');
  1242. $link_previous = iassign_icons::insert('left_disable');
  1243. $link_up = iassign_icons::insert('up_disable');
  1244. $link_down = iassign_icons::insert('down_disable');
  1245. // next_activity
  1246. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1247. $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);
  1248. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1249. }
  1250. // previous_activity
  1251. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1252. $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);
  1253. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1254. }
  1255. // previous_student
  1256. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1257. $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);
  1258. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1259. }
  1260. // next_student
  1261. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1262. $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);
  1263. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1264. }
  1265. if ($iassign_submission) {
  1266. $student_answer = $iassign_submission->answer;
  1267. }
  1268. $last_iassign = get_string('last_iassign', 'iassign');
  1269. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1270. // Messages related to due date (and user role)
  1271. $this->activity->view_dates();
  1272. print $OUTPUT->box_start();
  1273. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1274. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1275. print $OUTPUT->user_picture($user_data);
  1276. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1277. print '</td>' . "\n";
  1278. print '<td width=20% align=right>' . "\n";
  1279. print '<table width=50 cellpadding="0">';
  1280. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1281. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1282. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1283. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1284. print '</table>' . "\n";
  1285. print '</td></tr></table>' . "\n";
  1286. print $OUTPUT->box_end();
  1287. print $OUTPUT->box_start();
  1288. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1289. print '<td width=60% valign="top">' . "\n";
  1290. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1291. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1292. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1293. $resp = get_string('yes');
  1294. else
  1295. $resp = get_string('no');
  1296. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1297. if ($iassign_statement_activity_item->show_answer == 1)
  1298. $resp = get_string('yes');
  1299. else
  1300. $resp = get_string('no');
  1301. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1302. print '</td>';
  1303. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1304. print '<td width=40% valign="top" align="left">';
  1305. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1306. // check status of solution sent by the student
  1307. if ($iassign_submission) {
  1308. switch ($iassign_submission->status) {
  1309. case 3 :
  1310. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1311. break;
  1312. case 2 :
  1313. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1314. break;
  1315. case 1 :
  1316. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1317. break;
  1318. default :
  1319. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1320. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1321. } // switch ($iassign_submission->status)
  1322. }
  1323. else { // if ($iassign_submission)
  1324. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1325. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1326. }
  1327. // update_status
  1328. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1329. $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);
  1330. print " <script type='text/javascript'>
  1331. //<![CDATA[
  1332. function overwriteStatus (newstatus) {
  1333. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1334. document.formEditStatus.return_status.value=newstatus;
  1335. document.formEditStatus.submit();
  1336. }
  1337. else
  1338. document.formEditStatus.return_status.value=-1;
  1339. }
  1340. //]]>
  1341. </script>";
  1342. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1343. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1344. 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";
  1345. print " <input type='hidden' name='return_status'>\n";
  1346. print "</form>\n";
  1347. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1348. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1349. $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);
  1350. print "
  1351. <script type='text/javascript'>
  1352. //<![CDATA[
  1353. function overwriteGrade (newgrade,maxgrade) {
  1354. if (newgrade<0 || newgrade>maxgrade) {
  1355. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1356. document.formEditGrade.return_grade.value=-1;
  1357. document.formEditGrade.submit();
  1358. }
  1359. else {
  1360. document.formEditGrade.return_grade.value=newgrade;
  1361. document.formEditGrade.submit();
  1362. }
  1363. }
  1364. //]]>
  1365. </script>";
  1366. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1367. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1368. print " <input type='text' name='grade' size='6'>";
  1369. print " <input type='hidden' name='return_grade'> ";
  1370. 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";
  1371. print "</form>";
  1372. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1373. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1374. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1375. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1376. if ($teacher)
  1377. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1378. } // if ($iassign_submission->experiment > 0)
  1379. print '</td>';
  1380. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1381. print '</tr></table>';
  1382. print $OUTPUT->box_end();
  1383. $USER->iassignEdit = $this->bottonPost;
  1384. if ($iassign_submission && $allow_resubmission) {
  1385. // Put the iLM to
  1386. print $OUTPUT->box_start();
  1387. print '<p><strong>' . $last_iassign . '</strong></p>';
  1388. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1389. $enderecoPOST = "";
  1390. // Prepare tags to present the iLM
  1391. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1392. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1393. print $OUTPUT->box_end();
  1394. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1395. // ATTENTION: exception used by iGeom (exercise with "script")
  1396. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1397. if (substr($ilm_name, 0, 5)=="igeom") {
  1398. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1399. $loadTeacherActivity = true;
  1400. }
  1401. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1402. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1403. // Prepare tags to present the iLM
  1404. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1405. }
  1406. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1407. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1408. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1409. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1410. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1411. // *** (end) Teacher access (view learner's submission to the activity)
  1412. // *** Student access (view the activity)
  1413. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1414. // It could be the learner (he could send or resend the activity)
  1415. // ---> access student
  1416. $time_now = time();
  1417. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1418. // activity of type example - not submit button for submission
  1419. $this->view_iassign = true;
  1420. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1421. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1422. // activity of type test - iLM automatic evaluator - submit button for submission
  1423. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1424. $this->bottonPost = 1;
  1425. $this->view_iassign = true;
  1426. } else
  1427. $this->view_iassign = false;
  1428. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1429. // activity of type exercise (learner can send his answer, if yet open...)
  1430. $this->view_iassign = true;
  1431. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1432. $this->view_iassign = false;
  1433. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1434. $this->bottonPost = 1; // allow the submit button
  1435. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1436. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1437. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1438. if (!$iassign_submission) {
  1439. $str_iassign_submission_id = '';
  1440. $str_iassign_submission_answer = '';
  1441. }
  1442. else {
  1443. $str_iassign_submission_id = $iassign_submission->id;
  1444. $str_iassign_submission_answer = $iassign_submission->answer;
  1445. }
  1446. if ($this->action != 'repeat') {
  1447. $repeat = "<a href='view.php?action=repeat&id="
  1448. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1449. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1450. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1451. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1452. }
  1453. $this->bottonPost = 1;
  1454. $this->write_solution = 1; // can register his submission
  1455. $student_answer = $str_iassign_submission_answer;
  1456. }
  1457. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1458. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1459. $last_iassign = get_string('last_iassign', 'iassign');
  1460. if ($iassign_submission) {
  1461. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1462. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1463. $student_answer = $iassign_submission->answer;
  1464. } else {
  1465. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1466. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1467. }
  1468. }
  1469. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1470. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1471. $this->bottonPost = 1;
  1472. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1473. } else {
  1474. $last_iassign = get_string('last_iassign', 'iassign');
  1475. if ($iassign_submission) {
  1476. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1477. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1478. $student_answer = $iassign_submission->answer;
  1479. } else {
  1480. // Symbol of "redo activity"
  1481. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1482. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1483. }
  1484. }
  1485. } // elseif ($iassign_statement_activity_item->test == 1)
  1486. elseif ($iassign_statement_activity_item->test == 0)
  1487. $this->view_iassign = false;
  1488. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1489. if ($iassign_submission)
  1490. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1491. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1492. else
  1493. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1494. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1495. $this->view_legend_icons();
  1496. $this->activity->view_dates();
  1497. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1498. print $OUTPUT->box_start();
  1499. print '<table width=100% border=0 valign="top">' . "\n";
  1500. print '<tr><td width=60% valign="top">' . "\n";
  1501. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1502. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1503. $flag_dependency = true;
  1504. if ($iassign_statement_activity_item->type_iassign == 3) {
  1505. if ($iassign_statement_activity_item->dependency == 0) {
  1506. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1507. } else {
  1508. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1509. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1510. foreach ($dependencys as $dependency) {
  1511. if ($dependency) {
  1512. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1513. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1514. if ($dependencysubmissions) {
  1515. if ($dependencysubmissions->status == 3)
  1516. $icon = iassign_icons::insert('correct');
  1517. elseif ($dependencysubmissions->status == 2) {
  1518. $icon = iassign_icons::insert('incorrect');
  1519. $flag_dependency = false;
  1520. } elseif ($dependencysubmissions->status == 1) {
  1521. $icon = iassign_icons::insert('post');
  1522. $flag_dependency = false;
  1523. } elseif ($dependencysubmissions->status == 0) {
  1524. $icon = iassign_icons::insert('not_post');
  1525. $flag_dependency = false;
  1526. }
  1527. } else {
  1528. $icon = iassign_icons::insert('not_post');
  1529. $flag_dependency = false;
  1530. } // if ($dependencysubmissions)
  1531. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1532. } // if ($dependency)
  1533. } // foreach ($dependencys as $dependency)
  1534. } // if ($iassign_statement_activity_item->dependency == 0)
  1535. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1536. if ($flag_dependency == false) {
  1537. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1538. $this->view_iassign = false;
  1539. print '</tr></table>' . "\n";
  1540. }
  1541. else {
  1542. $this->view_iassign = true;
  1543. print '</td>' . "\n";
  1544. } // if ($flag_dependency == false)
  1545. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1546. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1547. // receiver=1 - message to teacher
  1548. // receiver=2 - message to student
  1549. if ($iassign_submission) {
  1550. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1551. if ($verify_message)
  1552. $comment = iassign_icons::insert('comment_unread');
  1553. }
  1554. print '<td width=40% valign="top" align="left">';
  1555. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1556. if ($iassign_statement_activity_item->show_answer == 1) {
  1557. // check status of solution sent by the student
  1558. if ($iassign_submission) {
  1559. switch ($iassign_submission->status) {
  1560. case 3 :
  1561. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1562. break;
  1563. case 2 :
  1564. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1565. break;
  1566. case 1 :
  1567. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1568. break;
  1569. default :
  1570. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1571. $repeat = "";
  1572. $last_iassign = "";
  1573. } // switch ($iassign_submission->status)
  1574. } else {
  1575. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1576. $repeat = "";
  1577. $last_iassign = "";
  1578. }
  1579. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1580. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1581. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1582. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1583. if ($iassign_statement_activity_item->max_experiment == 0)
  1584. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1585. else {
  1586. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1587. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1588. $repeat = "";
  1589. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1590. $this->bottonPost = 0;
  1591. $this->write_solution = 0;
  1592. }
  1593. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1594. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  1595. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1596. if ($teacher)
  1597. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  1598. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  1599. } // if ($iassign_statement_activity_item->show_answer==1)
  1600. else {
  1601. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  1602. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1603. $repeat = "";
  1604. $last_iassign = "";
  1605. } elseif ($iassign_submission->status == 1) {
  1606. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1607. }
  1608. }
  1609. print '</td>';
  1610. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1611. print '</tr></table>' . "\n";
  1612. // Presents the iLM
  1613. print '<table width=100% border=0 valign="top">' . "\n";
  1614. print '<td width=80% align="left">';
  1615. 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\".
  1616. print '<td width=20% align="rigth">';
  1617. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  1618. print $repeat; // symbol of "redo activity"
  1619. print '</td></tr></table>' . "\n";
  1620. //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)'
  1621. $output = '';
  1622. if (!$iassign_ilm) {
  1623. $iassign_ilm = new stdClass();
  1624. $iassign_ilm->file_jar = "";
  1625. }
  1626. $output .= $OUTPUT->box_start();
  1627. $USER->iassignEdit = $this->bottonPost;
  1628. // ---
  1629. // Presents the iLM
  1630. // Prepare tags to present the iLM
  1631. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  1632. $student_answer = ""; //?
  1633. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  1634. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  1635. $student_answer = "";
  1636. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  1637. } else {
  1638. // When student is redoing his activity
  1639. // ATTENTION: exception used by iGeom (exercise with "script")
  1640. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  1641. if (substr($ilm_name, 0, 5)=="igeom") {
  1642. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1643. $loadTeacherActivity = true;
  1644. }
  1645. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  1646. }
  1647. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  1648. //1 $history_comment = '';
  1649. //1 if ($iassign_submission) {
  1650. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  1651. //1 }
  1652. //1 if (!empty($history_comment)) {
  1653. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1654. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1655. //1 $output .= $history_comment;
  1656. //1 $output .= "</table>\n";
  1657. //1 }
  1658. //1 $output .= "</form></center>\n";
  1659. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  1660. //1 }
  1661. $output .= $OUTPUT->box_end();
  1662. print $output;
  1663. } // if ($this->view_iassign)
  1664. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1665. } // if ($this->view_iassign)
  1666. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1667. else
  1668. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1669. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1670. print '<table width=100% border=0 valign="top">' . "\n";
  1671. print '<tr><td width=60% valign="top">' . "\n";
  1672. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1673. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1674. print '</tr></table>' . "\n";
  1675. $student_answer = "";
  1676. $enderecoPOST = "";
  1677. // Prepare tags to present the iLM
  1678. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1679. print $output;
  1680. }
  1681. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  1682. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1683. 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
  1684. // Put a block with area to sent/answer comments
  1685. $output = '';
  1686. $history_comment = '';
  1687. $row = optional_param('row', 0, PARAM_INT);
  1688. $column = optional_param('column', 0, PARAM_INT);
  1689. if ($iassign_submission) {
  1690. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1691. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1692. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1693. }
  1694. else {
  1695. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1696. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1697. }
  1698. $output .= $OUTPUT->box_start();
  1699. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1700. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1701. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1702. $output .= "</form></center>\n";
  1703. if (!empty($history_comment)) {
  1704. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1705. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1706. $output .= $history_comment;
  1707. $output .= "</table>";
  1708. }
  1709. $output .= $OUTPUT->box_end();
  1710. print $output;
  1711. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1712. // final block 'studant'
  1713. print $OUTPUT->footer();
  1714. die();
  1715. } // function view_iassign_current()
  1716. /// Export the data from performance report into CSV file format
  1717. function export_csv () {
  1718. global $USER, $CFG, $DB, $OUTPUT;
  1719. $str = "";
  1720. $fields = "student_id, student_name";
  1721. // Finding all iassign activities for the iassign:
  1722. $id = $this->cm->id;
  1723. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1724. $c = 1;
  1725. foreach ($iassign_list as $iassign) {
  1726. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1727. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1728. $c ++;
  1729. }
  1730. // Finding enrolled students:
  1731. $params = array('shortname' => 'student');
  1732. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  1733. $context = context_course::instance($this->course->id);
  1734. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1735. $students = $DB->get_records_sql(
  1736. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1737. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1738. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1739. foreach ($students as $student) {
  1740. $str .= $student->userid . ',';
  1741. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1742. foreach ($iassign_list as $iassign) {
  1743. $str .= ',' . $iassign->id . ',';
  1744. $str .= '"' . $iassign->name . '",';
  1745. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1746. $str .= $student_submissions->experiment . ',';
  1747. $str .= $student_submissions->grade . ',';
  1748. switch ($student_submissions->status) {
  1749. case 3:
  1750. $str .= '"correct",';
  1751. break;
  1752. case 2:
  1753. $str .= '"incorrect",';
  1754. break;
  1755. case 1:
  1756. $str .= '"post",';
  1757. break;
  1758. case 0:
  1759. $str .= '"not_post",';
  1760. break;
  1761. }
  1762. $str .= $iassign->iassign_ilmid . ',';
  1763. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1764. $str .= '"' . $ilm_activity->name . '"';
  1765. }
  1766. $str .= "\n";
  1767. }
  1768. $str = $fields . "\n" . $str;
  1769. header("Content-disposition: attachment; filename=report.csv");
  1770. header("Pragma: no-cache");
  1771. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1772. header('Content-Length: ' . strlen($str));
  1773. header('Connection: close');
  1774. print $str;
  1775. flush();
  1776. } // function export_csv()
  1777. /// Display report of performance
  1778. function report () {
  1779. global $USER, $CFG, $DB, $OUTPUT;
  1780. $id = $this->cm->id;
  1781. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1782. if ($this->action != 'print') {
  1783. $title = get_string('report', 'iassign');
  1784. print $OUTPUT->header();
  1785. } // if ($this->action != 'print')
  1786. print $OUTPUT->box_start();
  1787. $this->view_legend_icons();
  1788. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1789. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1790. print $OUTPUT->box_end();
  1791. if ($this->action == 'print')
  1792. print '<table border=1 width="100%">' . "\n";
  1793. else
  1794. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1795. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1796. // $num = array();
  1797. $i = 1;
  1798. $num = array();
  1799. foreach ($iassign_list as $iassign) {
  1800. $test_exercise = "";
  1801. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1802. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1803. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1804. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1805. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1806. $num[$i] = new stdClass();
  1807. $num[$i]->name = $iassign->name;
  1808. $num[$i]->id = $i;
  1809. $num[$i]->iassignid = $iassign->id;
  1810. print ' <tr >' . "\n";
  1811. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1812. print "<td class=\"cell c0 actvity\">";
  1813. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1814. print ' </tr>' . "\n";
  1815. $i ++;
  1816. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1817. } // foreach ($iassign_list as $iassign)
  1818. print "</table>";
  1819. print "<p></p>";
  1820. if ($this->action == 'print')
  1821. print '<table border=1 width="100%">' . "\n";
  1822. else
  1823. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1824. $context = context_course::instance($this->course->id);
  1825. if ($i > 1) {
  1826. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1827. $params = array('shortname' => 'student');
  1828. $role = $DB->get_record_sql(
  1829. "SELECT s.id, s.shortname FROM {role} s " .
  1830. " WHERE s.shortname = :shortname", $params);
  1831. // $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");
  1832. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1833. $students = $DB->get_records_sql(
  1834. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1835. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1836. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1837. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1838. for ($j = 1; $j < $i; $j ++) {
  1839. $sum_iassign_correct[$j] = 0;
  1840. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1841. }
  1842. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1843. $sum_iassign = $j - 1;
  1844. print '</tr>' . "\n";
  1845. $total = 0;
  1846. $sum_student = 0;
  1847. $comment = iassign_icons::insert('comment_read');
  1848. $sum_comment = 0;
  1849. $sum_correct_iassign = array();
  1850. $sum_correct_student = array();
  1851. $USER->matrix_iassign = array();
  1852. if ($students) {
  1853. $w = 0;
  1854. foreach ($students as $tmp) {
  1855. $users_array[$w] = $tmp;
  1856. $w ++;
  1857. }
  1858. for ($x = 0; $x < $w; $x ++) {
  1859. print '<tr>' . "\n";
  1860. $sum_student ++;
  1861. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1862. print ' <td >' . $name . '</td>' . "\n";
  1863. $total_student = 0;
  1864. $tentativas = 0;
  1865. for ($j = 1; $j < $i; $j ++) {
  1866. $sum_comment = 0;
  1867. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1868. print ' <td valign="bottom" align="center">' . "\n";
  1869. if ($student_submissions) {
  1870. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1871. $tentativas = $student_submissions->experiment;
  1872. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1873. $params = array('iassign_submissionid' => $student_submissions->id);
  1874. $student_submissions_comment = $DB->get_record_sql(
  1875. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1876. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1877. if ($student_submissions_comment)
  1878. foreach ($student_submissions_comment as $tmp)
  1879. $sum_comment = $tmp;
  1880. // informations to previous activities
  1881. if ($j - 1 < 1 || $j == $i)
  1882. $iassign_previous = "-1";
  1883. else
  1884. $iassign_previous = $num[$j - 1]->iassignid;
  1885. if ($x - 1 < 0 || $x == $w)
  1886. $user_previous = "-1";
  1887. else
  1888. $user_previous = $users_array[$x - 1]->userid;
  1889. // next
  1890. if ($i - 1 > $j)
  1891. $iassign_next = $num[$j + 1]->iassignid;
  1892. else
  1893. $iassign_next = "-1";
  1894. if ($w - 1 > $x)
  1895. $user_next = $users_array[$x + 1]->userid;
  1896. else
  1897. $user_next = "-1";
  1898. $position = "&row= $x&column=$j";
  1899. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1900. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1901. $url .= $position;
  1902. // receiver=1 - message to teacher
  1903. // receiver=2 - message to student
  1904. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1905. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1906. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1907. $verify_message = $DB->get_record_sql(
  1908. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1909. "WHERE iassign_submissionid = :iassign_submissionid " .
  1910. " AND return_status= :return_status " .
  1911. " AND receiver= :receiver", $params);
  1912. if ($verify_message)
  1913. foreach ($verify_message as $tmp)
  1914. $sum_verify_message = $tmp;
  1915. if ($sum_verify_message > 0)
  1916. $comment = iassign_icons::insert('comment_unread');
  1917. else
  1918. $comment = iassign_icons::insert('comment_read');
  1919. if ($student_submissions->status == 3) {
  1920. $sum_iassign_correct[$j] ++;
  1921. $total_student ++;
  1922. $feedback = iassign_icons::insert('correct');
  1923. }
  1924. elseif ($student_submissions->status == 2) {
  1925. $feedback = iassign_icons::insert('incorrect');
  1926. }
  1927. elseif ($student_submissions->status == 1) {
  1928. $feedback = iassign_icons::insert('post');
  1929. }
  1930. elseif ($student_submissions->status == 0) {
  1931. $feedback = iassign_icons::insert('not_post');
  1932. }
  1933. if ($this->action != 'print') {
  1934. print '<table><tr>';
  1935. if ($tentativas > 0)
  1936. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  1937. else
  1938. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  1939. print '<td> &nbsp; </td>';
  1940. print '</tr>' . "\n";
  1941. if ($sum_comment > 0 && $sum_verify_message > 0)
  1942. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  1943. else if ($sum_comment > 0)
  1944. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  1945. print '</table>' . "\n";
  1946. }
  1947. if ($this->action == 'print')
  1948. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1949. } // if ($student_submissions)
  1950. else { // if ($student_submissions)
  1951. // informations to browse previous activities
  1952. if ($j - 1 < 1 || $j == $i)
  1953. $iassign_previous = "-1";
  1954. else
  1955. $iassign_previous = $num[$j - 1]->iassignid;
  1956. if ($x - 1 < 0 || $x == $w)
  1957. $user_previous = "-1";
  1958. else
  1959. $user_previous = $users_array[$x - 1]->userid;
  1960. // next
  1961. if ($i - 1 > $j)
  1962. $iassign_next = $num[$j + 1]->iassignid;
  1963. else
  1964. $iassign_next = "-1";
  1965. if ($w - 1 > $x)
  1966. $user_next = $users_array[$x + 1]->userid;
  1967. else
  1968. $user_next = "-1";
  1969. $position = "&row= $x&column=$j";
  1970. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  1971. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1972. $url .= $position;
  1973. $feedback = iassign_icons::insert('not_post');
  1974. if ($this->action == 'print')
  1975. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1976. else {
  1977. print '<table><tr>';
  1978. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  1979. print '<td> &nbsp; </td>';
  1980. print '</tr><tr>' . "\n";
  1981. print '<td> &nbsp;</td>';
  1982. if ($sum_comment > 0)
  1983. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  1984. else
  1985. print '<td> &nbsp;</td>';
  1986. print '</tr></table>';
  1987. }
  1988. } // else if ($student_submissions)
  1989. $USER->matrix_iassign[$x][$j] = new stdClass();
  1990. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  1991. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  1992. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  1993. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  1994. if ($student_submissions)
  1995. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  1996. else
  1997. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  1998. print '</td>' . "\n";
  1999. } // for ($j=1; $j<$i; $j++)
  2000. $total = $total + $total_student;
  2001. $porcentagem = ($total_student / ($j - 1)) * 100;
  2002. if ($tentativas != 0 && $tentativas != null) {
  2003. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2004. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2005. }
  2006. else {
  2007. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2008. }
  2009. print '</tr>' . "\n";
  2010. $sum_correct_student[$sum_student] = new stdClass();
  2011. $sum_correct_student[$sum_student]->name = $name;
  2012. $sum_correct_student[$sum_student]->sum = $total_student;
  2013. } // for ($x = 0; $x < $w; $x ++)
  2014. for ($i = 1; $i < $j; $i ++) {
  2015. if (is_null($sum_iassign_correct[$i]))
  2016. $sum_iassign_correct[$i] = 0;
  2017. $sum_correct_iassign[$i] = new stdClass();
  2018. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2019. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2020. }
  2021. // print '</tr></table>' . "\n";
  2022. }
  2023. } // if ($i>1)
  2024. else {
  2025. print_string('no_activity', 'iassign');
  2026. }
  2027. print "</table>\n";
  2028. if ($this->action != 'print')
  2029. print $OUTPUT->footer();
  2030. die();
  2031. } // function report()
  2032. /// Display graphics of performance
  2033. function stats () {
  2034. global $USER, $CFG, $DB, $OUTPUT;
  2035. $id = $this->cm->id;
  2036. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2037. if ($this->action != 'printstats')
  2038. $title = get_string('graphic', 'iassign');
  2039. $num = array();
  2040. $sum_correct_iassign = array();
  2041. $sum_correct_student = array();
  2042. $sum_student = 0;
  2043. $i = 1;
  2044. foreach ($iassign_list as $iassign) {
  2045. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2046. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2047. $sum_iassign_correct[$i] = 0;
  2048. $num[$i] = new stdClass();
  2049. $num[$i]->name = $iassign->name;
  2050. $num[$i]->id = $i;
  2051. $num[$i]->iassignid = $iassign->id;
  2052. $i ++;
  2053. } // if ($iassign->type_iassign == 3)
  2054. } // foreach ($iassign_list as $iassign)
  2055. $sum_iassign = $i - 1;
  2056. $context = context_course::instance($this->course->id);
  2057. if ($i > 1) {
  2058. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2059. $params = array('shortname' => 'student');
  2060. $role = $DB->get_record_sql(
  2061. "SELECT s.id, s.shortname FROM {role} s " .
  2062. " WHERE s.shortname = :shortname", $params);
  2063. // $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");
  2064. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2065. $students = $DB->get_records_sql(
  2066. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2067. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2068. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2069. $total = 0;
  2070. $sum_student = 0;
  2071. $j = 0;
  2072. $sum_correct_iassign = array();
  2073. $sum_correct_student = array();
  2074. $sum_experiment = array();
  2075. if ($students) {
  2076. foreach ($students as $users) {
  2077. $sum_student ++;
  2078. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2079. // rows
  2080. $total_student = 0;
  2081. for ($j = 1; $j < $i; $j ++) {
  2082. $total_experiment = 0;
  2083. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2084. if ($student_submissions) {
  2085. if ($student_submissions->status == 3) {
  2086. $sum_iassign_correct[$j] ++;
  2087. $total_student ++;
  2088. } // if ($student_submissions->status == 3)
  2089. $total_experiment += $student_submissions->experiment;
  2090. }
  2091. $sum_experiment[$j] = $total_experiment;
  2092. } // for ($j=1; $j<$i; $j++)
  2093. $total = $total + $total_student;
  2094. $sum_correct_student[$sum_student] = new stdClass();
  2095. $sum_correct_student[$sum_student]->name = $name;
  2096. $sum_correct_student[$sum_student]->sum = $total_student;
  2097. } // foreach ($students as $users)
  2098. }
  2099. for ($i = 1; $i < $j; $i ++) {
  2100. if (is_null($sum_iassign_correct[$i]))
  2101. $sum_iassign_correct[$i] = 0;
  2102. $sum_correct_iassign[$i] = new stdClass();
  2103. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2104. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2105. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2106. } // for ($i = 1; $i < $j; $i++)
  2107. } // if ($i > 1)
  2108. if ($this->action != 'printstats') {
  2109. $title = get_string('graphic', 'iassign');
  2110. print $OUTPUT->header();
  2111. $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>";
  2112. $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>";
  2113. print '<table width=100%><tr>';
  2114. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2115. print '<td width=15% align="right">' . $link_report . '</td>';
  2116. print '</td></tr></table>' . "\n";
  2117. print "<br><br>";
  2118. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2119. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2120. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2121. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2122. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2123. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2124. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2125. print '</tr>' . "\n";
  2126. $sum_correct = 0;
  2127. if ($sum_correct_iassign) {
  2128. foreach ($sum_correct_iassign as $iassign) {
  2129. if (is_null($iassign->experiment))
  2130. $iassign->experiment = 0;
  2131. $bar = "";
  2132. $sum = $iassign->sum;
  2133. $percent = ($sum / $sum_student) * 100;
  2134. $text = number_format($percent, 1) . '%';
  2135. $sum_correct += $sum;
  2136. if ($sum > 0) {
  2137. for ($i = 1; $i < $percent * 2; $i ++)
  2138. $bar .= iassign_icons::insert('hbar_blue');
  2139. $bar .= iassign_icons::insert('hbar_blue_r');
  2140. } // if ($sum > 0)
  2141. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2142. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2143. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2144. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2145. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2146. print '</tr>' . "\n";
  2147. } // foreach ($sum_correct_iassign as $iassign)
  2148. }
  2149. print "</table>";
  2150. print "<br><br>";
  2151. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2152. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2153. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2154. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2155. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2156. print '</tr>' . "\n";
  2157. $sum_correct = 0;
  2158. foreach ($sum_correct_student as $student) {
  2159. $bar = "";
  2160. $sum = $student->sum;
  2161. $percent = ($sum / $sum_iassign) * 100;
  2162. $text = number_format($percent, 1) . '%';
  2163. $sum_correct += $sum;
  2164. if ($sum > 0) {
  2165. for ($i = 1; $i < $percent * 2; $i ++)
  2166. $bar .= iassign_icons::insert('hbar_blue');
  2167. $bar .= iassign_icons::insert('hbar_blue_r');
  2168. } // if ($sum > 0)
  2169. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2170. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2171. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2172. print '</tr>' . "\n";
  2173. } // foreach ($sum_correct_student as $student)
  2174. print "</table>\n";
  2175. print "<br><br>\n";
  2176. $var = 0;
  2177. $cv = 0;
  2178. $dv = 0;
  2179. $avg = 0;
  2180. if ($sum_correct_student) {
  2181. $avg = $sum_correct / $sum_student;
  2182. if ($avg > 0) {
  2183. foreach ($sum_correct_student as $student)
  2184. $var += pow($student->sum - $avg, 2);
  2185. $var = $var / $sum_student;
  2186. $dv = sqrt($var);
  2187. $cv = ($dv / $avg) * 100;
  2188. }
  2189. }
  2190. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2191. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2192. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2193. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2194. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2195. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2196. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2197. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2198. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2199. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2200. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2201. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2202. print "</table>\n";
  2203. print $OUTPUT->footer();
  2204. } else {
  2205. print "<STYLE TYPE='text/css'>
  2206. <!--
  2207. .boldtable {
  2208. font-family:sans-serif;
  2209. font-size:10pt;
  2210. }
  2211. -->
  2212. </STYLE>\n";
  2213. print '<table border=1 width=100%>' . "\n";
  2214. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2215. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2216. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2217. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2218. print '</tr>' . "\n";
  2219. $sum_correct = 0;
  2220. foreach ($sum_correct_iassign as $iassign) {
  2221. $bar = "";
  2222. $sum = $iassign->sum;
  2223. $percent = ($sum / $sum_student) * 100;
  2224. $text = number_format($percent, 1) . '%';
  2225. $sum_correct += $sum;
  2226. if ($sum > 0) {
  2227. for ($i = 1; $i < $percent * 2; $i ++)
  2228. $bar .= iassign_icons::insert('hbar_blue');
  2229. $bar .= iassign_icons::insert('hbar_blue_r');
  2230. } // if ($sum > 0)
  2231. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2232. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2233. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2234. print '</tr>' . "\n";
  2235. } // foreach ($sum_correct_iassign as $iassign)
  2236. print "</table>";
  2237. print "<br><br>";
  2238. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2239. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2240. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2241. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2242. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2243. print '</tr>' . "\n";
  2244. $sum_correct = 0;
  2245. foreach ($sum_correct_student as $student) {
  2246. $bar = "";
  2247. $sum = $student->sum;
  2248. $percent = ($sum / $sum_iassign) * 100;
  2249. $text = number_format($percent, 1) . '%';
  2250. $sum_correct += $sum;
  2251. if ($sum > 0) {
  2252. for ($i = 1; $i < $percent * 2; $i ++)
  2253. $bar .= iassign_icons::insert('hbar_blue');
  2254. $bar .= iassign_icons::insert('hbar_blue_r');
  2255. } // if ($sum > 0)
  2256. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2257. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2258. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2259. print '</tr>' . "\n";
  2260. } // foreach ($sum_correct_student as $student)
  2261. print "</table>\n";
  2262. print "<br/><br/>\n";
  2263. $var = 0;
  2264. $cv = 0;
  2265. $dv = 0;
  2266. $avg = 0;
  2267. if ($sum_correct_student) {
  2268. $avg = $sum_correct / $sum_student;
  2269. if ($avg > 0) {
  2270. foreach ($sum_correct_student as $student)
  2271. $var += pow($student->sum - $avg, 2);
  2272. $var = $var / $sum_student;
  2273. $dv = sqrt($var);
  2274. $cv = ($dv / $avg) * 100;
  2275. }
  2276. }
  2277. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2278. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2279. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2280. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2281. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2282. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2283. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2284. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2285. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2286. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2287. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2288. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2289. print "</table>\n";
  2290. } // if ($this->action != 'printstats')
  2291. die();
  2292. }
  2293. /// Display graphics of performance for students
  2294. function stats_students () {
  2295. global $USER, $CFG, $DB, $OUTPUT;
  2296. $id = $this->cm->id;
  2297. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2298. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2299. $title = get_string('results', 'iassign');
  2300. $sum_correct = 0;
  2301. $sum_incorrect = 0;
  2302. $sum_post = 0;
  2303. $sum_nopost = 0;
  2304. $sum_iassign = count($iassign_statement_list);
  2305. $bar_nopost = "";
  2306. $bar_correct = "";
  2307. $bar_incorrect = "";
  2308. $bar_post = "";
  2309. $text_nopost = "";
  2310. $text_correct = "";
  2311. $text_incorrect = "";
  2312. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2313. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2314. if ($iassign_submission) {
  2315. if ($iassign_submission->status == 3)
  2316. $sum_correct ++;
  2317. elseif ($iassign_submission->status == 2)
  2318. $sum_incorrect ++;
  2319. elseif ($iassign_submission->status == 1)
  2320. $sum_post ++;
  2321. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2322. $sum_nopost ++;
  2323. } // if ($iassign_submission)
  2324. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2325. if ($sum_iassign > 0) {
  2326. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2327. $text_correct = number_format($percent_correct, 1) . '%';
  2328. }
  2329. if ($sum_correct > 0) {
  2330. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2331. $bar_correct .= iassign_icons::insert('hbar_green');
  2332. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2333. } // if ($sum_correct > 0)
  2334. if ($sum_iassign > 0) {
  2335. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2336. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2337. }
  2338. if ($sum_incorrect > 0) {
  2339. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2340. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2341. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2342. } // if ($sum_incorrect > 0)
  2343. if ($sum_iassign > 0) {
  2344. $percent_post = ($sum_post / $sum_iassign) * 100;
  2345. $text_post = number_format($percent_post, 1) . '%';
  2346. }
  2347. if ($sum_post > 0) {
  2348. for ($i = 1; $i < $percent_post * 2; $i ++)
  2349. $bar_post .= iassign_icons::insert('hbar_blue');
  2350. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2351. } // if ($sum_post > 0)
  2352. if ($sum_iassign > 0) {
  2353. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2354. $text_nopost = number_format($percent_nopost, 1) . '%';
  2355. }
  2356. if ($sum_nopost > 0) {
  2357. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2358. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2359. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2360. } // if ($sum_nopost > 0)
  2361. print $OUTPUT->header();
  2362. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2363. print '<table width=100%><tr>';
  2364. print '<td align="right">' . $link_return . '</td>' . "\n";
  2365. print '</td></tr></table>' . "\n";
  2366. print "<br/><br/>\n";
  2367. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2368. print '<tr><th colspan=3 class="header c1">' . "\n";
  2369. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2370. // $imagetext = '');
  2371. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2372. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2373. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2374. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2375. print '</tr>' . "\n";
  2376. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2377. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2378. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2379. print '</tr>' . "\n";
  2380. if ($sum_post) {
  2381. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2382. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2383. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2384. print '</tr>' . "\n";
  2385. } // if ($sum_post)
  2386. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2387. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2388. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2389. print '</tr>' . "\n";
  2390. print "</table>";
  2391. print "<br><br>";
  2392. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2393. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2394. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2395. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2396. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2397. $sum_grade = 0;
  2398. $sum_grade_student = 0;
  2399. $avg = 0;
  2400. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2401. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2402. if (!$iassign_submission) {
  2403. $iassign_submission = new stdClass();
  2404. $iassign_submission->grade = 0;
  2405. }
  2406. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2407. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2408. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2409. print '</tr>' . "\n";
  2410. $sum_grade += $iassign_statement_activity_item->grade;
  2411. $sum_grade_student += $iassign_submission->grade;
  2412. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2413. if ($sum_grade > 0)
  2414. $avg = $sum_grade_student / $sum_grade * 100;
  2415. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2416. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2417. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2418. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2419. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2420. print "</table>";
  2421. print $OUTPUT->footer();
  2422. die();
  2423. } // function stats_students()
  2424. /// Display page of iAssign's activity
  2425. function view_iassigns () {
  2426. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2427. $id = $this->cm->id;
  2428. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2429. $notice = optional_param('notice', '', PARAM_TEXT);
  2430. if (strpos($notice, 'error'))
  2431. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2432. else if ($notice != '')
  2433. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2434. print $OUTPUT->box_start();
  2435. print '<table width=100% border=0><tr>' . "\n";
  2436. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2437. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2438. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2439. $link_add = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=add&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('add_iassign') . get_string('add_iassign', 'iassign') . "</a>";
  2440. $link_report = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('view_report') . get_string('report', 'iassign') . "</a>";
  2441. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2442. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2443. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2444. // Has capability to see "report": teacher or up
  2445. print '<td width=10% align="left">' . "\n";
  2446. print $link_help;
  2447. print '</td>' . "\n";
  2448. print '<td width=10% align="left">' . "\n";
  2449. print $link_report;
  2450. print '</td>' . "\n";
  2451. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2452. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2453. print '<td width=15% align="left">' . "\n";
  2454. print $link_add;
  2455. print "</td>\n";
  2456. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2457. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2458. if ($iassign_list) {
  2459. print '<td align="right">' . "\n";
  2460. // $USER->iassignEdit == 0 view 'Turn editing off'
  2461. // $USER->iassignEdit == 1 view 'Turn editing on'
  2462. if (!isset($USER->iassignEdit))
  2463. $USER->iassignEdit = 0;
  2464. if ($USER->iassignEdit == 0) {
  2465. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2466. $botton = 1;
  2467. } // if ($USER->iassignEdit == 0)
  2468. elseif ($USER->iassignEdit == 1) {
  2469. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2470. $botton = 0;
  2471. } // elseif ($USER->iassignEdit == 1)
  2472. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2473. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2474. print " <input type=submit value='$bottonEdit_message'/>\n";
  2475. print "</form>\n";
  2476. print "</td>\n";
  2477. } // if ($iassign_list)
  2478. }
  2479. print '</tr></table>' . "\n";
  2480. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2481. $this->view_legend_icons();
  2482. print $OUTPUT->box_end();
  2483. $iassign_array_exercise = array();
  2484. $i_exercise = 0;
  2485. $iassign_array_test = array();
  2486. $i_test = 0;
  2487. $iassign_array_example = array();
  2488. $i_example = 0;
  2489. $iassign_array_general = array();
  2490. $i_general = 0;
  2491. if ($iassign_list) {
  2492. if ($this->iassign->activity_group == 0) {
  2493. foreach ($iassign_list as $iassign) {
  2494. $iassign_array_general[$i_general] = $iassign;
  2495. $i_general ++;
  2496. }
  2497. } // if ($this->iassign->activity_group == 0)
  2498. else {
  2499. foreach ($iassign_list as $iassign) {
  2500. if ($iassign->type_iassign == 3) {
  2501. $iassign_array_exercise[$i_exercise] = $iassign;
  2502. $i_exercise ++;
  2503. } // if ($iassign->type_iassign == 3)
  2504. if ($iassign->type_iassign == 2) {
  2505. $iassign_array_test[$i_test] = $iassign;
  2506. $i_test ++;
  2507. } // if ($iassign->type_iassign == 2)
  2508. if ($iassign->type_iassign == 1) {
  2509. $iassign_array_example[$i_example] = $iassign;
  2510. $i_example ++;
  2511. } // if ($iassign->type_iassign == 1)
  2512. }
  2513. }
  2514. if ($iassign_array_exercise) {
  2515. $title = get_string('exercise', 'iassign');
  2516. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2517. }
  2518. if ($iassign_array_test) {
  2519. $title = get_string('test', 'iassign');
  2520. $this->show_iassign($title, $iassign_array_test, $i_test);
  2521. }
  2522. if ($iassign_array_example) {
  2523. $title = get_string('example', 'iassign');
  2524. $this->show_iassign($title, $iassign_array_example, $i_example);
  2525. }
  2526. if ($iassign_array_general) {
  2527. $title = "";
  2528. $this->show_iassign($title, $iassign_array_general, $i_general);
  2529. }
  2530. } else { // if ($iassign_list)
  2531. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2532. }
  2533. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2534. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2535. print $OUTPUT->box_start();
  2536. print '<table width=100% border=0><tr>' . "\n";
  2537. print '<td width=10% align="left">' . "\n";
  2538. print $link_report;
  2539. print '</td>' . "\n";
  2540. print '</tr></table>' . "\n";
  2541. print $OUTPUT->box_end();
  2542. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2543. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2544. print $OUTPUT->box_start();
  2545. print '<table width=100% border=0><tr>' . "\n";
  2546. print '<td align="left">' . "\n";
  2547. print $link_add;
  2548. print '</td>' . "\n";
  2549. print '</tr></table>' . "\n";
  2550. print $OUTPUT->box_end();
  2551. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2552. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2553. } // function view_iassigns()
  2554. /// Display all iAssigns
  2555. function show_iassign ($title, $iassign_array, $i) {
  2556. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2557. $id = $this->cm->id;
  2558. print $OUTPUT->box_start();
  2559. print " <script type='text/javascript'>
  2560. //<![CDATA[
  2561. function validate_move () {
  2562. var radios = document.getElementsByName('iassign_destiny');
  2563. var formValid = false;
  2564. //alert('aqui validate_move()');
  2565. var i = 0;
  2566. while (!formValid && i < radios.length) {
  2567. if (radios[i].checked) formValid = true;
  2568. i++;
  2569. }
  2570. if (!formValid) {
  2571. document.getElementById('move_dest').classList.add('alert-danger');
  2572. }
  2573. return formValid;
  2574. }
  2575. var modal;
  2576. function load_move(id_ias) {
  2577. document.form_move_activity.iassign_current.value = id_ias;
  2578. modal.style.display = 'block';
  2579. var radios = document.getElementsByName('iassign_destiny');
  2580. var i = 0;
  2581. while (i < radios.length) {
  2582. radios[i].checked = false;
  2583. i++;
  2584. }
  2585. document.getElementById('move_dest').classList.remove('alert-danger');
  2586. }
  2587. function load_modal_elements() {
  2588. modal = document.getElementById('myModal');
  2589. var span = document.getElementById('close_modal');
  2590. span.onclick = function() {
  2591. modal.style.display = 'none';
  2592. }
  2593. window.onclick = function(event) {
  2594. if (event.target == modal) {
  2595. modal.style.display = 'none';
  2596. }
  2597. }
  2598. }
  2599. window.onload = load_modal_elements;
  2600. //]]>
  2601. </script>\n";
  2602. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2603. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2604. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2605. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2606. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2607. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2608. <input type='hidden' name='iassign_current' value='' />";
  2609. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2610. $section = $course_sections[0];
  2611. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2612. for ($k = 0; $k < count($ids_sections); $k++) {
  2613. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2614. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2615. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2616. if ($c_cm) {
  2617. if ($ccm->instance == $c_cm->instance) {
  2618. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2619. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2620. }
  2621. else {
  2622. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2623. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2624. }
  2625. }
  2626. }
  2627. $radio_buttons .= "</ul>";
  2628. }
  2629. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2630. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2631. </form>
  2632. </div></div> </div></div>\n";
  2633. print " <style>.modal {
  2634. display: none;
  2635. position: fixed;
  2636. z-index: 1;
  2637. left: 0;
  2638. top: 0;
  2639. width: 100%;
  2640. height: 100%;
  2641. overflow: scroll;
  2642. background-color: rgb(0,0,0);
  2643. background-color: rgba(0,0,0,0.4);
  2644. }
  2645. .modal-content {
  2646. background-color: #fefefe;
  2647. margin: 15% auto;
  2648. padding: 10px 10px;
  2649. border: 1px solid #888;
  2650. width: 50%;
  2651. }
  2652. #close_modal {
  2653. color: #aaa;
  2654. float: right;
  2655. font-size: 28px;
  2656. font-weight: bold;
  2657. margin-top: -15px;
  2658. margin-right: -3px;
  2659. }
  2660. #close_modal:hover,
  2661. #close_modal:focus {
  2662. color: black;
  2663. text-decoration: none;
  2664. cursor: pointer;
  2665. }
  2666. #modal_title {
  2667. min-height: 3rem;
  2668. color: initial;
  2669. background: initial;
  2670. font-size: 1.5rem;
  2671. line-height: 1.5;
  2672. padding: 15px;
  2673. border-bottom: 1px solid #e5e5e5;
  2674. }
  2675. .input_move {
  2676. width: 90%;
  2677. padding: 2px;
  2678. }
  2679. .input_move:hover {
  2680. background: #eff0ef;
  2681. }
  2682. </style>";
  2683. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2684. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2685. for ($j = 0; $j < $i; $j ++) {
  2686. $iassign_current = $iassign_array[$j]->id;
  2687. // receiver=1 - message to teacher
  2688. // receiver=2 - message to student
  2689. $sum_comment = 0;
  2690. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2691. foreach ($iassign_submissions as $iassign_submission) {
  2692. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2693. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2694. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2695. if ($verify_message)
  2696. foreach ($verify_message as $tmp)
  2697. $sum_comment += $tmp;
  2698. } // foreach ($iassign_submissions as $iassign_submission)
  2699. if ($sum_comment == 0)
  2700. $comment_unread = "";
  2701. else {
  2702. $comment_unread_message = get_string('comment_unread', 'iassign');
  2703. if ($sum_comment == 1)
  2704. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2705. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2706. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2707. }
  2708. if ($j == $i - 1)
  2709. $iassign_down = $iassign_array[$j]->id;
  2710. else
  2711. $iassign_down = $iassign_array[$j + 1]->id;
  2712. if ($j > 0)
  2713. $iassign_up = $iassign_array[$j - 1]->id;
  2714. else
  2715. $iassign_up = $iassign_array[$j]->id;
  2716. if ($iassign_array[$j]->visible == 0)
  2717. $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>";
  2718. else
  2719. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2720. $links .= $comment_unread;
  2721. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2722. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  2723. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2724. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2725. if ($j==0) // first activity
  2726. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2727. else
  2728. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2729. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2730. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2731. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2732. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2733. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2734. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2735. if (count($iassign_array) > 1) {
  2736. if ($j == 0)
  2737. $links .= $link_down;
  2738. elseif ($j == $i - 1)
  2739. $links .= $link_up;
  2740. else
  2741. $links .= $link_up . $link_down;
  2742. } // if (count($iassign_array) > 1)
  2743. $links .= $link_edit . $link_delete;
  2744. if ($iassign_array[$j]->visible == 0)
  2745. $links .= $link_visible_show;
  2746. else
  2747. $links .= $link_visible_hide;
  2748. $links .= $link_duplicate_activity . $link_move_activity;
  2749. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2750. print '<p>' . $links . '</p>' . "\n";
  2751. }
  2752. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2753. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2754. print '<table width=100% ><tr>' . "\n";
  2755. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2756. print '</tr></table>' . "\n";
  2757. for ($j = 0; $j < $i; $j ++) {
  2758. $icon_status = "";
  2759. $icon_comment = "";
  2760. if ($iassign_array[$j]->visible == 1) {
  2761. $iassign_current = $iassign_array[$j]->id;
  2762. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2763. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2764. $icon_status = "";
  2765. $icon_comment = "";
  2766. if ($iassign_submission) {
  2767. // receiver=1 - message to teacher
  2768. // receiver=2 - message to student
  2769. // $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");
  2770. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2771. $verify_message = $DB->get_record_sql(
  2772. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2773. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2774. if ($verify_message)
  2775. foreach ($verify_message as $tmp)
  2776. $sum_comment = $tmp;
  2777. if ($sum_comment > 0) {
  2778. $comment_unread_message = get_string('comment_unread', 'iassign');
  2779. if ($sum_comment == 1)
  2780. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2781. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2782. }
  2783. // $icon_comment = iassign_icons::insert('comment_unread');
  2784. if ($iassign_array[$j]->type_iassign == 3) {
  2785. if ($iassign_array[$j]->show_answer == 1) {
  2786. if ($iassign_submission->status == 3)
  2787. $icon_status = iassign_icons::insert('correct');
  2788. elseif ($iassign_submission->status == 2)
  2789. $icon_status = iassign_icons::insert('incorrect');
  2790. elseif ($iassign_submission->status == 1)
  2791. $icon_status = iassign_icons::insert('post');
  2792. elseif ($iassign_submission->status == 0)
  2793. $icon_status = iassign_icons::insert('not_post');
  2794. } // if ($iassign_array[$j]->show_answer==1)
  2795. else {
  2796. if ($iassign_submission->status == 0)
  2797. $icon_status = iassign_icons::insert('not_post');
  2798. else
  2799. $icon_status = iassign_icons::insert('post');
  2800. }
  2801. } // if ($iassign_array[$j]->type_iassign == 3)
  2802. } // if ($iassign_submission)
  2803. elseif ($iassign_array[$j]->type_iassign == 3) {
  2804. $icon_status = iassign_icons::insert('not_post');
  2805. } // if ($iassign_array[$j]->type_iassign == 3)
  2806. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2807. } // if ($iassign_array[$j]->visible == 1)
  2808. } // for ($j = 0; $j < $i; $j++)
  2809. } else if (isguestuser()) {
  2810. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2811. print '<table width=100% ><tr>' . "\n";
  2812. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2813. print '</tr></table>' . "\n";
  2814. for ($j = 0; $j < $i; $j ++) {
  2815. $icon_status = "";
  2816. $icon_comment = "";
  2817. if ($iassign_array[$j]->visible == 1) {
  2818. $iassign_current = $iassign_array[$j]->id;
  2819. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2820. print '<p>' . $links . '</p>' . "\n";
  2821. } // if ($iassign_array[$j]->visible == 1)
  2822. }
  2823. }
  2824. print $OUTPUT->box_end();
  2825. } // function show_iassign($title, $iassign_array, $i)
  2826. /// Show message of return
  2827. function return_home_course ($message) {
  2828. //D global $DB, $OUTPUT;
  2829. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2830. //D echo $OUTPUT->box_start();
  2831. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2832. //D echo '<tr><td align="left"><strong>' . "\n";
  2833. //D print_string($message, 'iassign');
  2834. //D echo '</strong></td>' . "\n";
  2835. //D echo '<td width=20% align="right">' . "\n";
  2836. //D echo $link_return;
  2837. //D echo '</td></tr></table>' . "\n";
  2838. //D echo $OUTPUT->box_end();
  2839. //D // echo $OUTPUT->footer();
  2840. redirect(new moodle_url($this->return . '&notice=' . $message));
  2841. exit;
  2842. }
  2843. /// Search comment of activity
  2844. function search_comment_submission ($iassign_submissionid) {
  2845. global $USER, $DB, $OUTPUT, $COURSE;
  2846. // $context = context_course::instance($COURSE->id);
  2847. $colorEdit1 = "#a7bede"; // "#dce7ec"
  2848. $colorEdit2 = "#b7ceee";
  2849. $has_capability = 0;
  2850. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2851. $text = "";
  2852. if ($comments) {
  2853. $even = 1;
  2854. foreach ($comments as $tmp) {
  2855. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2856. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2857. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2858. // $text .= $tmp->comment . "</td></tr>";
  2859. //} else {
  2860. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2861. if ($even) {
  2862. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2863. $even = 0;
  2864. } else {
  2865. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  2866. $even = 1;
  2867. }
  2868. $text .= $tmp->comment . "</td></tr>\n";
  2869. } // foreach ($comments as $tmp)
  2870. }
  2871. return $text;
  2872. }
  2873. /// Update comment of activity
  2874. function update_comment ($iassign_submissionid) {
  2875. global $USER, $DB, $OUTPUT;
  2876. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2877. $receiver = 1; // student message to teacher
  2878. else
  2879. $receiver = 2; // teacher message to student
  2880. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2881. if ($verify_message) {
  2882. foreach ($verify_message as $message) {
  2883. if ($message->receiver == $receiver) {
  2884. $newentry = new stdClass();
  2885. $newentry->id = $message->id;
  2886. $newentry->return_status = 1;
  2887. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2888. print_error('error_update', 'iassign');
  2889. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2890. } // if ($message->receiver == $receiver)
  2891. // Trigger module viewed event.
  2892. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2893. 'objectid' => $this->iassign->id,
  2894. 'context' => $this->context
  2895. ));
  2896. $event->add_record_snapshot('course', $this->course);
  2897. $event->trigger();
  2898. } // foreach ($verify_message as $message)
  2899. }
  2900. }
  2901. /// Record comment of activity
  2902. function write_comment_submission () {
  2903. global $USER, $CFG, $DB;
  2904. $id = $this->cm->id;
  2905. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2906. $row = optional_param('row', 0, PARAM_INT);
  2907. $column = optional_param('column', 0, PARAM_INT);
  2908. $sum_comment = 0;
  2909. $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);
  2910. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2911. $str1 = trim($submission_comment);
  2912. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2913. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2914. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  2915. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  2916. $receiver = 1; // student message to teacher
  2917. $this->action = 'view';
  2918. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  2919. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  2920. } else {
  2921. $receiver = 2; // teacher message to student
  2922. $this->action = 'viewsubmission';
  2923. //D $tousers = array(); //MOOC 2016
  2924. //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
  2925. }
  2926. //MOOC 2016: foi p/ 15 linhas acima:
  2927. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  2928. if (!$iassign_submission) {
  2929. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  2930. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  2931. $this->iassign_submission_current = $id_submission;
  2932. } else {
  2933. $id_submission = $iassign_submission->id;
  2934. } // if (!$iassign_submission)
  2935. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  2936. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  2937. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  2938. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  2939. $comments = $DB->get_record_sql(
  2940. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2941. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  2942. if ($comments)
  2943. foreach ($comments as $tmp)
  2944. $sum_comment = $tmp;
  2945. if ($sum_comment == 0) {
  2946. $newentry = new stdClass();
  2947. $newentry->iassign_submissionid = $id_submission;
  2948. $newentry->comment_authorid = $USER->id;
  2949. $newentry->timecreated = time();
  2950. $newentry->comment = $submission_comment;
  2951. $newentry->receiver = $receiver;
  2952. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  2953. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  2954. //T $eventdata = new stdClass();
  2955. //T $eventdata->component = 'mod_iassign'; //your component name
  2956. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  2957. //T $eventdata->userfrom = $USER;
  2958. //T $eventdata->userto = $touser;
  2959. //T $eventdata->subject = "Teste de Subject";
  2960. //T $eventdata->fullmessage = "Teste de Mensagem...";
  2961. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  2962. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  2963. //T $eventdata->smallmessage = "Teste de Mensagem";
  2964. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  2965. //T // alteracao tulio faria
  2966. //T //message_send($eventdata);
  2967. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  2968. // Trigger module viewed event.
  2969. $event = \mod_iassign\event\submission_comment_created::create(array(
  2970. 'objectid' => $this->iassign->id,
  2971. 'context' => $this->context
  2972. ));
  2973. $event->add_record_snapshot('course', $this->course);
  2974. $event->trigger();
  2975. }
  2976. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  2977. // if ($this->action=='viewsubmission') {
  2978. // echo $OUTPUT->header();
  2979. // $this->return_last('confirm_add_comment', $link_return);
  2980. // die;
  2981. // }
  2982. return true;
  2983. } // function write_comment_submission()
  2984. /// Writes a new submission
  2985. // The first student answer is under 'function get_answer()'
  2986. function new_submission ($iassignid, $id_user, $receiver) {
  2987. global $USER, $DB, $OUTPUT;
  2988. $newentry = new stdClass();
  2989. $newentry->iassign_statementid = $iassignid;
  2990. $newentry->userid = $id_user;
  2991. $newentry->timecreated = time();
  2992. $newentry->timemodified = time();
  2993. $newentry->answer = 0; // student only submit message
  2994. if ($receiver == 2) // teacher message to student (write id teacher)
  2995. $newentry->teacher = $USER->id;
  2996. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  2997. return_home_course('error_insert_submissions');
  2998. else {
  2999. // Trigger module view event
  3000. $event = \mod_iassign\event\submission_created::create(array(
  3001. 'objectid' => $this->iassign->id,
  3002. 'context' => $this->context
  3003. ));
  3004. $event->add_record_snapshot('course', $this->course);
  3005. $event->trigger();
  3006. }
  3007. return $newentry->id;
  3008. }
  3009. /// Return to a specific address of page
  3010. function return_last ($message, $link_return) {
  3011. global $DB, $OUTPUT;
  3012. print $OUTPUT->box_start();
  3013. print '<table width=100% border=0 valign="top">' . "\n";
  3014. print '<tr><td align="left"><strong>' . "\n";
  3015. print_string($message, 'iassign');
  3016. print '</strong></td>' . "\n";
  3017. print '<td width=20% align="right">' . "\n";
  3018. print $link_return;
  3019. print '</td></tr></table>' . "\n";
  3020. print $OUTPUT->box_end();
  3021. print $OUTPUT->footer();
  3022. die();
  3023. } // function return_last($message, $link_return)
  3024. } // class iassign
  3025. /// Class for manage activities
  3026. class activity {
  3027. var $activity;
  3028. /// Constructor of class.
  3029. // @param int $id Id of activity
  3030. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3031. //D public function activity($id) { self::__construct($id); }
  3032. function __construct ($id) {
  3033. global $DB;
  3034. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3035. if (empty($this->activity))
  3036. $this->activity = null;
  3037. }
  3038. /// Get an activity
  3039. // @return NULL
  3040. function get_activity () {
  3041. if ($this->activity != null)
  3042. return $this->activity;
  3043. else
  3044. return null;
  3045. }
  3046. /// Delete interactive activities
  3047. function delete ($return) {
  3048. global $USER, $CFG, $DB, $OUTPUT;
  3049. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3050. $output = $OUTPUT->header();
  3051. $output .= $OUTPUT->box_start();
  3052. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3053. if ($iassign_submission_currents) {
  3054. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3055. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3056. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3057. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3058. $output .= $OUTPUT->box_end();
  3059. $output .= $OUTPUT->footer();
  3060. print $output;
  3061. die();
  3062. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3063. } // if ($iassign_submission_currents)
  3064. else
  3065. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3066. $output .= '<table width=50% border=0>';
  3067. $output .= '<tr valign="top"><td>';
  3068. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3069. $output .= '</td><td>';
  3070. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3071. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3072. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3073. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3074. $output .= "</form>\n";
  3075. $output .= '</td><td>';
  3076. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3077. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3078. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3079. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3080. $output .= "</form>\n";
  3081. $output .= '</td></tr></table>' . "\n";
  3082. $output .= $OUTPUT->box_end();
  3083. $output .= $OUTPUT->footer();
  3084. print $output;
  3085. } // function delete($return)
  3086. /// Function for confirm the delete of activity
  3087. // @param String $return Url of return
  3088. // @param Object $iassign Object content an activity
  3089. function deleteyes ($return, $iassign) {
  3090. global $USER, $CFG, $DB, $OUTPUT;
  3091. $msg = '';
  3092. if (!empty($this->activity->id)) {
  3093. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3094. if ($iassign_submission_currents) {
  3095. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3096. foreach ($iassign_submission_currents as $iassign_submission)
  3097. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3098. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3099. } // if ($iassign_submission_currents)
  3100. }
  3101. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3102. $this->delete_calendar($this->activity->id);
  3103. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3104. iassign::update_grade_iassign($this->activity->iassignid);
  3105. if ($delete_iassign_current) {
  3106. $iassign->return_home_course('confirm_delete_iassign');
  3107. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3108. } else {
  3109. $iassign->return_home_course('error_confirm_delete_iassign');
  3110. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3111. }
  3112. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3113. }
  3114. }
  3115. /// Changes position of activities (between those inside a group of interactive activities)
  3116. // @param $move_action = must be "up" or "down"
  3117. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3118. function move_iassign ($move_action, $target, $return) {
  3119. global $DB, $OUTPUT;
  3120. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3121. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3122. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3123. if ($move_action=="firstdown") {
  3124. $final_position_source = 2;
  3125. $final_position_target = 1;
  3126. }
  3127. else
  3128. if ($move_action=="down") {
  3129. $final_position_target = $this->activity->position;
  3130. $final_position_source = $final_position_target + 1;
  3131. }
  3132. else
  3133. if ($move_action=="up") {
  3134. $final_position_target = $this->activity->position;
  3135. $final_position_source = $final_position_target - 1;
  3136. }
  3137. else { // error:
  3138. print_error('error_update_move_iassign', 'iassign');
  3139. exit;
  3140. }
  3141. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3142. $newentry->id = $this->activity->id; // ID of the "source activity"
  3143. $newentry->position = $final_position_source;
  3144. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3145. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3146. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3147. print_error('error_update_move_iassign', 'iassign');
  3148. }
  3149. else { // first update performed successfully
  3150. $newentry->id = $iassign_target->id;
  3151. $newentry->position = $final_position_target;
  3152. if (!$DB->update_record('iassign_statement', $newentry))
  3153. print_error('error_update_move_iassign', 'iassign');
  3154. }
  3155. redirect($return);
  3156. }
  3157. /// Enable or disable the display of interactive activities
  3158. function visible_iassign ($return) {
  3159. global $DB;
  3160. $newentry = new stdClass();
  3161. $newentry->id = $this->activity->id;
  3162. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3163. if (!$DB->update_record('iassign_statement', $newentry))
  3164. print_error('error_update_visible_iassign', 'iassign');
  3165. redirect($return);
  3166. }
  3167. /// Add news interactive activities (register in table 'iassign_statement')
  3168. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3169. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3170. function new_iassign ($param) {
  3171. global $DB;
  3172. $newentry = new stdClass();
  3173. $newentry->iassignid = $param->iassignid;
  3174. $newentry->name = $param->name;
  3175. $newentry->type_iassign = $param->type_iassign;
  3176. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3177. $proposition = $param->proposition;
  3178. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3179. else $proposition_text = $proposition;
  3180. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3181. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3182. //TODO Then get it directly from the form data $_POST!
  3183. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3184. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3185. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3186. $newentry->author_name = $param->author_name;
  3187. $newentry->author_modified_name = $param->author_modified_name;
  3188. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3189. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3190. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3191. $newentry->grade = $param->grade;
  3192. $newentry->timemodified = time();
  3193. $newentry->timecreated = time();
  3194. if ($param->type_iassign == 1) {
  3195. $newentry->timedue = 0;
  3196. $newentry->timeavailable = 0;
  3197. } // if ($param->type_iassign == 1)
  3198. else {
  3199. $newentry->timedue = $param->timedue;
  3200. $newentry->timeavailable = $param->timeavailable;
  3201. }
  3202. $newentry->preventlate = $param->preventlate;
  3203. $newentry->test = $param->test;
  3204. $newentry->special_param1 = $param->special_param1;
  3205. $newentry->visible = $param->visible;
  3206. $newentry->position = $param->position;
  3207. $newentry->max_experiment = $param->max_experiment;
  3208. $newentry->dependency = $param->dependency;
  3209. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3210. $newentry->show_answer = $param->show_answer;
  3211. $id = $DB->insert_record("iassign_statement", $newentry);
  3212. if ($id) {
  3213. $component = 'mod_iassign';
  3214. $filearea = 'exercise';
  3215. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3216. $file = $fs->get_file_by_id($param->file);
  3217. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3218. // File already inserted in other context!
  3219. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3220. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3221. $updateentry = new stdClass();
  3222. $updateentry->id = $id;
  3223. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3224. $updateentry->file = $newfile->get_itemid();
  3225. if (!$DB->update_record("iassign_statement", $updateentry))
  3226. print_error('error_add', 'iassign');
  3227. if ($param->type_iassign == 3)
  3228. iassign::update_grade_iassign($param->iassignid);
  3229. //TODO iLM_HTML5 :: //MOOC2014
  3230. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3231. //D if ($iassign_ilm_configs) {
  3232. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3233. //D if ($iassign_ilm_config->param_type != 'static') {
  3234. //D $newentry = new stdClass();
  3235. //D $newentry->iassign_statementid = $id;
  3236. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3237. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3238. //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});
  3239. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3240. //D print_error('error_add_param', 'iassign');
  3241. //D }
  3242. //D }
  3243. //D }
  3244. // log event --------------------------------------------------------------------------------------
  3245. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3246. // log event --------------------------------------------------------------------------------------
  3247. return $id;
  3248. }
  3249. else
  3250. print_error('error_add', 'iassign');
  3251. } // function new_iassign($param)
  3252. /// Add the calendar entries for this iassign
  3253. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3254. // @return bool
  3255. static function add_calendar ($iassignid) {
  3256. global $DB, $CFG;
  3257. require_once($CFG->dirroot . '/calendar/lib.php');
  3258. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3259. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3260. $event = new stdClass();
  3261. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3262. $event->description = $iassign_statement_activity_item->name;
  3263. $event->courseid = $iassign->course;
  3264. $event->groupid = 0;
  3265. $event->userid = 0;
  3266. $event->modulename = 'iassign';
  3267. $event->instance = $iassign->id;
  3268. $event->eventtype = 'due';
  3269. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3270. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3271. calendar_event::create($event);
  3272. }
  3273. /// Update the calendar entries for this iassign
  3274. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3275. // @return bool
  3276. function update_calendar ($iassignid, $olddescription) {
  3277. global $DB, $CFG;
  3278. require_once($CFG->dirroot . '/calendar/lib.php');
  3279. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3280. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3281. $event = new stdClass();
  3282. $event->id = 0;
  3283. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3284. if ($events) {
  3285. foreach ($events as $value) {
  3286. if ($value->description == $olddescription) {
  3287. $event->id = $value->id;
  3288. }
  3289. }
  3290. }
  3291. if ($event->id != 0) {
  3292. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3293. $event->description = $iassign_statement_activity_item->name;
  3294. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3295. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3296. $calendarevent = calendar_event::load($event->id);
  3297. $calendarevent->update($event);
  3298. } else
  3299. $this->add_calendar($iassignid);
  3300. }
  3301. /// Update the calendar entries for this iassign
  3302. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3303. // @return bool
  3304. function delete_calendar ($iassignid) {
  3305. global $DB, $CFG;
  3306. require_once($CFG->dirroot . '/calendar/lib.php');
  3307. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3308. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3309. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3310. if ($events) {
  3311. foreach ($events as $value) {
  3312. if ($value->description == $iassign_statement_activity_item->name) {
  3313. $DB->delete_records('event', array('id' => $value->id));
  3314. }
  3315. }
  3316. }
  3317. }
  3318. /// Update interactive activities
  3319. function update_iassign ($param) {
  3320. global $DB;
  3321. $component = 'mod_iassign';
  3322. $filearea = 'exercise';
  3323. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3324. $file = $fs->get_file_by_id($param->file);
  3325. $fileold = $fs->get_file_by_id($param->fileold);
  3326. if ($param->file != $param->fileold) {
  3327. if ($fileold) {
  3328. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3329. foreach ($fileoldarea as $value) {
  3330. $value->delete();
  3331. }
  3332. }
  3333. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3334. $itemid = $file->get_itemid() + $param->iassign_id;
  3335. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3336. $param->file = $newfile->get_itemid();
  3337. } else
  3338. $param->file = $file->get_itemid();
  3339. } else {
  3340. $param->file = $file->get_itemid();
  3341. }
  3342. $newentry = new stdClass();
  3343. $newentry->id = $param->iassign_id;
  3344. $newentry->name = $param->name;
  3345. $newentry->type_iassign = $param->type_iassign;
  3346. //2019 $newentry->proposition = $param->proposition;
  3347. $proposition = $param->proposition;
  3348. if (is_array($proposition))
  3349. $proposition_text = $proposition['text'];
  3350. else
  3351. $proposition_text = $proposition;
  3352. $newentry->proposition = $proposition_text;
  3353. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3354. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3355. $newentry->grade = $param->grade;
  3356. $newentry->author_modified_name = $param->author_modified_name;
  3357. $newentry->timemodified = time();
  3358. if ($param->type_iassign == 1) {
  3359. $newentry->timedue = 0;
  3360. $newentry->timeavailable = 0;
  3361. } // if ($param->type_iassign == 1)
  3362. else {
  3363. $newentry->timedue = $param->timedue;
  3364. $newentry->timeavailable = $param->timeavailable;
  3365. }
  3366. $newentry->preventlate = $param->preventlate;
  3367. $newentry->test = $param->test;
  3368. $newentry->special_param1 = $param->special_param1;
  3369. $newentry->visible = $param->visible;
  3370. $newentry->max_experiment = $param->max_experiment;
  3371. $newentry->dependency = $param->dependency;
  3372. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3373. $newentry->show_answer = $param->show_answer;
  3374. if (!$DB->update_record("iassign_statement", $newentry))
  3375. print_error('error_update', 'iassign');
  3376. if ($param->type_iassign == 3) {
  3377. iassign::update_grade_iassign($param->iassignid);
  3378. }
  3379. //$id = $newentry->id; // MOOC 2016 --- inicio
  3380. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3381. //if ($iassign_activity_item_configs) {
  3382. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3383. // $newentry = new stdClass();
  3384. // $newentry->id = $iassign_activity_item_config->id;
  3385. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3386. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3387. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3388. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3389. // print_error('error_edit_param', 'iassign');
  3390. // }
  3391. // } // MOOC 2016 --- final
  3392. // log event --------------------------------------------------------------------------------------
  3393. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3394. // log event --------------------------------------------------------------------------------------
  3395. return $newentry->id;
  3396. // if ($param->type_iassign==3)
  3397. // $this->update_grade_iassign($param->iassignid);
  3398. } // function update_iassign($param)
  3399. /// Show information of activity
  3400. function show_info_iassign () {
  3401. global $DB, $OUTPUT;
  3402. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3403. if ($this->activity->type_iassign == 3) {
  3404. if ($this->activity->dependency == 0) {
  3405. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3406. } else {
  3407. $dependencys = explode(';', $this->activity->dependency);
  3408. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3409. foreach ($dependencys as $dependency) {
  3410. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3411. if ($dependencyiassign)
  3412. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3413. } // foreach ($dependencys as $dependency)
  3414. } // if ($iassign_statement_activity_item->dependency == 0)
  3415. if ($this->activity->max_experiment == 0)
  3416. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3417. else
  3418. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3419. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3420. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3421. print $OUTPUT->box($output);
  3422. } // function show_info_iassign()
  3423. /// Shows date of opening and closing activities
  3424. function view_dates () {
  3425. global $USER, $CFG, $DB, $OUTPUT;
  3426. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3427. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3428. $status_iassign = "";
  3429. $status_iassign1 = "";
  3430. $status_iassign2 = "";
  3431. if ($this->activity->type_iassign == 1) // activity of type example
  3432. $type_iassign = get_string('example_iassign', 'iassign');
  3433. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3434. $type_iassign = get_string('test_iassign', 'iassign');
  3435. if ($this->activity->timeavailable > time()) {
  3436. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3437. } elseif ($this->activity->timedue < time()) {
  3438. $status_iassign = get_string('last_timedue', 'iassign');
  3439. }
  3440. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3441. $type_iassign = get_string('exercise_iassign', 'iassign');
  3442. if ($this->activity->timeavailable > time()) {
  3443. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3444. } elseif ($this->activity->timedue < time()) { // after delivery
  3445. $status_iassign = get_string('last_timedue', 'iassign');
  3446. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3447. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3448. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3449. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3450. if ($this->activity->test == 1) // allowed to test after of deadline
  3451. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3452. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3453. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3454. } // elseif ($iassign_statement_activity_item->test == 0)
  3455. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3456. } // elseif ($iassign_statement_activity_item->timedue < time())
  3457. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3458. $output = '<table width=100% >' . "\n";
  3459. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3460. $output .= '<tr>' . "\n";
  3461. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3462. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3463. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3464. // leo $output .= '<td width=80%>' . $type_iassign;
  3465. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3466. // $output .= '</td>' . "\n";
  3467. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3468. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3469. $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>";
  3470. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3471. } else {
  3472. $link_next = "";
  3473. $link_previous = "";
  3474. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3475. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3476. // previous_activity
  3477. if ($iassign_previous) {
  3478. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3479. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3480. } // next_activity
  3481. if ($iassign_next) {
  3482. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3483. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3484. }
  3485. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3486. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3487. $output .= '</tr></table>' . "\n";
  3488. $output .= '<table width=100% >' . "\n";
  3489. if ($this->activity->type_iassign > 1) {
  3490. if ($this->activity->timeavailable)
  3491. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3492. if ($this->activity->timedue)
  3493. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3494. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3495. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3496. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3497. $output .= '</table>' . "\n";
  3498. print $OUTPUT->box($output);
  3499. } // function view_dates()
  3500. } // class activity
  3501. /// Class to manage Interactive Learning Module (iLM)
  3502. class ilm {
  3503. var $ilm;
  3504. /// Constructor of class
  3505. // @param int $id Id of iLM
  3506. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3507. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3508. function __construct ($id) {
  3509. global $DB;
  3510. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3511. if (empty($this->ilm))
  3512. $this->ilm = null;
  3513. }
  3514. /// Shows activity in iLM
  3515. // @calledby view_iassign_current()
  3516. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3517. global $USER, $CFG, $DB;
  3518. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3519. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3520. $typec = strtolower($iassign_ilm->type);
  3521. require_once 'ilm_handlers/' . $typec . '.php';
  3522. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3523. return $retorno;
  3524. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3525. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3526. // @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);
  3527. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3528. // @param Object $file File in use in activity
  3529. // @return int Return the id of log
  3530. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3531. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3532. $newentry = new stdClass();
  3533. $newentry->iassign_statementid = $iassign_activity_itemid;
  3534. $newentry->userid = $USER->id;
  3535. $newentry->file = $content_or_id_from_ilm_security;
  3536. $newentry->timecreated = time();
  3537. $newentry->view = 1;
  3538. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3539. if (!$id_iLM_security) {
  3540. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3541. } // from (!$DB->insert_record("iassign_security", $newentry))
  3542. return $id_iLM_security;
  3543. }
  3544. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3545. // @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);
  3546. // @param int $userid
  3547. // @param int $iassign_activity_itemid Id of iassign statement
  3548. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3549. global $DB;
  3550. // 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")
  3551. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3552. }
  3553. } // class ilm
  3554. /// Class to manage settings of iLM.
  3555. class ilm_settings {
  3556. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3557. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3558. // @param int $ilm_id Id of iLM
  3559. // @param array $options An array with options for create dynamic tag html APPLET
  3560. // @return string Return with a tag html APPLET created
  3561. static function build_ilm_tags ($ilm_id, $options = array()) {
  3562. global $DB;
  3563. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3564. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3565. $typec = strtolower($iassign_ilm->type);
  3566. require_once 'ilm_handlers/' . $typec . '.php';
  3567. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3568. return $retorno;
  3569. } // static function build_ilm_tags($ilm_id, $options = array())
  3570. /// Function for get modified date of iLM file
  3571. // @param string $file_jar String with Ids of iLM files
  3572. // @return string Return with the filenames and modified date
  3573. static function applet_filetime ($file_jar) {
  3574. $filetime = "";
  3575. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3576. $files_jar = explode(",", $file_jar);
  3577. foreach ($files_jar as $one_file) {
  3578. $file = $fs->get_file_by_id($one_file);
  3579. if ($file)
  3580. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3581. }
  3582. return $filetime;
  3583. }
  3584. /// Function for verify an default applet
  3585. // @param String $file_jar String containing an list de ids of applet files
  3586. // @return boolean Return true or fale if applet is default
  3587. static function applet_default ($file_jar) {
  3588. $is_default = true;
  3589. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3590. $files_jar = explode(",", $file_jar);
  3591. foreach ($files_jar as $one_file) {
  3592. $file = $fs->get_file_by_id($one_file);
  3593. if ($file)
  3594. $is_default &= ($file->get_itemid() == 0);
  3595. }
  3596. return $is_default;
  3597. }
  3598. /// Function for get form variables for add, edit, or copy iLM
  3599. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3600. // @see settings_form.php
  3601. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3602. // @param int $ilm_id Id of iLM
  3603. // @param string $action String with the action
  3604. // @return object Return an object with forms variables
  3605. static function add_edit_copy_ilm ($ilm_id, $action) {
  3606. global $USER, $DB, $CFG;
  3607. require_once('settings_form.php'); // put the form
  3608. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3609. $param = new stdClass();
  3610. $param->action = $action;
  3611. $param->ilm_id = $ilm_id;
  3612. $CFG->action_ilm = $action;
  3613. $CFG->ilm_id = $ilm_id;
  3614. if ($action == 'add') {
  3615. $param->title = get_string('add_ilm', 'iassign');
  3616. $param->name = "";
  3617. $param->version = "";
  3618. $param->url = "";
  3619. $param->description = "";
  3620. $param->extension = "";
  3621. $param->author = $USER->id;
  3622. $param->file_jar = "";
  3623. $param->file_jar_static = "";
  3624. $param->file_class = "";
  3625. $param->width = 800;
  3626. $param->height = 600;
  3627. $param->enable = 0; // 0 - hide / 1 - show
  3628. $param->timecreated = time();
  3629. $param->timemodified = time();
  3630. $param->evaluate = 0;
  3631. $param->parent = 0;
  3632. }
  3633. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3634. if ($iassign_ilm) {
  3635. $description = json_decode($iassign_ilm->description);
  3636. $param->title = get_string('edit_ilm', 'iassign');
  3637. $param->id = $iassign_ilm->id;
  3638. $param->name_ilm = $iassign_ilm->name;
  3639. $param->name = $iassign_ilm->name;
  3640. $param->version = $iassign_ilm->version;
  3641. $param->ilm_type = $iassign_ilm->type;
  3642. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3643. $param->url = $iassign_ilm->url;
  3644. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  3645. if (!isset($description->{current_language()})) {
  3646. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  3647. else
  3648. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  3649. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  3650. }
  3651. else
  3652. $param->description = $description->{current_language()};
  3653. $param->description_lang = $iassign_ilm->description;
  3654. $param->extension = $iassign_ilm->extension;
  3655. $param->author = $iassign_ilm->author;
  3656. $param->file_jar = $iassign_ilm->file_jar;
  3657. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3658. $param->file_class = $iassign_ilm->file_class;
  3659. $param->width = $iassign_ilm->width;
  3660. $param->height = $iassign_ilm->height;
  3661. $param->enable = $iassign_ilm->enable;
  3662. $param->timecreated = $iassign_ilm->timecreated;
  3663. $param->timemodified = time();
  3664. $param->evaluate = $iassign_ilm->evaluate;
  3665. $param->parent = $iassign_ilm->parent;
  3666. }
  3667. }
  3668. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3669. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3670. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3671. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3672. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3673. // echo "Sem dados<br/>"; exit;
  3674. return;
  3675. }
  3676. $description = json_decode($iassign_ilm->description);
  3677. if ($iassign_ilm) {
  3678. if ($iassign_ilm->parent == 0)
  3679. $iassign_ilm->parent = $ilm_id;
  3680. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3681. $param->title = get_string('new_version_ilm', 'iassign');
  3682. $param->name_ilm = $iassign_ilm->name;
  3683. $param->name = $iassign_ilm->name;
  3684. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3685. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3686. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3687. $param->ilm_type = $iassign_ilm->type;
  3688. $param->url = $iassign_ilm->url;
  3689. $param->description = $description->{current_language()};
  3690. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3691. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3692. $param->extension = $iassign_ilm->extension;
  3693. $param->author = $USER->id;
  3694. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3695. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3696. $param->file_jar_static = '';
  3697. $param->file_class = $iassign_ilm->file_class;
  3698. $param->width = $iassign_ilm->width;
  3699. $param->height = $iassign_ilm->height;
  3700. $param->enable = 0;
  3701. $param->timecreated = time();
  3702. $param->timemodified = time();
  3703. $param->evaluate = $iassign_ilm->evaluate;
  3704. $param->parent = $iassign_ilm->parent;
  3705. }
  3706. }
  3707. elseif ($action == 'copy') {
  3708. $description = json_decode($iassign_ilm->description);
  3709. if ($iassign_ilm) {
  3710. if ($iassign_ilm->parent == 0)
  3711. $iassign_ilm->parent = $ilm_id;
  3712. $param->title = get_string('copy_ilm', 'iassign');
  3713. $param->id = $iassign_ilm->id;
  3714. $param->name_ilm = $iassign_ilm->name;
  3715. $param->name = $iassign_ilm->name;
  3716. $param->version = "";
  3717. $param->ilm_type = $iassign_ilm->type;
  3718. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3719. $param->url = $iassign_ilm->url;
  3720. $param->description = $description->{current_language()};
  3721. $param->description_lang = $iassign_ilm->description;
  3722. $param->extension = $iassign_ilm->extension;
  3723. $param->author = $USER->id;
  3724. $param->file_jar = '';
  3725. $param->file_jar_static = '';
  3726. $param->file_class = $iassign_ilm->file_class;
  3727. $param->width = $iassign_ilm->width;
  3728. $param->height = $iassign_ilm->height;
  3729. $param->enable = 0;
  3730. $param->timecreated = time();
  3731. $param->timemodified = time();
  3732. $param->evaluate = $iassign_ilm->evaluate;
  3733. $param->parent = $iassign_ilm->parent;
  3734. }
  3735. }
  3736. return $param;
  3737. } // static function add_edit_copy_ilm($ilm_id, $action)
  3738. /// Function for save iLM file in moodledata
  3739. // @param int $itemid Itemid of file save in draft (upload file)
  3740. // @param int $ilm_id Id of iLM
  3741. // @return string Return an string with ids of iLM files
  3742. static function new_file_ilm ($itemid, $iassign_ilm) {
  3743. global $CFG, $USER, $DB;
  3744. $return = null;
  3745. $file_jar = array();
  3746. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3747. $contextuser = context_user::instance($USER->id);
  3748. $contextsystem = context_system::instance();
  3749. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3750. if ($files_ilm) {
  3751. foreach ($files_ilm as $value) {
  3752. // CHECK IF file is HTML type
  3753. if ($iassign_ilm->type == 1) {
  3754. // Check if the file extension is ZIP
  3755. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3756. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  3757. if ((strtolower($ext) == 'zip')) {
  3758. // Coping...:
  3759. $destination = 'ilm_debug/' . $value->get_filename();
  3760. $value->copy_content_to($destination);
  3761. // Extracting content...:
  3762. $zip = new ZipArchive();
  3763. $extracted = './ilm';
  3764. $dir = "";
  3765. if ($zip->open($destination) === TRUE) {
  3766. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3767. if (is_dir($dir)) {
  3768. $i = 1;
  3769. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3770. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3771. $i ++;
  3772. }
  3773. $name = $previous . "_" . $i;
  3774. $dir = './ilm/' . $name . "/";
  3775. $j = 0;
  3776. while ($item_name = $zip->getNameIndex($j)) {
  3777. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3778. $j++;
  3779. }
  3780. $zip->close();
  3781. }
  3782. $zip->open($destination);
  3783. $zip->extractTo($extracted);
  3784. $zip->close();
  3785. // After the extraction, remove it from DEBUG
  3786. unlink($destination);
  3787. } else { // Error trying to open destination...
  3788. // After the extraction error, also remove it from DEBUG
  3789. unlink($destination);
  3790. print_error('error_add_ilm_zip', 'iassign');
  3791. }
  3792. return $dir;
  3793. }
  3794. } // if ($iassign_ilm->type == 1)
  3795. if ($value->get_filename() != '.') {
  3796. $file_ilm = array(
  3797. 'userid' => $USER->id,
  3798. 'contextid' => $contextsystem->id,
  3799. 'component' => 'mod_iassign',
  3800. 'filearea' => 'ilm',
  3801. 'itemid' => rand(1, 999999999),
  3802. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3803. 'filename' => $value->get_filename());
  3804. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3805. array_push($file_jar, $file_ilm->get_id());
  3806. }
  3807. }
  3808. if (!empty($file_jar)) {
  3809. $return = implode(",", $file_jar);
  3810. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3811. foreach ($old_file_jar as $value) {
  3812. $file = $fs->get_file_by_id($value);
  3813. if ($file)
  3814. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3815. }
  3816. }
  3817. }
  3818. else // if ($files_ilm)
  3819. $return = $iassign_ilm->file_jar;
  3820. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3821. return $return;
  3822. } // static function new_file_ilm($itemid, $iassign_ilm)
  3823. /// Function for save in database an new iLM
  3824. // @param object $param An object with iLM params
  3825. static function new_ilm ($itemid) {
  3826. global $CFG, $USER, $OUTPUT;
  3827. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3828. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3829. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3830. }
  3831. $pathtemp = $CFG->dataroot . '/temp/';
  3832. $contextuser = context_user::instance($USER->id);
  3833. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3834. $zip = new zip_packer();
  3835. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3836. foreach ($files as $file) {
  3837. if (!$file->is_directory())
  3838. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3839. }
  3840. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3841. // Verifica se o pacote possui o XML
  3842. if (!$application_xml) {
  3843. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3844. return;
  3845. } else {
  3846. $missing = "";
  3847. if (!isset($application_xml->name)) {
  3848. $missing .= "name";
  3849. }
  3850. if (!isset($application_xml->version)) {
  3851. $missing .= ", version";
  3852. }
  3853. if (!isset($application_xml->type)) {
  3854. $missing .= ", type";
  3855. }
  3856. if (!isset($application_xml->extension)) {
  3857. $missing .= ", extension";
  3858. }
  3859. if (!isset($application_xml->file_jar)) {
  3860. $missing .= ", file_jar";
  3861. }
  3862. if (!isset($application_xml->file_class)) {
  3863. $missing .= ", file_class";
  3864. }
  3865. if (!isset($application_xml->width)) {
  3866. $missing .= ", width";
  3867. }
  3868. if (!isset($application_xml->height)) {
  3869. $missing .= ", height";
  3870. }
  3871. if (!isset($application_xml->evaluate)) {
  3872. $missing .= ", evaluate";
  3873. }
  3874. if (strlen($missing) > 2) {
  3875. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3876. return;
  3877. }
  3878. }
  3879. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3880. $typec = strtolower($application_xml->type);
  3881. require_once 'ilm_handlers/' . $typec . '.php';
  3882. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3883. return $retorno;
  3884. } // static function new_ilm($itemid)
  3885. /// Function for save in database an iLM edit
  3886. // @param object $param An object with iLM params
  3887. static function edit_ilm ($param, $itemid) {
  3888. // Descobrir o tipo de iLM:
  3889. global $DB, $USER, $CFG;
  3890. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3891. $pathtemp = $CFG->dataroot . '/temp/';
  3892. $contextuser = context_user::instance($USER->id);
  3893. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3894. $zip = new zip_packer();
  3895. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3896. $files_extract = null;
  3897. foreach ($files as $file) {
  3898. if (!$file->is_directory())
  3899. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3900. }
  3901. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3902. $typec = strtolower($iassign_t->type);
  3903. require_once 'ilm_handlers/' . $typec . '.php';
  3904. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3905. }
  3906. /// Function for register the new iLM (in database and in the directory)
  3907. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3908. // @param object $param An object with iLM params
  3909. static function copy_new_version_ilm ($param) {
  3910. global $DB, $CFG, $USER;
  3911. $itemid = $param->file;
  3912. $pathtemp = $CFG->dataroot . '/temp/';
  3913. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3914. //D echo "pathtemp=$pathtemp<br/>";
  3915. $contextuser = context_user::instance($USER->id);
  3916. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3917. $zip = new zip_packer();
  3918. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3919. $files_extract = null;
  3920. foreach ($files as $file) {
  3921. if (!$file->is_directory())
  3922. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3923. }
  3924. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3925. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3926. $typec = strtolower($iassign_t->type);
  3927. require_once 'ilm_handlers/' . $typec . '.php';
  3928. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  3929. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  3930. } // static function copy_new_version_ilm($param)
  3931. //VER::
  3932. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  3933. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  3934. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  3935. /// Function for change visibility of iLM
  3936. // @param int $ilm_id Id of iLM
  3937. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3938. static function visible_ilm ($ilm_id, $status) {
  3939. global $DB;
  3940. if ($status == 0)
  3941. $visible = 1;
  3942. else
  3943. $visible = 0;
  3944. $newentry = new stdClass();
  3945. $newentry->id = $ilm_id;
  3946. $newentry->enable = $visible;
  3947. if (!$DB->update_record("iassign_ilm", $newentry))
  3948. error(get_string('error_edit_ilm', 'iassign'));
  3949. }
  3950. /// Function for confirm change default iLM
  3951. // @param int $ilm_id Id of iLM
  3952. // @param int $ilm_parent Id of parent iLM
  3953. // @return string Return with an string for create default page confirmation
  3954. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3955. global $OUTPUT, $DB;
  3956. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3957. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3958. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3959. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3960. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3961. return $return;
  3962. }
  3963. /// Function for change the default iLM
  3964. // @see settings_ilm.php
  3965. // @param int $ilm_id Id of iLM
  3966. // @return int Return Id of default iLM
  3967. static function default_ilm ($ilm_id) {
  3968. global $DB;
  3969. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3970. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3971. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3972. $iassign_ilm_default->id = $iassign_ilm->id;
  3973. $iassign_ilm_default->parent = 0;
  3974. $iassign_ilm->parent = $iassign_ilm_default->id;
  3975. $iassign_ilm->id = 0;
  3976. $iassign_ilm_default->enable = 1;
  3977. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  3978. print_error('error_edit_ilm', 'iassign');
  3979. }
  3980. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  3981. if (!$inserted) {
  3982. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  3983. print_error($msg_error);
  3984. //xx print_error('error_add_ilm', 'iassign');
  3985. }
  3986. return $iassign_ilm_default->id;
  3987. } // static function default_ilm ($ilm_id)
  3988. /// Function for confirm delete iLM
  3989. // @param int $ilm_id Id of iLM
  3990. // @param int $ilm_parent Id of parent iLM
  3991. // @return string Return with an string for create delete page confirmation
  3992. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3993. global $OUTPUT, $DB;
  3994. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3995. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3996. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3997. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3998. }
  3999. /// Function for delete directory where the iLM is allocated.
  4000. // @param string $dirPath
  4001. // @throws InvalidArgumentException
  4002. public static function delete_dir ($dirPath) {
  4003. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4004. $dirPath .= '/';
  4005. }
  4006. $files = glob($dirPath . '*', GLOB_MARK);
  4007. foreach ($files as $file) {
  4008. if (is_dir($file)) {
  4009. ilm_settings::delete_dir($file);
  4010. } else {
  4011. unlink($file);
  4012. }
  4013. }
  4014. rmdir($dirPath);
  4015. }
  4016. /// Function for delete iLM
  4017. // @param int $ilm_id Id of iLM
  4018. // @return int Return Id of parent iLM
  4019. static function delete_ilm ($ilm_id) {
  4020. global $DB;
  4021. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4022. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4023. $typec = strtolower($iassign_ilm->type);
  4024. require_once 'ilm_handlers/' . $typec . '.php';
  4025. $retorno = $typec::delete_ilm($ilm_id);
  4026. return $retorno;
  4027. }
  4028. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4029. // @param int $ilm_id Id of iLM
  4030. static function export_ilm ($ilm_id) {
  4031. global $DB;
  4032. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4033. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4034. $typec = strtolower($iassign_ilm->type);
  4035. require_once 'ilm_handlers/' . $typec . '.php';
  4036. $typec::export_ilm($ilm_id);
  4037. } // static function export_ilm($ilm_id)
  4038. //TODO iLM_HTML5 :: //MOOC 2016
  4039. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4040. // @param int $ilm_id Id of iLM
  4041. static function export_update_ilm ($ilm_id) {
  4042. global $DB, $CFG;
  4043. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4044. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4045. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4046. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4047. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4048. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4049. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4050. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4051. $upgrade_descriptor .= '</upgrade>' . "\n";
  4052. file_put_contents($xml_filename, $upgrade_descriptor);
  4053. header("Pragma: public");
  4054. header("Expires: 0");
  4055. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4056. header("Cache-Control: private", false);
  4057. header('Content-Type: application/xml; charset=utf-8');
  4058. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4059. header("Content-Length: " . @filesize($xml_filename));
  4060. set_time_limit(0);
  4061. @readfile("$xml_filename") || die("File not found.");
  4062. unlink($xml_filename);
  4063. exit;
  4064. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4065. /// Function for save iLM from XML descriptor
  4066. // @param array $application_xml Data of XML descriptor
  4067. // @param array $files_extract Filenames of extract files
  4068. // @return array Return an array content id of JAR files
  4069. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4070. global $CFG, $USER;
  4071. // Tratamento diferenciado se for do tipo HTML5:
  4072. $source = "";
  4073. $diretorio = "";
  4074. if (strtolower($application_xml->type) == 'html5') {
  4075. $i = 0;
  4076. foreach ($files_extract as $key => $value) {
  4077. $file = $CFG->dataroot . '/temp/' . $key;
  4078. // Verifica se já existe a pasta no diretório dos iLM:
  4079. if ($i == 0) {
  4080. $source = $file;
  4081. if (file_exists("ilm/" . basename($file))) {
  4082. $j = 1;
  4083. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4084. $j ++;
  4085. }
  4086. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4087. // mkdir($diretorio, 0777, true);
  4088. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4089. }
  4090. else {
  4091. $diretorio = 'ilm/' . basename($file);
  4092. // mkdir($diretorio, 0777, true);
  4093. mkdir($diretorio, 0755, true);
  4094. }
  4095. break;
  4096. }
  4097. $i ++;
  4098. }
  4099. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4100. if ($item->isDir()) {
  4101. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4102. }
  4103. else {
  4104. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4105. }
  4106. }
  4107. ilm_settings::delete_dir($source);
  4108. return "./" . $diretorio;
  4109. }
  4110. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4111. $file_jar = array();
  4112. $files_ilm = explode(",", $application_xml->file_jar);
  4113. $contextsystem = context_system::instance();
  4114. foreach ($files_ilm as $value) {
  4115. $file_ilm = array(
  4116. 'userid' => $USER->id,
  4117. 'contextid' => $contextsystem->id,
  4118. 'component' => 'mod_iassign',
  4119. 'filearea' => 'ilm',
  4120. 'itemid' => rand(1, 999999999),
  4121. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4122. 'filename' => $value);
  4123. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4124. array_push($file_jar, $file_ilm->get_id());
  4125. }
  4126. foreach ($files_extract as $key => $value) {
  4127. $file = $CFG->dataroot . '/temp/' . $key;
  4128. if (file_exists($file))
  4129. unlink($file);
  4130. }
  4131. return $file_jar;
  4132. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4133. /// Function for import the iLM from an package
  4134. // @param int $itemid Itemid of zip file
  4135. static function import_ilm ($itemid) {
  4136. global $CFG, $USER, $OUTPUT;
  4137. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4138. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4139. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4140. }
  4141. $pathtemp = $CFG->dataroot . '/temp/';
  4142. $contextuser = context_user::instance($USER->id);
  4143. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4144. $zip = new zip_packer();
  4145. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4146. foreach ($files as $file) {
  4147. if (!$file->is_directory())
  4148. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4149. }
  4150. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4151. // Verifica se o pacote possui o XML
  4152. if (!$application_xml) {
  4153. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4154. return;
  4155. } else {
  4156. $missing = "";
  4157. if (!isset($application_xml->name)) {
  4158. $missing .= "name";
  4159. }
  4160. if (!isset($application_xml->version)) {
  4161. $missing .= ", version";
  4162. }
  4163. if (!isset($application_xml->type)) {
  4164. $missing .= ", type";
  4165. }
  4166. if (!isset($application_xml->extension)) {
  4167. $missing .= ", extension";
  4168. }
  4169. if (!isset($application_xml->file_jar)) {
  4170. $missing .= ", file_jar";
  4171. }
  4172. if (!isset($application_xml->file_class)) {
  4173. $missing .= ", file_class";
  4174. }
  4175. if (!isset($application_xml->width)) {
  4176. $missing .= ", width";
  4177. }
  4178. if (!isset($application_xml->height)) {
  4179. $missing .= ", height";
  4180. }
  4181. if (!isset($application_xml->evaluate)) {
  4182. $missing .= ", evaluate";
  4183. }
  4184. if (strlen($missing) > 2) {
  4185. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4186. return;
  4187. }
  4188. }
  4189. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4190. $typec = strtolower($application_xml->type);
  4191. require_once 'ilm_handlers/' . $typec . '.php';
  4192. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4193. } // static function import_ilm($itemid)
  4194. /// Function for list iLM defaults
  4195. // @return string Return an string with a table of iLM
  4196. static function list_ilm () {
  4197. global $DB, $OUTPUT;
  4198. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4199. $str = '';
  4200. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4201. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4202. if ($iassign_ilm) {
  4203. foreach ($iassign_ilm as $ilm) {
  4204. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4205. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4206. $str .= '<tr><td>';
  4207. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4208. $str .= '<tr>';
  4209. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4210. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4211. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4212. $str .= '</tr>';
  4213. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4214. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4215. $str .= '</table>';
  4216. $str .= '</td></tr>';
  4217. }
  4218. }
  4219. $str .= '</table>';
  4220. return $str;
  4221. }
  4222. /// Function for download and install an upgrade of an iLM
  4223. // @param int $ilm_id Id of iLM
  4224. static function upgrade_ilm ($ilm_id) {
  4225. global $DB, $CFG, $USER;
  4226. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4227. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4228. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4229. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4230. if (!$result)
  4231. print_error('error_upgrade_ilm', 'iassign');
  4232. else {
  4233. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4234. $extension = explode(".", $zip_filename);
  4235. if ($extension[count($extension) - 1] != 'ipz') {
  4236. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4237. die;
  4238. }
  4239. $zip = new zip_packer();
  4240. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4241. $contextuser = context_user::instance($USER->id);
  4242. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4243. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4244. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4245. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4246. if (file_exists($zip_filename))
  4247. unlink($zip_filename);
  4248. if (empty($file_jar)) {
  4249. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4250. print_error($msg_error);
  4251. //xx print_error('error_add_ilm', 'iassign');
  4252. }
  4253. else {
  4254. $newentry = new stdClass();
  4255. $newentry->name = (String) $application_xml->name;
  4256. $newentry->version = (String) $application_xml->version;
  4257. $newentry->url = (String) $application_xml->url;
  4258. $newentry->description = $description_str;
  4259. $newentry->extension = strtolower((String) $application_xml->extension);
  4260. $newentry->file_jar = implode(",", $file_jar);
  4261. $newentry->file_class = (String) $application_xml->file_class;
  4262. $newentry->width = (String) $application_xml->width;
  4263. $newentry->height = (String) $application_xml->height;
  4264. $newentry->enable = 0;
  4265. $newentry->timemodified = time();
  4266. $newentry->author = $USER->id;
  4267. $newentry->timecreated = time();
  4268. $newentry->evaluate = (String) $application_xml->evaluate;
  4269. $newentry->parent = $ilm_id;
  4270. }
  4271. }
  4272. return $iassign_ilm->id;
  4273. } // static function upgrade_ilm($ilm_id)
  4274. //MOOC2014 -- inicio
  4275. //TODO: REVIEW
  4276. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4277. // static function move_iassign($ilm_id)
  4278. //MOOC2014 -- final
  4279. /// Function for list iLM versions with all informations
  4280. // @return string Return an string with a table of iLM
  4281. static function view_ilm ($ilmid, $from) {
  4282. global $DB;
  4283. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4284. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4285. $typec = strtolower($iassign_ilm->type);
  4286. require_once 'ilm_handlers/' . $typec . '.php';
  4287. $retorno = $typec::view_ilm($ilmid, $from);
  4288. return $retorno;
  4289. }
  4290. /// Function for get form variables for add, edit, or copy iLM params
  4291. // @param int $ilm_param_id Id of iLM param
  4292. // @param string $action String with the action
  4293. // @return object Return an object with forms variables
  4294. static function add_edit_copy_param ($ilm_param_id, $action) {
  4295. global $DB;
  4296. require_once('params_form.php');
  4297. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4298. $param = new stdClass();
  4299. $param->action = $action;
  4300. $param->ilm_param_id = $ilm_param_id;
  4301. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4302. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4303. $type = $iassign_ilm_config->param_type;
  4304. if ($action == 'add') {
  4305. $param->title = get_string('add_ilm', 'iassign');
  4306. $param->iassign_ilmid = $ilm_param_id;
  4307. $param->param_name = "";
  4308. $param->param_value = "";
  4309. $param->description = "";
  4310. $param->visible = 1;
  4311. }
  4312. elseif ($action == 'edit') {
  4313. if ($iassign_ilm_config) {
  4314. $param->title = get_string('edit_ilm', 'iassign');
  4315. $param->id = $iassign_ilm_config->id;
  4316. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4317. $param->param_type = $type; //MOOC2014
  4318. $param->param_name = $iassign_ilm_config->param_name;
  4319. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4320. $param->param_value = $iassign_ilm_config->param_value;
  4321. else //MOOC2014
  4322. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4323. $param->param_value = $iassign_ilm_config->param_value;
  4324. $param->description = $iassign_ilm_config->description;
  4325. $param->visible = $iassign_ilm_config->visible;
  4326. }
  4327. }
  4328. elseif ($action == 'copy') {
  4329. if ($iassign_ilm_config) {
  4330. $param->title = get_string('copy_ilm', 'iassign');
  4331. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4332. $param->param_type = $type; //MOOC2014
  4333. $param->param_name = $iassign_ilm_config->param_name;
  4334. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4335. $param->param_value = $iassign_ilm_config->param_value;
  4336. else //MOOC2014
  4337. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4338. $param->description = $iassign_ilm_config->description;
  4339. $param->visible = $iassign_ilm_config->visible;
  4340. }
  4341. }
  4342. return $param;
  4343. } // static function add_edit_copy_param($ilm_param_id, $action)
  4344. /// Function for change visibility of iLM param
  4345. // @param int $ilm_param_id Id of iLM param
  4346. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4347. static function visible_param ($ilm_param_id, $status) {
  4348. global $DB, $CFG;
  4349. if ($status == 0)
  4350. $visible = 1;
  4351. else
  4352. $visible = 0;
  4353. $newentry = new stdClass();
  4354. $newentry->id = $ilm_param_id;
  4355. $newentry->visible = $visible;
  4356. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4357. error(get_string('error_edit_param', 'iassign'));
  4358. }
  4359. /// Function for save in database an new iLM param
  4360. // @param object $param An object with iLM params
  4361. static function add_param ($param) {
  4362. global $DB;
  4363. $newentry = new stdClass();
  4364. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4365. //MOOC2014 $newentry->param_name = $param->param_name;
  4366. $newentry->param_type = $param->param_type; //MOOC2014
  4367. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4368. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4369. $newentry->param_value = $param->param_value;
  4370. else //MOOC2014
  4371. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4372. $newentry->description = $param->description;
  4373. $newentry->visible = $param->visible;
  4374. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4375. if (!$newentry->id) {
  4376. print_error('error_add_param', 'iassign');
  4377. }
  4378. }
  4379. /// Function for save in database a iLM param edit
  4380. // @param object $param An object with iLM params
  4381. static function edit_param ($param) {
  4382. global $DB;
  4383. $updentry = new stdClass();
  4384. $updentry->id = $param->id;
  4385. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4386. $updentry->param_type = $param->param_type; //MOOC2014
  4387. // $updentry->param_name = $param->param_name;
  4388. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4389. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4390. $updentry->param_value = $param->param_value;
  4391. else //MOOC2014
  4392. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4393. $updentry->description = $param->description;
  4394. $updentry->visible = $param->visible;
  4395. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4396. error(get_string('error_edit_param', 'iassign'));
  4397. }
  4398. }
  4399. /// Function for save in database a iLM param copy
  4400. // @param object $param An object with iLM params
  4401. static function copy_param ($param) {
  4402. global $DB;
  4403. $newentry = new stdClass();
  4404. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4405. //$newentry->param_name = $param->param_name;
  4406. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4407. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4408. $newentry->param_value = $param->param_value;
  4409. else //MOOC2014
  4410. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4411. $newentry->description = $param->description;
  4412. $newentry->visible = $param->visible;
  4413. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4414. if (!$newentry->id) {
  4415. print_error('error_add_param', 'iassign');
  4416. }
  4417. }
  4418. /// Function for delete iLM param of database
  4419. // @param int $param_id Id of iLM param
  4420. static function delete_param ($param_id) {
  4421. global $DB;
  4422. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4423. print_error('error_delete_param', 'iassign');
  4424. }
  4425. }
  4426. } // class ilm_settings
  4427. /// Class for manage iLM files (editor).
  4428. class ilm_manager {
  4429. var $id; // course id
  4430. var $url;
  4431. var $from;
  4432. /// Constructor for the base ilm_manager class
  4433. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4434. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4435. function __construct ($id, $url, $from) {
  4436. $this->id = $id; // course id
  4437. $this->url = $url;
  4438. $this->from = $from;
  4439. }
  4440. /// Function to get iAssign content file in Moodle data (exercise)
  4441. // @calledby x function preview_ilm($iassign_ilm) :
  4442. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4443. function get_file_ilm () {
  4444. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4445. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4446. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4447. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4448. $md_file = $fs->get_file_by_id($fileid);
  4449. $ilm_content_file = $md_file->get_content();
  4450. return $ilm_content_file;
  4451. }
  4452. /// Function for creating a new file from the iLM online editor
  4453. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4454. function ilm_editor_new () {
  4455. global $CFG, $DB, $OUTPUT, $PAGE;
  4456. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4457. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4458. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4459. $context = context_course::instance($this->id);
  4460. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4461. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4462. if (!$iassign) {
  4463. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4464. die();
  4465. }
  4466. $temp = explode(",", $iassign->extension);
  4467. $extension = $temp[0]; // default extension for this iLM
  4468. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4469. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4470. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4471. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4472. if ($stringArchiveContent != NULL) {
  4473. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4474. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4475. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4476. $filename = optional_param('filename', NULL, PARAM_RAW);
  4477. //Leo $filename = iassign_utils::format_filename($filename); //
  4478. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4479. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4480. //2019/02 $arrayfilename = explode(".", $filename);
  4481. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4482. //2019/02 $count_dots = count($arrayfilename);
  4483. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4484. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4485. //2019/02 if ($last_name != $extension)
  4486. //2019/02 $filename = $filename . '.' . $extension;
  4487. //2019/02 }
  4488. //2019/02 else { // no extension...
  4489. //2019/02 $filename = $filename . '.' . $extension;
  4490. //2019/02 }
  4491. // Store the name of recent created file
  4492. $_SESSION['file_name'] = $filename;
  4493. //$this->write_file_iassign($string, $filename);
  4494. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4495. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4496. die();
  4497. }
  4498. else { // if ($stringArchiveContent != NULL)
  4499. // iLM On-line editor
  4500. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4501. $str_get_iLM = "window.frames.iLM";
  4502. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4503. }
  4504. else { // otherwise it is JAR named 'iLM'
  4505. $str_get_iLM = "document.iLM";
  4506. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4507. }
  4508. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4509. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4510. $files_array = '';
  4511. foreach ($files as $value) {
  4512. if ($value->get_filename() != ".")
  4513. $files_array .= "'" . $value->get_filename() . "',";
  4514. }
  4515. $files_array .= "''";
  4516. $file = null;
  4517. $ia_content = "";
  4518. $filename = "";
  4519. $error_files_exists = get_string('error_file_exists', 'iassign');
  4520. $output = "<script type='text/javascript'>
  4521. //<![CDATA[
  4522. //D alert('locallib.php: ilm_editor_new');
  4523. function submit_iLM_Answer () {
  4524. var docFormOnLineEditor = document.formEnvio;
  4525. var resposta_exerc = new Array(3);
  4526. var valor_resposta = new Array(3);
  4527. var sessao = new Array(3);
  4528. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4529. resposta_exerc[0] = doc_iLM.getAnswer();
  4530. valor_resposta[0] = doc_iLM.getEvaluation();
  4531. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4532. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4533. var files = new Array(" . $files_array . ");
  4534. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4535. if (docFormOnLineEditor.filename.value=='') {
  4536. // ERROR: the file name is empty
  4537. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4538. return false;
  4539. }
  4540. // }
  4541. for (i=0; i<files.length; i++) {
  4542. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4543. alert('" . $error_files_exists . "');
  4544. return false;
  4545. }
  4546. }
  4547. docFormOnLineEditor.submit();
  4548. return true;
  4549. }
  4550. //]]>
  4551. </script>\n";
  4552. $output .= "
  4553. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4554. $output .= $OUTPUT->box_start();
  4555. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4556. $output .= "
  4557. <table width='100%' cellpadding='20'>
  4558. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4559. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4560. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4561. </tr>
  4562. </table>\n";
  4563. $output .= $OUTPUT->box_end();
  4564. $output .= "<center>\n";
  4565. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4566. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4567. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4568. $output .= $output_ilm;
  4569. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4570. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4571. </center>
  4572. </form>\n";
  4573. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4574. $PAGE->navbar->add($title);
  4575. $PAGE->set_title($title);
  4576. $PAGE->set_heading($title); // insert title above the navigation bar
  4577. print $OUTPUT->header();
  4578. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4579. print $output;
  4580. print $OUTPUT->footer();
  4581. }
  4582. die();
  4583. } // function ilm_editor_new()
  4584. /// Function for editing an file in online editor
  4585. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4586. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4587. global $CFG, $DB, $OUTPUT, $PAGE;
  4588. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4589. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4590. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4591. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4592. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4593. // If iLM is not registered, error!
  4594. if (!$iassign) {
  4595. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4596. die;
  4597. }
  4598. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4599. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  4600. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4601. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4602. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4603. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4604. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4605. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4606. if ($stringArchiveContent != NULL) {
  4607. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4608. die();
  4609. } else { // if ($stringArchiveContent != NULL)
  4610. $end_file = '';
  4611. if ($content_file) {
  4612. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4613. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4614. }
  4615. $temp = explode(",", $iassign->extension);
  4616. $extension = $temp[0]; // default extension for this iLM
  4617. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4618. $str_get_iLM = "window.frames.iLM";
  4619. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4620. } else { // otherwise it is JAR named 'iLM'
  4621. $str_get_iLM = "document.iLM";
  4622. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4623. }
  4624. $output = "<script type='text/javascript'>
  4625. //<![CDATA[
  4626. function submit_iLM_Answer () {
  4627. var docFormEditor = document.formEnvio;
  4628. var activityAnswer; // to get activity answer (text)
  4629. var activityValue; // to get activity answer value (float)
  4630. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4631. //activityAnswer = doc_iLM.getAnswer();
  4632. //activityValue = doc_iLM.getEvaluation();
  4633. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4634. activityValue = " . $str_get_iLM . ".getEvaluation();
  4635. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4636. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4637. docFormEditor.submit();
  4638. return true;
  4639. }
  4640. //]]>
  4641. </script>\n";
  4642. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4643. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4644. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4645. // return true;
  4646. // }
  4647. $output .= "
  4648. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4649. $output .= $OUTPUT->box_start();
  4650. $output .= "
  4651. <table width='100%' cellpadding='20'>
  4652. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4653. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4654. <input type='hidden' name='filename' value='$filename'/></td>
  4655. <td>
  4656. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4657. </tr>
  4658. </table>\n";
  4659. $output .= $OUTPUT->box_end();
  4660. $output .= " <center>\n";
  4661. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4662. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4663. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4664. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4665. </center>
  4666. </form>\n";
  4667. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4668. $PAGE->navbar->add($title);
  4669. $PAGE->set_title($title);
  4670. $PAGE->set_heading($title); // insert title above the navigation bar
  4671. print $OUTPUT->header();
  4672. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4673. print $output;
  4674. print $OUTPUT->footer();
  4675. } // else if ($stringArchiveContent != NULL)
  4676. die();
  4677. } // function ilm_editor_update()
  4678. /// Function for write iAssign file in Moodle data (exercise)
  4679. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  4680. // @param string $stringArchiveContent Content of iassign file
  4681. // @param string $filename Filename of iassign file
  4682. function write_file_iassign ($stringArchiveContent, $filename) {
  4683. global $USER;
  4684. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4685. $context = context_course::instance($this->id);
  4686. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4687. $dirid = $this->get_dir_ilm('dirid');
  4688. $dir = $fs->get_file_by_id($dirid);
  4689. $fileinfo = array('contextid' => $context->id, // ID of course
  4690. 'component' => 'mod_iassign', // usually = table name
  4691. 'filearea' => 'activity', // usually = table name
  4692. 'itemid' => 0, // usually = ID of row in table
  4693. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4694. 'userid' => $USER->id,
  4695. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4696. 'filename' => $filename); // any filename
  4697. // Create file containing text. '$stringArchiveContent'
  4698. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4699. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4700. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4701. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4702. // 'Activité interactive enregistrée avec succès sous le nom:';
  4703. // 'Atividade interativa gravada com sucesso sob o nome:'
  4704. $output = "
  4705. <script type='text/javascript'>
  4706. //<![CDATA[
  4707. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4708. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4709. //]]>
  4710. </script>";
  4711. print $output;
  4712. die();
  4713. }
  4714. /// Function for write iAssign file in Moodle data (exercise)
  4715. // @param string $stringArchiveContent Content of iassign file
  4716. // @param string $filename Filename of iassign file
  4717. // @param int $itemid Itemid of iassign file
  4718. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4719. global $OUTPUT, $USER;
  4720. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4721. $context = context_course::instance($this->id);
  4722. $dirid = $this->get_dir_ilm('dirid');
  4723. if ($stringArchiveContent != (-1)) {
  4724. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4725. $file = $fs->get_file_by_id($fileid);
  4726. if (!$file) {
  4727. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4728. die;
  4729. }
  4730. $fileinfo = array('contextid' => $context->id, // ID of context
  4731. 'component' => 'mod_iassign', // usually = table name
  4732. 'filearea' => 'activity', // usually = table name
  4733. 'itemid' => 0, // usually = ID of row in table
  4734. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4735. 'userid' => $USER->id,
  4736. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4737. 'license' => 'allrightsreserved', // allrightsreserved
  4738. 'timecreated' => $file->get_timecreated(),
  4739. 'filename' => $file->get_filename()); // any filename
  4740. $file->delete();
  4741. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4742. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4743. }
  4744. $output = "<script type='text/javascript'>
  4745. //<![CDATA[
  4746. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4747. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4748. //]]>
  4749. </script>";
  4750. print $output;
  4751. die();
  4752. }
  4753. /// Function for create an tag for iAssign filter
  4754. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4755. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4756. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4757. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4758. // @param int $fileid Id of file
  4759. // @return string Return an string with an tag of iassign filter
  4760. function tag_ilm ($fileid) {
  4761. global $DB;
  4762. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4763. $width = '600';
  4764. $height = '400';
  4765. $file = $fs->get_file_by_id($fileid);
  4766. $filetype = explode(".", $file->get_filename());
  4767. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4768. foreach ($iassign_ilm as $value) {
  4769. $extensions = explode(",", $value->extension);
  4770. if (in_array($filetype[1], $extensions)) {
  4771. $width = $value->width;
  4772. $height = $value->height;
  4773. }
  4774. }
  4775. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4776. }
  4777. /// Function for delete iAssign file in Moodle data (exercise)
  4778. function delete_file_ilm () {
  4779. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4780. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4781. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4782. $file = $fs->get_file_by_id($fileid);
  4783. if ($file)
  4784. $file->delete();
  4785. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4786. die();
  4787. }
  4788. /// Function for delete selected iAssign file in Moodle data (exercise)
  4789. function delete_selected_ilm () {
  4790. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4791. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4792. $context = context_course::instance($this->id);
  4793. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4794. $dirid = $this->get_dir_ilm('dirid');
  4795. foreach ($files_id as $file_id) {
  4796. $file = $fs->get_file_by_id($file_id);
  4797. if ($file) {
  4798. if (!$file->is_directory())
  4799. $file->delete();
  4800. else {
  4801. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4802. foreach ($files_delete as $value)
  4803. $value->delete();
  4804. $file->delete();
  4805. }
  4806. }
  4807. }
  4808. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4809. die();
  4810. }
  4811. /// Function for duplicate iAssign file from "online" edition
  4812. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4813. function duplicate_file_ilm () {
  4814. global $USER, $COURSE;
  4815. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4816. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4817. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4818. $filename = optional_param('filename', NULL, PARAM_RAW);
  4819. $file = $fs->get_file_by_id($fileid);
  4820. $context = context_course::instance($this->id);
  4821. $fileinfo = array(
  4822. 'contextid' => $context->id, // ID of context
  4823. 'component' => 'mod_iassign', // usually = table name
  4824. 'filearea' => 'activity', // usually = table name
  4825. 'itemid' => 0, // usually = ID of row in table
  4826. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4827. 'userid' => $USER->id,
  4828. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4829. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4830. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4831. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4832. die();
  4833. }
  4834. /// Function for rename iAssign file
  4835. function rename_file_ilm () {
  4836. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4837. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4838. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4839. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4840. $file = $fs->get_file_by_id($fileid);
  4841. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4842. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4843. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4844. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4845. die();
  4846. }
  4847. /// Function for get iassign file for iassign form
  4848. function add_ilm () {
  4849. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4850. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4851. $output = "
  4852. <script type='text/javascript'>
  4853. //<![CDATA[
  4854. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4855. iassign_file_link.innerHTML = '$filename';
  4856. window.opener.document.forms['mform1'].file.value='$fileid';
  4857. window.opener.document.forms['mform1'].filename.value='$filename';
  4858. window.close();
  4859. //]]>
  4860. </script>";
  4861. print $output;
  4862. die();
  4863. }
  4864. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4865. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4866. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4867. function preview_ilm ($courseid, $iassign_ilm) {
  4868. global $OUTPUT, $CFG, $USER;
  4869. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4870. $title = get_string('modulename', 'iassign'); // iAssign
  4871. print $OUTPUT->header();
  4872. print $OUTPUT->box_start();
  4873. $javascript = "
  4874. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4875. <script type='text/javascript'>
  4876. //<![CDATA[
  4877. function submit_close () {
  4878. window.opener.location.reload();
  4879. window.close();
  4880. }
  4881. //]]>
  4882. </script>\n";
  4883. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4884. // to the complete "applet" tag
  4885. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4886. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4887. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4888. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4889. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4890. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4891. if ($ilm_name != "ivprog") {
  4892. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4893. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4894. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4895. } else {
  4896. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4897. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4898. $timecreated = time();
  4899. $token = md5($timecreated);
  4900. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4901. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4902. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4903. $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)
  4904. }
  4905. $html = "
  4906. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4907. <table border='1'>
  4908. <tr><td>
  4909. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4910. <!-- iLM calls : end -->
  4911. </td></tr>
  4912. </table>
  4913. <table>
  4914. <tr>
  4915. <td align='center'>
  4916. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4917. </td></tr>
  4918. </table>
  4919. </form>\n";
  4920. print $javascript . $html;
  4921. print $OUTPUT->box_end();
  4922. //NAO echo format_string($html); // Moodle 3.X
  4923. die();
  4924. } // function preview_ilm($courseid, $iassign_ilm)
  4925. //r_ function preview_ilm ($iassign_ilm)
  4926. //r_ /// Function for preview iassign file from iassign filter.
  4927. //r_ function preview_ilm() {
  4928. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4929. //r_ $tag_filter = $this->tag_ilm($fileid);
  4930. //r_ $javascript = "<script type='text/javascript'>
  4931. //r_ //<![CDATA[
  4932. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4933. //r_ //]]>
  4934. //r_ </script>";
  4935. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4936. //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>
  4937. //r_ </table></form></body></html>";
  4938. //r_ echo $javascript . format_text($html);
  4939. //r_ die;
  4940. //r_ }
  4941. /// Function for export an package (zip) of iassign files
  4942. function export_files_ilm () {
  4943. global $CFG;
  4944. $context = context_course::instance($this->id);
  4945. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4946. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4947. $zip = new zip_archive();
  4948. $zip->open($zip_filename);
  4949. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4950. foreach ($files_id as $file_id) {
  4951. $file = $fs->get_file_by_id($file_id);
  4952. if (!$file->is_directory())
  4953. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4954. else {
  4955. $zip->add_directory($file->get_filepath());
  4956. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4957. foreach ($files_zip as $value) {
  4958. if (!$value->is_directory())
  4959. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4960. else
  4961. $zip->add_directory($value->get_filepath());
  4962. }
  4963. }
  4964. }
  4965. $zip->close();
  4966. header("Pragma: public");
  4967. header("Expires: 0");
  4968. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4969. header("Cache-Control: private", false);
  4970. header("Content-Type: application/zip");
  4971. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4972. header("Content-Transfer-Encoding: binary");
  4973. header("Content-Length: " . @filesize($zip_filename));
  4974. set_time_limit(0);
  4975. @readfile("$zip_filename") || die("File not found.");
  4976. unlink($zip_filename);
  4977. exit;
  4978. }
  4979. /// Function of execute a command in button editor tinymce
  4980. // @param int $fileid Id of file
  4981. function tinymce_ilm ($fileid) {
  4982. $tag_filter = $this->tag_ilm($fileid);
  4983. $output = "<script type='text/javascript'>
  4984. //<![CDATA[
  4985. var tag_filter = '$tag_filter';
  4986. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4987. // all right, insert it
  4988. } else {
  4989. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4990. }
  4991. // window.close();
  4992. //]]>
  4993. </script>\n";
  4994. print $output;
  4995. die();
  4996. }
  4997. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4998. /// Function to add content to the Editor Window
  4999. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5000. // @param int $fileid Id of file
  5001. function editor_ilm ($fileid, $editor) {
  5002. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5003. $output1 = "<script type='text/javascript'>
  5004. //<![CDATA[
  5005. var tag_filter = '$tag_filter';\n";
  5006. if ($editor == 'atto') {
  5007. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5008. } elseif ($editor == 'tinyMCE') {
  5009. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5010. } else
  5011. $output2 = "";
  5012. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5013. window.close();
  5014. //]]>
  5015. </script>\n";
  5016. //D var_dump($output);
  5017. print $output1 . $output2 . $output3;
  5018. die();
  5019. }
  5020. /// Function to add content to the Atto Editor Window
  5021. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5022. // @param int $fileid Id of file
  5023. function atto_ilm ($fileid) {
  5024. global $CFG, $DB;
  5025. $tag_filter = $this->tag_ilm($fileid);
  5026. $output = "<script type='text/javascript'>
  5027. //<![CDATA[
  5028. var tag_filter = '$tag_filter';
  5029. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5030. // all right, insert iLM tag to this editor
  5031. } else {
  5032. // error trying to insert
  5033. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5034. }
  5035. //window.close();
  5036. //]]>
  5037. </script>\n";
  5038. print $output;
  5039. die();
  5040. }
  5041. /// Function for get path and infos of dirs: dirid, dir_base, dir_parent, dir_home
  5042. // @param string $key Key for return information
  5043. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5044. function get_dir_ilm ($key) {
  5045. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5046. $context = context_course::instance($this->id);
  5047. $dirid = optional_param('dirid', 0, PARAM_INT);
  5048. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5049. if ($dirid == 0) {
  5050. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5051. $dirid = $dir->get_id();
  5052. } else {
  5053. $dir = $fs->get_file_by_id($dirid);
  5054. $dir_base = $dir->get_filepath();
  5055. }
  5056. $dir_parent = $dir->get_parent_directory();
  5057. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5058. return $data[$key];
  5059. }
  5060. /// Function for create an new dir
  5061. function new_dir_ilm () {
  5062. global $USER;
  5063. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5064. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5065. $dir_base = $this->get_dir_ilm('dir_base');
  5066. $context = context_course::instance($this->id);
  5067. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5068. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5069. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5070. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5071. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5072. }
  5073. /// Function for delete an dir
  5074. function delete_dir_ilm () { //
  5075. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5076. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5077. $context = context_course::instance($this->id);
  5078. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5079. $dir_parent = $this->get_dir_ilm('dir_parent');
  5080. if ($dir) {
  5081. if ($dir->is_directory()) {
  5082. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5083. foreach ($files_delete as $value)
  5084. $value->delete();
  5085. $dir->delete();
  5086. }
  5087. }
  5088. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5089. die();
  5090. }
  5091. /// Function for rename an dir
  5092. function rename_dir_ilm () {
  5093. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5094. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5095. $context = context_course::instance($this->id);
  5096. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5097. $dir_parent = $this->get_dir_ilm('dir_parent');
  5098. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5099. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5100. if ($dir->is_directory()) {
  5101. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5102. foreach ($files_rename_path as $value)
  5103. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5104. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5105. }
  5106. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5107. die();
  5108. }
  5109. /// Function for move an dir and your content for other dir
  5110. function selected_move_ilm () {
  5111. global $PAGE, $OUTPUT, $CFG;
  5112. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5113. $context = context_course::instance($this->id);
  5114. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5115. $dirid = $this->get_dir_ilm('dirid');
  5116. $dir_base = $this->get_dir_ilm('dir_base');
  5117. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5118. $code_javascript_ilm = "
  5119. <script type='text/javascript'>
  5120. //<![CDATA[
  5121. function getRadiobutton () {
  5122. var radioButtons = document.getElementsByTagName('input');
  5123. var param = '';
  5124. for (var counter=0; counter < radioButtons.length; counter++) {
  5125. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5126. param = radioButtons[counter].value;
  5127. }
  5128. return param;
  5129. }
  5130. function move_selected_ilm () {
  5131. var msgAnswer;
  5132. if (getRadiobutton() != '') {
  5133. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5134. if (msgAnswer)
  5135. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5136. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5137. }
  5138. else
  5139. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5140. }
  5141. function cancel_selected_ilm () {
  5142. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5143. }
  5144. //]]>
  5145. </script>\n";
  5146. $title = get_string('move_files', 'iassign');
  5147. $PAGE->set_title($title);
  5148. $PAGE->set_pagelayout('base');
  5149. print $OUTPUT->header();
  5150. print $OUTPUT->heading($title);
  5151. $dir_paths = array();
  5152. print $OUTPUT->box_start();
  5153. print "<center>";
  5154. foreach ($files_id as $file_id) {
  5155. $file = $fs->get_file_by_id($file_id);
  5156. if ($file) {
  5157. if (!$file->is_directory())
  5158. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5159. else {
  5160. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5161. array_push($dir_paths, $file->get_filepath());
  5162. }
  5163. }
  5164. }
  5165. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5166. if ($dir_base != '/') {
  5167. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5168. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5169. }
  5170. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5171. foreach ($files_tree as $file) {
  5172. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5173. $is_parent = false;
  5174. foreach ($dir_paths as $dir) {
  5175. $path = explode("/", $dir);
  5176. array_pop($path);
  5177. $path[count($path) - 1] = '';
  5178. $path = implode("/", $path);
  5179. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5180. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5181. }
  5182. if ($is_parent == false) {
  5183. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5184. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5185. }
  5186. }
  5187. }
  5188. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5189. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5190. print "</center>";
  5191. print $OUTPUT->box_end();
  5192. print $OUTPUT->footer();
  5193. print $code_javascript_ilm;
  5194. die;
  5195. }
  5196. /// Function for move files for an dir
  5197. function move_files_ilm () {
  5198. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5199. $context = context_course::instance($this->id);
  5200. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5201. $dirid = $this->get_dir_ilm('dirid');
  5202. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5203. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5204. foreach ($files_id as $file_id) {
  5205. $file = $fs->get_file_by_id($file_id);
  5206. if ($file) {
  5207. if ($file->is_directory()) {
  5208. $pathname = explode("/", $file->get_filepath());
  5209. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5210. foreach ($files_move_path as $value) {
  5211. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5212. $value->rename($path_move, $value->get_filename());
  5213. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5214. }
  5215. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5216. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5217. $file->rename($path_move, $file->get_filename());
  5218. } else {
  5219. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5220. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5221. }
  5222. }
  5223. }
  5224. //die;
  5225. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5226. die();
  5227. } // function move_files_ilm()
  5228. /// Function for recover files in use on all activities of a course
  5229. function recover_files_ilm () {
  5230. global $DB, $USER;
  5231. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5232. $courseid = optional_param('id', NULL, PARAM_INT);
  5233. $dirid = $this->get_dir_ilm('dirid');
  5234. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5235. $contextfile = context_course::instance($this->id);
  5236. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5237. foreach ($iassigns as $iassign) {
  5238. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5239. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5240. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5241. $context = context_module::instance($cm->id);
  5242. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5243. if ($files) {
  5244. foreach ($files as $value) {
  5245. $extension = explode(".", $value->get_filename());
  5246. if (!$value->is_directory()) {
  5247. $fileinfo = array('contextid' => $contextfile->id,
  5248. 'component' => 'mod_iassign',
  5249. 'filearea' => 'activity',
  5250. 'itemid' => 0,
  5251. 'filepath' => $this->get_dir_ilm('dir_base'),
  5252. 'userid' => $USER->id,
  5253. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5254. 'license' => 'allrightsreserved',
  5255. 'timecreated' => time(),
  5256. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5257. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5258. }
  5259. }
  5260. } // if ($files)
  5261. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5262. } // foreach ($iassigns as $iassign)
  5263. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5264. die();
  5265. } // function recover_files_ilm()
  5266. /// Auxiliary function the get all files in a given context
  5267. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5268. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5269. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5270. function get_files_in_context (&$allfiles, $contextid, $extension, $userid) {
  5271. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5272. // (NAO s_iassign_statement.file = s_files.id)
  5273. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5274. $dir_base = $this->get_dir_ilm('dir_base');
  5275. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5276. $countf = 0;
  5277. $array_files_id = array(); // all files from this context
  5278. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5279. //$filename = $item_fc->get_filename();
  5280. //$filepath = $item_fc->get_filepath();
  5281. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5282. //$fileuserid = $item_fc->get_userid(); // get user.id of the author
  5283. // $array_files_aux[] = $item_fc;
  5284. $itemid = $item_fc->get_id();
  5285. if (!in_array($itemid, $array_files_id)) {
  5286. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5287. $allfiles[] = $item_fc;
  5288. $array_files_id[] = $itemid;
  5289. $countf++;
  5290. }
  5291. }
  5292. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5293. return $countf;
  5294. }
  5295. /// List iassign files from course directory
  5296. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5297. function view_files_ilm ($iassign_ilm_class, $extension, $start = 0) {
  5298. //TODO usar $start para trazer no maximo 50 arquivos iniciando em $start
  5299. global $CFG, $DB, $USER, $OUTPUT;
  5300. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5301. $context = context_course::instance($this->id); // $this->id = ID of the current course
  5302. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5303. $dirid = $this->get_dir_ilm('dirid');
  5304. $dir_base = $this->get_dir_ilm('dir_base');
  5305. // Get all files in module iAssign
  5306. // -- start
  5307. $array_all_files = array(); // all files from all context.id (in data decreasing order)
  5308. $array_contextid_files = array(); // context.id in data decreasing order
  5309. $array_contextid_files_aux = array(); // all context.id in data creasing order
  5310. // Get all files from table '*_files': id ; contenthash ; pathnamehash ; contextid ; component ;... filename ; userid ...
  5311. // $DB is 'mysqli_native_moodle_database' object
  5312. // if (has_capability("moodle/site:config", $context, $USER->id, true))
  5313. // if (has_capability("mod/iassign:addinstance", $context, $USER->id, true))
  5314. $hascapability = has_capability("moodle/site:config", $context, $USER->id); // *_capabilities="moodle/site:config" : greatest one)
  5315. if ($hascapability==1) {
  5316. //$array_query = array('component' => 'mod_iassign');
  5317. $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity'";
  5318. }
  5319. else {
  5320. // $array_query = array('component' => 'mod_iassign', 'userid' => $USER->id);
  5321. $query_sql = "SELECT * FROM {files} WHERE component='mod_iassign' AND filearea='activity' AND " .
  5322. " (license<>'allrightsreserved' OR contextid=" . $context->id . " OR userid=" . $USER->id . ")";
  5323. }
  5324. // files : id contenthash pathnamehash contextid component filearea itemid filepath filename userid filesize mimetype status source author license timecreated timemodified sortorder referencefileid
  5325. // $files_iassign = $DB->get_records('files', $array_query); // extensions for all iLM...
  5326. $files_iassign = $DB->get_records_sql($query_sql);
  5327. //D echo "view_files_ilm: " . $USER->id . ", " . $hascapability . ": " . $query_sql . "<br/>";
  5328. //D SELECT id,contextid,component,filearea,itemid,filepath,filename,userid FROM s_files WHERE component='mod_iassign' AND filearea='exercise';
  5329. $count_all_files = 0;
  5330. $count_files_with_ext = 0;
  5331. $count_thisauthor_contextid = 0;
  5332. $count_otherauthors_contextid = 0;
  5333. //D echo "view_files_ilm: user.id=" . $USER->id . ", ext=$extension, #files=" . count($files_iassign) . "<br/>";
  5334. if (is_array($files_iassign))
  5335. foreach ($files_iassign as $item_files_iassign) {
  5336. $extensionF = explode(".", $item_files_iassign->filename); // $item_files_iassign->get_filename()
  5337. $lastitem = sizeof($extensionF);
  5338. if ($lastitem>0) $lastitem--;
  5339. else { echo ".";// error: it must have extension (after ".")
  5340. continue;}
  5341. $str_extension = $extensionF[$lastitem];
  5342. $count_files_with_ext++;
  5343. if ($extension == $str_extension) {
  5344. $contextid = $item_files_iassign->contextid;
  5345. if (!in_array($contextid, $array_contextid_files_aux)) { // not yet in array of context with this extension
  5346. $array_contextid_files_aux[] = $contextid;
  5347. $total_in_context = $this->get_files_in_context($array_all_files, $contextid, $extension, $USER->id); // $array_all_files by reference
  5348. $count_all_files += $total_in_context;
  5349. }
  5350. }
  5351. }
  5352. //D echo "view_files_ilm: #array_contextid_files_aux=".count($array_contextid_files_aux). ", count_all_files=$count_all_files<br/>";
  5353. //view_files_ilm: #array_contextid_files_aux=54
  5354. //TODO Deste modo vem: se ADMIN => todos os arquivos de extensao compativel; senao todos os arquivos do usuario
  5355. //TODO Implementar: se NAO ADMIN => pegar TODOS os arquivos do curso
  5356. //TODO Tabela pegar todos '*_files.contextid' tais que '*_files.component=="mod_iassign"'
  5357. $array_files_course = array();
  5358. $dirs_array = ''; // if there are none 'exercise' file
  5359. $files_array = ''; // idem
  5360. $files_array = "''"; // idem
  5361. $error_files_exists = "''"; // idem
  5362. for ($ii=$count_all_files-1; $ii>0; $ii--) {
  5363. //$contextid = $array_contextid_files[$ii];
  5364. //$files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5365. //$array_files_course[] = $files_course;
  5366. $files_course = $array_all_files[$ii];
  5367. $files_array = '';
  5368. $files_array .= "''";
  5369. $error_files_exists = get_string('error_file_exists', 'iassign');
  5370. $dirs_array = '';
  5371. foreach ($files_course as $one_file) {
  5372. if (!$one_file->is_directory())
  5373. $files_array .= "'" . $one_file->get_filename() . "',";
  5374. else { //if ($one_file->is_directory())
  5375. $pathname = explode("/", substr($one_file->get_filepath(), 0, strlen($one_file->get_filepath()) - 1));
  5376. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5377. }
  5378. } // foreach ($files_course as $one_file)
  5379. } // for ($ii=0; $ii<$num_contexts; $ii++)
  5380. print "#" . $count_all_files . "<br/>";
  5381. // -- end
  5382. $dirs_array .= "''";
  5383. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5384. //TODO Rever o 'preview' pois soh poder deixar ver uma vez
  5385. $code_javascript_ilm = "
  5386. <script type='text/javascript'>
  5387. //<![CDATA[
  5388. function preview_ilm (fileid, ilmid) { //JavaScript function
  5389. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5390. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5391. }
  5392. function update_ilm (ilmid, fileid) { //JavaScript function
  5393. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5394. }
  5395. function delete_ilm (ilmid, fileid) { //JavaScript function
  5396. var msgAnswer;
  5397. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5398. if (msgAnswer) {
  5399. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5400. }
  5401. }
  5402. function delete_selected_ilm () { //JavaScript function
  5403. var msgAnswer;
  5404. var param = getCheckbox();
  5405. if (param.join() != '') {
  5406. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5407. if (msgAnswer)
  5408. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5409. }
  5410. else
  5411. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5412. }
  5413. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5414. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5415. }
  5416. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5417. var filenamecopy;
  5418. var i;
  5419. var files = new Array($files_array);
  5420. do {
  5421. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5422. } while (filenamecopy == '');
  5423. if (filenamecopy == null)
  5424. return false;\n
  5425. else {
  5426. for (i=0;i<files.length;i++) {
  5427. if (files[i]==filenamecopy) {
  5428. alert('$error_files_exists');
  5429. return false;\n
  5430. }
  5431. }\n" .
  5432. // @see: function 'duplicate_file_ilm()' above
  5433. "
  5434. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5435. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5436. } // else
  5437. }
  5438. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5439. var filenamecopy;
  5440. var i;
  5441. var files = new Array($files_array);
  5442. do {
  5443. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5444. } while (filenamecopy == '');
  5445. if (filenamecopy == null)
  5446. return false;
  5447. else {
  5448. for (i=0;i<files.length;i++) {
  5449. if (files[i]==filenamecopy) {
  5450. alert('$error_files_exists');
  5451. return false;
  5452. }
  5453. }
  5454. 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;
  5455. }
  5456. }
  5457. function export_files_ilm () { //JavaScript function
  5458. var param = getCheckbox();
  5459. if (param.join() != '')
  5460. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5461. else
  5462. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5463. }
  5464. function select_all_ilm () { //JavaScript function
  5465. var checkBoxes = document.getElementsByTagName('input');
  5466. var selectAll = document.getElementById('select_all');
  5467. for (var counter=0; counter < checkBoxes.length; counter++) {
  5468. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5469. checkBoxes[counter].checked = selectAll.checked;
  5470. }
  5471. }
  5472. function getCheckbox () { //JavaScript function
  5473. var checkBoxes = document.getElementsByTagName('input');
  5474. var param = new Array();
  5475. for (var counter=0; counter < checkBoxes.length; counter++) {
  5476. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5477. param.push(checkBoxes[counter].value);
  5478. }
  5479. return param;
  5480. }
  5481. function new_dir_ilm () { //JavaScript function
  5482. var dirname = '';
  5483. var i;
  5484. var dirs = new Array($dirs_array);
  5485. do {
  5486. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5487. } while (dirname == '');
  5488. if (dirname == null)
  5489. return false;\n
  5490. else {
  5491. for (i=0;i<dirs.length;i++) {
  5492. if (dirs[i]==dirname) {
  5493. alert('$error_dir_exists');
  5494. return false;\n
  5495. }
  5496. }
  5497. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5498. }
  5499. }
  5500. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5501. var msgAnswer;
  5502. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5503. if (msgAnswer) {
  5504. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5505. }
  5506. }
  5507. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5508. var dirnamecopy;
  5509. var i;
  5510. var dirs = new Array($dirs_array);
  5511. do {
  5512. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5513. } while (dirnamecopy == '');
  5514. if (dirnamecopy == null)
  5515. return false;\n
  5516. else {
  5517. for (i=0;i<dirs.length;i++) {
  5518. if (dirs[i]==dirnamecopy) {
  5519. alert('$error_dir_exists');
  5520. return false;\n
  5521. }
  5522. }
  5523. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5524. }
  5525. }
  5526. function move_selected_ilm (ilmid) { //JavaScript function
  5527. var param = getCheckbox();
  5528. if (param.join() != '')
  5529. 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();
  5530. else
  5531. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5532. }
  5533. function recover_files_ilm () { //JavaScript function
  5534. var msgAnswer;
  5535. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5536. if (msgAnswer) {
  5537. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5538. }
  5539. }
  5540. window.onload = function() { //JavaScript function
  5541. var xPosition = 0;
  5542. var yPosition = 0;
  5543. element=document.getElementById('new_file');
  5544. while(element) {
  5545. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5546. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5547. element = element.offsetParent;
  5548. }
  5549. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5550. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5551. location.hash = '#new_file';
  5552. };
  5553. //]]>
  5554. </script>\n"; // end of $code_javascript_ilm
  5555. $output = "";
  5556. $select_all = "";
  5557. $count_files = 0;
  5558. $extensions_allow = array();
  5559. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5560. foreach ($iassign_ilm as $item_iassign_ilm)
  5561. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5562. //Estava foreach ($files_course as $one_file)
  5563. for ($ii=$count_all_files-1; $ii>0; $ii--) { // function view_files_ilm ($iassign_ilm_class, $extension)
  5564. //$contextid = $array_contextid_files[$ii]; // Notice: Undefined offset: 2257 in /var/www/html/saw/mod/iassign/locallib.php on line 6333
  5565. //$files_course = $array_files_course[$ii];
  5566. $one_file = $array_all_files[$ii];
  5567. $filename = $one_file->get_filename();
  5568. $filepath = $one_file->get_filepath();
  5569. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5570. $pathname = $pathname[count($pathname) - 1];
  5571. $fileid = $one_file->get_id();
  5572. $tmp = explode(".", $filename);
  5573. if (is_array($tmp)) { // define file type
  5574. if (sizeof($tmp)>1)
  5575. $filetype = $tmp[1];
  5576. else
  5577. $filetype = $extension;
  5578. }
  5579. else
  5580. $filetype = $extension;
  5581. $author = $one_file->get_author();
  5582. $timemodified = date("d/m/Y H:i:s", $one_file->get_timemodified());
  5583. $timecreated = date("d/m/Y H:i:s", $one_file->get_timecreated());
  5584. $extensions = explode(",", $extension);
  5585. if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5586. $count_files ++;
  5587. // buscar fileid nas tabelas do iassign
  5588. $list_filein_use = "";
  5589. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5590. if ($iassign_statement_activity_list) {
  5591. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5592. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5593. }
  5594. }
  5595. $array_iassign_ilm = $DB->get_records("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1'));
  5596. foreach ($array_iassign_ilm as $iassign_ilm) { // get files from all iLM equivalent
  5597. if (!$iassign_ilm) {
  5598. $iassign_ilm = new stdClass();
  5599. $iassign_ilm->id = $ilmid;
  5600. }
  5601. // Do not use $var inside "..." - problem with some "unusual" operational system
  5602. $url = $CFG->wwwroot . "/pluginfile.php/" . $one_file->get_contextid() . "/mod_iassign/activity";
  5603. $fileurl = $url . '/' . $one_file->get_itemid() . $filepath . $filename;
  5604. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5605. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5606. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5607. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5608. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5609. $check_select = "";
  5610. $link_rename = "";
  5611. $link_delete = "";
  5612. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5613. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5614. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5615. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5616. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5617. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5618. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5619. if ($one_file->get_userid() == $USER->id) {
  5620. if ($iassign_statement_activity_list) {
  5621. $check_select = "";
  5622. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5623. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5624. $link_rename = "";
  5625. }
  5626. else {
  5627. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5628. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5629. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5630. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5631. }
  5632. } // if ($one_file->get_userid() == $USER->id)
  5633. if (!in_array($filetype, $extensions_allow)) {
  5634. $link_edit = "";
  5635. $link_add_ilm_iassign = "";
  5636. $link_add_ilm_tinymce = "";
  5637. $link_add_ilm_atto = "";
  5638. $link_filter = "";
  5639. }
  5640. if ($one_file->is_directory()) {
  5641. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5642. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5643. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5644. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5645. <td><center>$author</center></td>
  5646. <td><center>$timecreated</center></td>
  5647. <td><center>$timemodified</center></td></tr>\n";
  5648. }
  5649. else if ($this->from == 'iassign') {
  5650. $new_id = "";
  5651. $new_class = "";
  5652. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5653. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5654. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5655. }
  5656. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5657. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5658. <td><center>$author</center></td>
  5659. <td><center>$timecreated</center></td>
  5660. <td><center>$timemodified</center></td></tr>\n";
  5661. }
  5662. else if ($this->from == 'block') {
  5663. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5664. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5665. <td><center>$author</center></td>
  5666. <td><center>$timecreated</center></td>
  5667. <td><center>$timemodified</center></td></tr>\n";
  5668. }
  5669. else if ($this->from == 'tinymce') {
  5670. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5671. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5672. <td><center>$author</center></td>
  5673. <td><center>$timecreated</center></td>
  5674. <td><center>$timemodified</center></td></tr>\n";
  5675. }
  5676. else if ($this->from == 'atto') {
  5677. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5678. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5679. <td><center>$author</center></td>
  5680. <td><center>$timecreated</center></td>
  5681. <td><center>$timemodified</center></td></tr>\n";
  5682. }
  5683. } // foreach ($array_iassign_ilm as $iassign_ilm)
  5684. } // if (in_array(strtolower($filetype), $extensions) || $one_file->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto')
  5685. } // for ($ii=$count_all_files-1; $ii>0; $ii--) // for ($ii=0; $ii<$num_contexts; $ii++)
  5686. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5687. $dir_base = "";
  5688. $header = "";
  5689. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5690. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5691. foreach ($basename as $value) {
  5692. $dir_base .= $value . "/";
  5693. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5694. if ($dir_id) {
  5695. if ($value == "") {
  5696. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5697. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5698. } else {
  5699. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5700. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5701. }
  5702. }
  5703. } // foreach ($basename as $value)
  5704. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5705. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5706. $html .= "
  5707. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5708. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5709. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5710. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5711. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5712. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5713. </table>\n";
  5714. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5715. $html .= "<table width='100%'><tr>\n";
  5716. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5717. if ($count_files != 0) {
  5718. $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";
  5719. $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";
  5720. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5721. }
  5722. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5723. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5724. $html .= "</form>\n";
  5725. print $code_javascript_ilm;
  5726. print $html;
  5727. } // function view_files_ilm($extension)
  5728. } // class ilm_manager
  5729. /// Class to insert of icons
  5730. class iassign_icons {
  5731. static function insert ($icon) {
  5732. global $CFG;
  5733. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5734. return $string;
  5735. }
  5736. }
  5737. /// Class with util functions for plugin manage
  5738. class iassign_utils {
  5739. /// Function to return the filename extension
  5740. // @param string The $filename as an string
  5741. // @return string Return an string (last group after '.')
  5742. static function filename_extension ($filename) {
  5743. if ($filename == null || $filename == '') {
  5744. return null;
  5745. }
  5746. $itens = explode('.', $filename);
  5747. $num = count($itens);
  5748. if ($num < 2) {
  5749. return null;
  5750. }
  5751. return $itens[$num - 1];
  5752. }
  5753. /// Use the PHP class/package ZipArchive to create a Zip file
  5754. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5755. // 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
  5756. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5757. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5758. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5759. $zip = new zip_archive(); //2
  5760. $res = $zip->open($full_path_zip_filename);
  5761. $total_vet = count($vet_student_filename);
  5762. for ($ii=0; $ii<$total_vet; $ii++) {
  5763. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5764. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5765. }
  5766. $ret = $zip->close();
  5767. iassign_utils::download_file($full_path_zip_filename);
  5768. $filenameZip = $zip->filename;
  5769. return array($ret, $zip);
  5770. }
  5771. static function download_file ($zip_filename) {
  5772. header("Pragma: public");
  5773. header("Expires: 0");
  5774. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5775. header("Cache-Control: private", false);
  5776. header("Content-Type: application/zip");
  5777. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5778. header("Content-Transfer-Encoding: binary");
  5779. header("Content-Length: " . @filesize($zip_filename));
  5780. set_time_limit(0);
  5781. @readfile("$zip_filename") || die("File not found.");
  5782. unlink($zip_filename);
  5783. }
  5784. /// Function for format filename remove special caracters
  5785. // @param string $text String for clean
  5786. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5787. // @return string Return an string in clean format
  5788. static function format_filename ($text) {
  5789. if ($text != '.') {
  5790. //D $text = htmlspecialchars(urldecode($text));
  5791. //D echo "locallib.php: format_filename: $text<br/>";
  5792. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5793. $text = json_decode($text)->{current_language()};
  5794. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5795. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  5796. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  5797. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  5798. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  5799. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  5800. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  5801. // E.g. text = "exerc_midpoint.course.geo"
  5802. // 0123456789012345678901234
  5803. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5804. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5805. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5806. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5807. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5808. //$ext = strrpos($text, ".");
  5809. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5810. //$text = str_replace($array1, $array2, $text);
  5811. }
  5812. return $text;
  5813. }
  5814. /// Function to filter characters to the file name to iLM content
  5815. // @param string $text String for clean
  5816. // @param string $ext String ot the extension of the iLM
  5817. // @return string Return an string in clean format
  5818. static function filter_filename_extension ($filename, $ext) {
  5819. if ($filename != '.') {
  5820. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  5821. $arrTo = array("_","","","","","","","","","","","","");
  5822. $filename = str_replace($arrFrom, $arrTo, $filename);
  5823. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  5824. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  5825. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  5826. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  5827. $index_lastposition = strlen($filenameF);
  5828. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  5829. $text = str_replace(".", "_", $text); // erase all other "."
  5830. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  5831. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  5832. }
  5833. else
  5834. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  5835. return $filenameF;
  5836. }
  5837. /// Function for format pathname remove special caracters
  5838. // @param string $text String for clean
  5839. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5840. // @return string Return an string in clean format
  5841. static function format_pathname ($text, $is_lowercase = true) {
  5842. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5843. $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", "-", "_", "", "", "");
  5844. $text = str_replace($array1, $array2, $text);
  5845. if ($is_lowercase)
  5846. $text = strtolower($text);
  5847. return $text;
  5848. }
  5849. /// Function for format file name from iLM original name
  5850. // @param string $text String to build the file neam
  5851. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5852. // @return string Return an string in clean format
  5853. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  5854. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5855. $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", "-", "_", "", "", "");
  5856. $index_firstposition_blank = strpos($ilm_name, " ");
  5857. if ($index_firstposition_blank) { // truncate the name!
  5858. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  5859. }
  5860. $index_firstposition_dots = strpos($ilm_name, ":");
  5861. if ($index_firstposition_dots) { // truncate the name!
  5862. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  5863. }
  5864. $namefiltered = str_replace($array1, $array2, $ilm_name);
  5865. if ($is_lowercase)
  5866. $namefiltered = strtolower($namefiltered);
  5867. return $namefiltered;
  5868. }
  5869. /// Function for insert version in the filename
  5870. // @param string $filename Name of file
  5871. // @return string Return the filename with version
  5872. static function version_filename ($filename) {
  5873. $array_filename = explode('.', $filename);
  5874. if (count($array_filename) > 1)
  5875. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5876. else
  5877. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5878. return $filename;
  5879. }
  5880. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5881. static function remove_code_message ($string) {
  5882. $array = explode("&lt;ia_uc&gt;", $string);
  5883. return $array[0];
  5884. }
  5885. }
  5886. // class iassign_utils
  5887. /// Class with language functions for plugin manage
  5888. class iassign_language {
  5889. /// Function for return text in language or get default language (en)
  5890. // @param string $lang Code of language
  5891. // @param string $description JSON text content all languages
  5892. // @return string Return an string in the language selected
  5893. static function get_description_lang ($lang, $descriptions) {
  5894. $description_lang = "";
  5895. $description = json_decode($descriptions);
  5896. if ($description == null) {
  5897. $description_lang = $descriptions;
  5898. }
  5899. else {
  5900. if (isset($description->{$lang}))
  5901. $description_lang = $description->{$lang};
  5902. else
  5903. if (isset($description->en)) //MOOC2014
  5904. $description_lang = $description->en;
  5905. else //MOOC2014
  5906. $description_lang = "en"; //MOOC2014
  5907. }
  5908. return $description_lang;
  5909. }
  5910. /// Function for return all language supported by iLM
  5911. // @param string $descriptions JSON text content all languages
  5912. // @return string Return as string with all languages
  5913. static function get_all_lang ($descriptions) {
  5914. $langs = "";
  5915. $description = json_decode($descriptions);
  5916. if ($description) {
  5917. foreach ($description as $key => $value) {
  5918. $langs .= $key . " ; ";
  5919. }
  5920. $langs = substr($langs, 0, strlen($langs) - 3);
  5921. }
  5922. return $langs;
  5923. }
  5924. /// Function for convert json in xml //MOOC2014
  5925. // @param string $json JSON text
  5926. // @return string Return as string with xml tags
  5927. static function json_to_xml ($json) {
  5928. $xml = "";
  5929. $json = json_decode($json);
  5930. foreach ($json as $key => $value) {
  5931. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5932. }
  5933. return $xml;
  5934. }
  5935. }
  5936. // class iassign_language
  5937. /// Class with log functions for plugin manage.
  5938. class iassign_log {
  5939. /// Function for insert log event
  5940. // @param string $action Code action of event
  5941. // @param string $information Text for describe action of event
  5942. // @param int $cmid Id of context module
  5943. // @param int $ilmid Id of iLM
  5944. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  5945. global $COURSE, $CFG, $USER, $DB;
  5946. $newentry = new stdClass();
  5947. $newentry->time = time();
  5948. $newentry->userid = $USER->id;
  5949. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  5950. $newentry->course = $COURSE->id;
  5951. $newentry->cmid = $cmid;
  5952. $newentry->ilmid = $ilmid;
  5953. $newentry->action = $action;
  5954. $newentry->info = $information;
  5955. $newentry->language = current_language();
  5956. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  5957. if (ini_get("browscap") && function_exists('get_browse')) {
  5958. $browser = get_browse(null, true);
  5959. $newentry->javascript = $browser['javascript'];
  5960. $newentry->java = $browser['javaapplets'];
  5961. }
  5962. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  5963. print_error('error_add_log', 'iassign');
  5964. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  5965. } // class iassign_log