locallib.php 321 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.2 2019/03/13
  7. * + Several fixes to allow iLM under HTML stack
  8. *
  9. * - v 4.9.1 2017/11/02
  10. * + 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")
  11. * + 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)'
  12. *
  13. * - v 4.9 2017/03/13
  14. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  15. *
  16. * - v 4.8 2016/05/12
  17. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  18. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  19. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  20. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  21. * replaced by
  22. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  23. * - v 4.7 2016/02/17
  24. * + 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(...)')
  25. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  26. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  27. * + 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)
  28. * + 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'
  29. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  30. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  31. *
  32. * --------------- (code bellow was used at our MOOC 2014)
  33. * - v 4.6 2014/02/25
  34. * + Fix bugs in filter function for open applets.
  35. * - v 4.5 2014/02/24
  36. * + Fix bugs in params.
  37. * + Insert new param type.
  38. * - v 4.4 2014/01/24
  39. * + Allow select type of params.
  40. * + Insert the use of applet params specific for activities.
  41. * - v 4.3 2014/01/23
  42. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  43. * - v 4.2 2016/02/13
  44. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  45. * --------------- (above code used at our MOOC 2014)
  46. *
  47. * - v 4.1 2013/12/13
  48. * + Insert log in iAssign actions.
  49. * + 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).
  50. * + Insert class for Log actions in system.
  51. * - v 4.0 2013/10/31
  52. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  53. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  54. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  55. * - v 3.9 2013/10/25
  56. * + Insert support of upgrade iLM.
  57. * + Insert support for more than one extension in iLM.
  58. * + Fix bugs in verion control.
  59. * - v 3.8 2013/09/19
  60. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  61. * - v 3.7 2013/09/12
  62. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  63. * + 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).
  64. * - v 3.6 2013/09/05
  65. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  66. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  67. * + Change tag APPLET in function ilm_settings::view_ilm.
  68. * - v 3.5 2013/08/26
  69. * + Fix bug in download package iassign without answers (iassign::report).
  70. * - v 3.4 2013/08/23
  71. * + Fix bug in export package iassign.
  72. * - v 3.3 2013/08/22
  73. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  74. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  75. * - v 3.2 2013/08/21
  76. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  77. * + Change functions for import files for ilm_manager.php.
  78. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  79. * - v 3.1 2013/08/15
  80. * + Change return file selected (ilm_manager::add_ilm).
  81. * + 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).
  82. * - v 3.0 2013/08/02
  83. * + 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).
  84. * - v 2.9 2013/08/01
  85. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  86. * - v 2.8 2013/07/25
  87. * + Insert the activity name in header of view (activity::view_dates).
  88. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  89. * - v 2.7 2013/07/24
  90. * + Create link previous and next for student view in one activity (activity::view_dates).
  91. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  92. * - v 2.6 2013/07/23
  93. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  94. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  95. * - v 2.5 2013/07/12
  96. * + 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).
  97. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  98. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  99. *
  100. * @author Patricia Alves Rodrigues
  101. * @author Leônidas O. Brandão
  102. * @contributor Igor Moreira Félix (2018-)
  103. * @contributor Márcio de Lima Passos (2014)
  104. * @version v 4.9.2 2019/03/13
  105. * @version v 4.8 2016/05/12
  106. * @package mod_iassign_lib
  107. * @since 2010/09/27
  108. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  109. *
  110. * <b>License</b>
  111. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  112. */
  113. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  114. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  115. //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"'
  116. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  117. /**
  118. * Standard base class for all iAssign
  119. */
  120. class iassign {
  121. var $cm;
  122. var $course;
  123. var $iassign;
  124. var $striassign;
  125. var $striassigns;
  126. var $context;
  127. var $activity;
  128. var $iassign_up;
  129. var $iassign_down;
  130. var $action;
  131. var $iassign_submission_current;
  132. var $userid_iassign;
  133. var $bottonPost;
  134. var $write_solution;
  135. var $view_iassign;
  136. // 3.1 update PHP 7.0 compatibility for all moodle versions
  137. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  138. /// Constructor for the base iassign class
  139. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  140. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  141. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  142. function __construct ($iassign, $cm, $course) {
  143. global $COURSE, $CFG, $USER, $DB;
  144. $botton = optional_param('botton', NULL, PARAM_TEXT);
  145. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  146. if (!is_null($botton))
  147. $USER->iassignEdit = $botton;
  148. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  149. // 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'
  150. $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"
  151. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  152. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  153. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  154. $this->action = optional_param('action', NULL, PARAM_TEXT);
  155. $this->cm = $cm;
  156. $this->context = context_module::instance($this->cm->id);
  157. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  158. $this->userid_iassign = $USER->id;
  159. if ($course) {
  160. $this->course = $course;
  161. }
  162. else if ($this->cm->course == $COURSE->id) {
  163. $this->course = $COURSE;
  164. }
  165. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  166. print_error('invalidid', 'iassign');
  167. }
  168. $this->coursecontext = context_course::instance($this->course->id);
  169. if ($iassign) {
  170. $this->iassign = $iassign;
  171. }
  172. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  173. print_error('invalidid', 'iassign');
  174. }
  175. $USER->context = context_module::instance($this->cm->id);
  176. $USER->cm = $this->cm->id;
  177. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  178. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  179. $this->context = context_module::instance($this->cm->id);
  180. $this->striassign = get_string('modulename', 'iassign');
  181. $this->striassigns = get_string('modulenameplural', 'iassign');
  182. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  183. $this->bottonPost = 0;
  184. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  185. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  186. $this->view();
  187. } // function __construct($iassign, $cm, $course)
  188. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  189. // This method provides the page to view each iLM with any interactive activity
  190. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  191. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  192. global $USER, $DB, $OUTPUT;
  193. // $iassign_statementid = $this->iassign->iassign_statementid;
  194. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  195. $iassign_statementid = $this->activity->get_activity()->id;
  196. else
  197. $iassign_statementid = "";
  198. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  199. // If this user has no capability to View 'iassign': stop here
  200. require_capability('mod/iassign:view', $this->context);
  201. // Trigger module view event
  202. $event = \mod_iassign\event\course_module_viewed::create(array(
  203. 'objectid' => $this->iassign->id,
  204. 'context' => $this->context
  205. ));
  206. $event->add_record_snapshot('course', $this->course);
  207. $event->trigger();
  208. if ($this->action) { // when student do/redo activity or teacher see student solution
  209. $this->action(); // calls '$this->view_iLM();'
  210. }
  211. else {
  212. print $OUTPUT->header();
  213. $this->view_iassigns(); // show the iLM with the content
  214. print $OUTPUT->footer();
  215. }
  216. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  217. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  218. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  219. //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" }
  220. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  221. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  222. //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" }
  223. //D else echo "Apagou!<br/>";
  224. die();
  225. } // function view()
  226. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  227. function action () {
  228. global $USER;
  229. // action:
  230. // up - move up activity (mover atividade para cima)
  231. // down - move down activity (mover atividade para baixo)
  232. // visible - view/hide activity (exibir/ocultar atividade)
  233. // delete - delete activity (excluir atividade)
  234. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  235. // deleteno - does not erase activity (não apaga atividade)
  236. // add - add activity (adicionar atividade)
  237. // edit - edit activity (modificar atividade)
  238. $action_iassign = array(
  239. 'newcomment' => '$this->get_answer();',
  240. 'view' => '$this->view_iassign_current();',
  241. 'get_answer' => '$this->get_answer();',
  242. 'repeat' => '$this->view_iassign_current();',
  243. 'overwrite' => '$this->get_answer();',
  244. 'stats_student' => '$this->stats_students();',
  245. 'download_answer' => '$this->export_file_answer();',
  246. 'download_all_answer' => '$this->export_package_answer();');
  247. $action_iassign_limit = array(
  248. 'view' => '$this->view_iassign_current();',
  249. 'newcomment' => '$this->get_answer();',
  250. 'viewsubmission' => '$this->view_iassign_current();',
  251. 'edit_status' => '$this->edit_status();',
  252. 'edit_grade' => '$this->edit_grade();',
  253. 'export_csv' => '$this->export_csv();',
  254. 'report' => '$this->report();',
  255. 'print' => '$this->report();',
  256. 'stats' => '$this->stats();',
  257. 'printstats' => '$this->stats();');
  258. $restricted = array('up' => '$this->activity->move_iassign($this->iassign_up,$this->return);',
  259. 'down' => '$this->activity->move_iassign($this->iassign_down,$this->return);',
  260. 'visible' => '$this->activity->visible_iassign($this->return);',
  261. 'delete' => '$this->activity->delete($this->return);',
  262. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  263. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  264. 'add' => '$this->add_edit_iassign();',
  265. 'edit' => '$this->add_edit_iassign();',
  266. 'get_answer' => '$this->get_answer();',
  267. 'duplicate_activity' => '$this->duplicate_activity();',
  268. 'move_activity' => '$this->move_activity();');
  269. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  270. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  271. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  272. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  273. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  274. }
  275. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  276. eval($action_iassign_limit[$this->action]);
  277. }
  278. else {
  279. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  280. // Arive here with: "get_answer"; "view"
  281. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  282. }
  283. } // function action()
  284. /// This method moves an iAssign activity
  285. function move_activity () {
  286. global $USER, $CFG, $DB, $COURSE;
  287. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  288. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  289. $update_entry_new_iassign = new stdClass();
  290. $update_entry_new_iassign->id = $iassign_id;
  291. $update_entry_new_iassign->iassignid = $iassign_destiny;
  292. // Update the iassign_statement
  293. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  294. // Update file context
  295. $c_i = context_module::instance($this->cm->id);
  296. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  297. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  298. $path_module = context_course::instance($COURSE->id);
  299. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  300. if ($context_file) {
  301. $id_context = $context_file->id;
  302. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  303. $fs = get_file_storage();
  304. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  305. foreach ($files as $value) {
  306. if ($value->get_filename() != ".") {
  307. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  308. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  309. $updateentry = new stdClass();
  310. $updateentry->id = $iassign_id;
  311. $updateentry->file = $newfile->get_itemid();
  312. $DB->update_record("iassign_statement", $updateentry);
  313. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  314. break;
  315. }
  316. }
  317. }
  318. $this->return_home_course('moved_activity');
  319. exit;
  320. }
  321. /// This method duplicates an iAssign activity
  322. function duplicate_activity () {
  323. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  324. $id = $this->cm->id;
  325. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  326. $context = context_module::instance($this->cm->id);
  327. $contextuser = context_user::instance($USER->id);
  328. // Get the the iAssign acitivity to be duplicated
  329. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  330. // Remove the current id of activity
  331. $iassign_statement->id=0;
  332. // Get the information about current author, and add this information in author_modified field
  333. $author = $DB->get_record("user", array('id' => $USER->id));
  334. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  335. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  336. // Store the activity in the table
  337. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  338. // Duplicate activity file
  339. $fs = get_file_storage();
  340. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  341. foreach ($files as $value) {
  342. if ($value->get_filename() != ".") {
  343. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  344. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  345. $updateentry = new stdClass();
  346. $updateentry->id = $id_;
  347. $updateentry->file = $newfile->get_itemid();
  348. // Update the duplicated iLM iAssign with new file id
  349. $DB->update_record("iassign_statement", $updateentry);
  350. }
  351. }
  352. }
  353. // log event --------------------------------------------------------------------------------------
  354. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  355. $this->return_home_course('duplicated_activity');
  356. exit;
  357. }
  358. /// This method gets the content from the iLM and register it
  359. // It could be the exercise model (teacher) or an answer (student)
  360. function get_answer () {
  361. global $USER, $CFG, $DB, $OUTPUT;
  362. $id = $this->cm->id;
  363. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  364. $comment = false;
  365. if ($submission_comment)
  366. $comment = $this->write_comment_submission();
  367. // receives data of iLM using the current activity
  368. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  369. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  370. // receives data of submission of current activity
  371. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  372. // receives post and get
  373. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  374. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  375. $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)
  376. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  377. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  378. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  379. $msg = '';
  380. // Feedback
  381. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  382. $str_action = "view"; // repeat
  383. if (strtolower($iassign_ilm->name) == "igeom") {
  384. }
  385. $title = get_string('evaluate_iassign', 'iassign');
  386. print $OUTPUT->header();
  387. print $OUTPUT->box_start();
  388. // Action = { view ; repeat ; viewsubmission }
  389. // * '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")
  390. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  391. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  392. $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;
  393. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  394. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  395. print '<table width=100% >';
  396. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  397. //TODO alterar aqui???
  398. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  399. // empty_answer_post = No solution was posted.
  400. if ($comment)
  401. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  402. else
  403. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  404. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  405. } else {
  406. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  407. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  408. // Correct answer!!
  409. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  410. $this->write_solution = 1; //
  411. $status = 3;
  412. $grade_student = $this->activity->get_activity()->grade; // evaluated as correct solution submitted is assigned the note pattern of activity
  413. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  414. // log record
  415. $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;
  416. // Trigger module viewed event.
  417. $event = \mod_iassign\event\submission_created::create(array(
  418. 'objectid' => $this->iassign->id,
  419. 'context' => $this->context,
  420. 'other' => $info
  421. ));
  422. $event->add_record_snapshot('course', $this->course);
  423. $event->trigger();
  424. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  425. // Wrong answer...: get_answer_incorrect
  426. $status = 2;
  427. $grade_student = 0; // evaluated as incorrect solution
  428. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  429. // log record
  430. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  431. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  432. // Trigger module viewed event.
  433. $event = \mod_iassign\event\submission_created::create(array(
  434. 'objectid' => $this->iassign->id,
  435. 'context' => $this->context,
  436. 'other' => $info
  437. ));
  438. $event->add_record_snapshot('course', $this->course);
  439. $event->trigger();
  440. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  441. // Presents to the learner the result of the automatic evaluate?
  442. if ($this->activity->get_activity()->show_answer == 0) { // no...
  443. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  444. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  445. print '<tr>';
  446. // log record
  447. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  448. // Trigger module viewed event.
  449. $event = \mod_iassign\event\submission_created::create(array(
  450. 'objectid' => $this->iassign->id,
  451. 'context' => $this->context,
  452. 'other' => $info
  453. ));
  454. $event->add_record_snapshot('course', $this->course);
  455. $event->trigger();
  456. } else { // yes!!!
  457. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  458. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  459. print '<tr>';
  460. print $msg;
  461. }
  462. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  463. $status = 1;
  464. $grade_student = 0; // iLM not have automatic evaluator
  465. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  466. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  467. print '<tr>';
  468. // log record
  469. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  470. $event = \mod_iassign\event\submission_created::create(array(
  471. 'objectid' => $this->iassign->id,
  472. 'context' => $this->context,
  473. 'other' => $info
  474. ));
  475. $event->add_record_snapshot('course', $this->course);
  476. $event->trigger();
  477. } // if ($iassign_ilm->evaluate == 1)
  478. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  479. print '</tr></table>';
  480. print $OUTPUT->box_end();
  481. // add or update evaluate
  482. if ($this->write_solution == 1) {
  483. $timenow = time();
  484. // new record
  485. if (!$iassign_submission) {
  486. $newentry = new stdClass();
  487. $newentry->userid = $this->userid_iassign;
  488. // $newentry->userid = $USER->id;
  489. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  490. $newentry->timecreated = $timenow;
  491. $newentry->timemodified = $timenow;
  492. $newentry->answer = $iLM_PARAM_ArchiveContent;
  493. $newentry->grade = $grade_student;
  494. $newentry->status = $status;
  495. $newentry->experiment = 1;
  496. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  497. print_error('error_insert', 'iassign');
  498. } else {
  499. // Trigger module viewed event.
  500. $event = \mod_iassign\event\submission_created::create(array(
  501. 'objectid' => $this->iassign->id,
  502. 'context' => $this->context
  503. ));
  504. $event->add_record_snapshot('course', $this->course);
  505. $event->trigger();
  506. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  507. }
  508. } elseif ($iassign_submission->status != 3) {
  509. $newentry = new stdClass();
  510. $newentry->id = $iassign_submission->id;
  511. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  512. $newentry->userid = $iassign_submission->userid;
  513. $newentry->timecreated = $iassign_submission->timecreated;
  514. $newentry->timemodified = $timenow;
  515. $newentry->answer = $iLM_PARAM_ArchiveContent;
  516. $newentry->grade = $grade_student;
  517. $newentry->status = $status;
  518. $newentry->experiment = $iassign_submission->experiment + 1;
  519. if (!$DB->update_record("iassign_submission", $newentry)) {
  520. print_error('error_update', 'iassign');
  521. //D depurar...
  522. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  523. //D $fp = fopen("teste1.txt","w");
  524. //D fwrite($fp,$stringAux);
  525. } else {
  526. // Trigger module viewed event.
  527. $event = \mod_iassign\event\submission_updated::create(array(
  528. 'objectid' => $this->iassign->id,
  529. 'context' => $this->context
  530. ));
  531. $event->add_record_snapshot('course', $this->course);
  532. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  533. }
  534. } else {
  535. if ($return_get_answer == 1) {
  536. $newentry = new stdClass();
  537. $newentry->id = $iassign_submission->id;
  538. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  539. $newentry->userid = $iassign_submission->userid;
  540. $newentry->timecreated = $iassign_submission->timecreated;
  541. $newentry->timemodified = $timenow;
  542. $newentry->answer = $iLM_PARAM_ArchiveContent;
  543. $newentry->grade = $grade_student;
  544. $newentry->status = $status;
  545. $newentry->experiment = $iassign_submission->experiment + 1;
  546. if (!$DB->update_record("iassign_submission", $newentry))
  547. print_error('error_update', 'iassign');
  548. else {
  549. $event = \mod_iassign\event\submission_updated::create(array(
  550. 'objectid' => $this->iassign->id,
  551. 'context' => $this->context
  552. ));
  553. $event->add_record_snapshot('course', $this->course);
  554. $event->trigger();
  555. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  556. print $OUTPUT->box_start();
  557. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  558. print $OUTPUT->box_end();
  559. }
  560. } elseif ($return_get_answer == 2) {
  561. print $OUTPUT->box_start();
  562. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  563. print $OUTPUT->box_end();
  564. } else {
  565. print $OUTPUT->box_start();
  566. print "
  567. <script type='text/javascript'>
  568. //<![CDATA[
  569. function overwrite () {
  570. document.formEnvio.return_get_answer.value = 1;
  571. document.formEnvio.submit();
  572. }
  573. function nooverwrite () {
  574. document.formEnvio.return_get_answer.value = 2;
  575. document.formEnvio.submit();
  576. }
  577. //]]>
  578. </script>";
  579. $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;
  580. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  581. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  582. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  583. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  584. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  585. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  586. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  587. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  588. <input type='hidden' name='return_get_answer'/> ";
  589. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  590. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  591. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  592. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  593. print " </form>";
  594. print $OUTPUT->box_end();
  595. }
  596. }
  597. } // if ($this->write_solution == 1)
  598. print $OUTPUT->footer();
  599. die();
  600. } // function get_answer()
  601. /// Export in file the answer of student.
  602. function export_file_answer () {
  603. global $DB;
  604. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  605. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  606. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  607. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  608. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  609. $extensions = explode(",", $iassign_ilm->extension);
  610. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  611. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  612. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  613. header("Pragma: public");
  614. header("Expires: 0");
  615. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  616. header("Cache-Control: private", false);
  617. header("Content-Type: document/unknown");
  618. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  619. set_time_limit(0);
  620. print($iassign_submission->answer);
  621. exit;
  622. } // function export_file_answer()
  623. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  624. // @calledby $this->export_package_answer()
  625. //TODO_HTML
  626. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  627. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  628. <head>
  629. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  630. $str_html .= " </head>
  631. <body>\n";
  632. $tam = sizeof($array_iassign_name);
  633. for ($ii=0; $ii<$tam; $ii++) {
  634. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  635. }
  636. $str_html .= "
  637. </body>\n</html>";
  638. return $str_html;
  639. }
  640. /// Export an package (zip) with all answer of students
  641. // @calledby $this->action()
  642. function export_package_answer () {
  643. global $DB, $CFG, $OUTPUT;
  644. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  645. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  646. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  647. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  648. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  649. $userid = optional_param('userid', NULL, PARAM_INT);
  650. $iassign_user = $DB->get_record("user", array("id" => $userid));
  651. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  652. //TODO_HTML echo "username=$username<br/>"; exit;
  653. $current_date = date('Y_m_d_H');
  654. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  655. // If temporary directory under Moodle data does not exists => create it
  656. if (!is_dir($diretorio)) {
  657. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  658. // created directory with permissions to be seen by everyone
  659. }
  660. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  661. if (!is_writable($diretorio)) { // send a highlighted message!
  662. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  663. exit; // just in case
  664. }
  665. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  666. $zip = new zip_archive(); // create ZIP
  667. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  668. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  669. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  670. $vet_student_filename = array();
  671. $vet_student_content = array();
  672. foreach ($iassign_statements as $iassign_statement) {
  673. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  674. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  675. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  676. $extensions = explode(",", $iassign_ilm->extension);
  677. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  678. if ($iassign_submission) {
  679. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  680. $student_content = $iassign_submission->answer;
  681. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  682. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  683. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  684. if ($resp) {
  685. $vet_student_filename[] = $student_filename;
  686. $vet_student_content[] = $student_content;
  687. }
  688. else { // send a highlighted message!
  689. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  690. exit; // just in case
  691. }
  692. }
  693. }
  694. $zip->close(); // close the ZIP file
  695. if (count($vet_student_filename)>0) {
  696. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  697. $result_tf = $vet_result[0];
  698. $filenameZip = $vet_result[1]->filename;
  699. }
  700. iassign_utils::download_file($zip_filename); // download the ZIP file
  701. exit;
  702. } // function export_package_answer()
  703. /// Editing status of interactive activities
  704. function edit_status () {
  705. global $USER, $DB, $OUTPUT;
  706. $newentry = new stdClass();
  707. $newentry->id = $this->iassign_submission_current;
  708. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  709. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  710. if ($iassign_submission->status != 0 && $newentry->status == 0)
  711. $newentry->status = $iassign_submission->status;
  712. $newentry->teacher = $USER->id;
  713. if (!$DB->update_record('iassign_submission', $newentry))
  714. print_error('error_update', 'iassign');
  715. else {
  716. // Trigger module viewed event.
  717. $event = \mod_iassign\event\submission_updated::create(array(
  718. 'objectid' => $this->iassign->id,
  719. 'context' => $this->context
  720. ));
  721. $event->add_record_snapshot('course', $this->course);
  722. $event->trigger();
  723. $this->action = 'viewsubmission';
  724. $this->view_iassign_current();
  725. } // if (!$DB->update_record('iassign_submission', $newentry))
  726. } // function edit_status()
  727. /// Editing grade of interactive activities
  728. function edit_grade () {
  729. global $USER, $DB, $OUTPUT;
  730. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  731. if ($newgrade && $newgrade >= 0) {
  732. $newentry = new stdClass();
  733. $newentry->id = $this->iassign_submission_current;
  734. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  735. $newentry->teacher = $USER->id;
  736. if (!$DB->update_record('iassign_submission', $newentry))
  737. print_error('error_update', 'iassign');
  738. else {
  739. // Trigger module viewed event.
  740. $event = \mod_iassign\event\submission_updated::create(array(
  741. 'objectid' => $this->iassign->id,
  742. 'context' => $this->context
  743. ));
  744. $event->add_record_snapshot('course', $this->course);
  745. $event->trigger();
  746. }
  747. } // if ($newgrade >= 0)
  748. $this->action = 'viewsubmission';
  749. $this->view_iassign_current();
  750. }
  751. /// Add or Edit interactive activities
  752. function add_edit_iassign () {
  753. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  754. require_once('iassign_form.php');
  755. $id = $this->cm->id;
  756. $iassignid = $this->iassign->id;
  757. $param = new stdClass();
  758. $param->action = $this->action; // oculto
  759. $param->id = $id; // oculto
  760. $COURSE->cm = $id;
  761. $COURSE->iassignid = $iassignid;
  762. $COURSE->iassign_file_id = NULL;
  763. $context = context_module::instance($this->cm->id);
  764. $contextuser = context_user::instance($USER->id);
  765. $component = 'mod_iassign';
  766. $filearea = 'exercise';
  767. if (!empty($this->iassign_current))
  768. $COURSE->iassign_id = $this->iassign_current;
  769. else
  770. $COURSE->iassign_id = 0;
  771. $total_of_activities = 0; // get the total number of activities in this iAssign block
  772. if ($this->action == 'add') {
  773. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  774. $total_of_activities = count($iassign_data);
  775. $params = array('iassignid' => $iassignid);
  776. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  777. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  778. $param->iassignid = $iassignid;
  779. $param->name = "";
  780. $param->oldname = "";
  781. $param->type_iassign = 3;
  782. $param->proposition = "";
  783. $author = $DB->get_record("user", array("id" => $USER->id));
  784. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  785. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  786. $param->author = $param->author_name;
  787. $param->author_modified = $param->author_modified_name;
  788. $COURSE->iassign_list = array();
  789. $param->iassign_list = array();
  790. if ($iassign_statement) {
  791. foreach ($iassign_statement as $iassign) {
  792. $param->iassign_list[$iassign->id] = 0;
  793. $COURSE->iassign_list[$iassign->id] = new stdClass();
  794. $COURSE->iassign_list[$iassign->id]->id = $iassign->id;
  795. $COURSE->iassign_list[$iassign->id]->name = $iassign->name;
  796. $COURSE->iassign_list[$iassign->id]->enable = 1;
  797. } // foreach ($iassign_statement as $iassign)
  798. }
  799. $param->iassign_ilmid = 0;
  800. //echo "locallib.php: add_edit_iassign(): add<br/>";
  801. $param->file = 0;
  802. $param->fileold = 0;
  803. $param->filename = "";
  804. $param->grade = $iassign_data->grade;
  805. $param->timemodified = time();
  806. $param->timecreated = time();
  807. $param->timeavailable = $iassign_data->timeavailable;
  808. $param->timedue = $iassign_data->timedue;
  809. $param->preventlate = $iassign_data->preventlate;
  810. $param->test = $iassign_data->test;
  811. $param->special_param1 = 0;
  812. $param->visible = 1;
  813. $param->max_experiment = $iassign_data->max_experiment;
  814. $param->dependency = 0;
  815. $param->automatic_evaluate = 1;
  816. $param->show_answer = 1;
  817. } // if ($this->action == 'add')
  818. elseif ($this->action == 'edit') {
  819. $COURSE->iassign_list = array();
  820. $this_activity = $this->activity->get_activity();
  821. if ($this_activity != null) {
  822. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  823. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  824. $param->iassign_id = $iassign_statement_current->id; // oculto
  825. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  826. $param->name = $iassign_statement_current->name;
  827. $param->oldname = $iassign_statement_current->name;
  828. $param->type_iassign = $iassign_statement_current->type_iassign;
  829. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  830. //2019 $param->proposition = $iassign_statement_current->proposition;
  831. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  832. $param->author_name = $iassign_statement_current->author_name; // oculto
  833. $param->author = $iassign_statement_current->author_name;
  834. $author = $DB->get_record("user", array('id' => $USER->id));
  835. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  836. $param->author_modified = $param->author_modified_name;
  837. $dependency = explode(';', $iassign_statement_current->dependency);
  838. $param->iassign_list = array();
  839. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  840. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  841. $array_dependency = array();
  842. $subdependency = "";
  843. $sub_subdependency = "";
  844. // dependent on this exercise
  845. if ($iassign_statement_dependency) {
  846. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  847. // to whom this exercise depends
  848. foreach ($inter as $tmp)
  849. $sub_subdependency .= $this->search_sub_dependency($tmp);
  850. $list_dependency = $subdependency . $sub_subdependency;
  851. $array_dependency = explode(";", $list_dependency);
  852. }
  853. // Get all activity with the same iLM - iassignid
  854. $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";
  855. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  856. $total_of_activities = count($all_others_iassign_statement) + 1;
  857. $inter = array();
  858. if ($all_others_iassign_statement)
  859. foreach ($all_others_iassign_statement as $iassign)
  860. if (in_array($iassign->id, $dependency))
  861. $inter[] = $iassign->id;
  862. if ($all_others_iassign_statement) {
  863. foreach ($all_others_iassign_statement as $iassign) {
  864. $COURSE->iassign_list[$iassign->id] = new stdClass();
  865. $COURSE->iassign_list[$iassign->id]->name = $iassign->name;
  866. $COURSE->iassign_list[$iassign->id]->id = $iassign->id;
  867. if (in_array($iassign->id, $dependency))
  868. $param->iassign_list[$iassign->id] = 1;
  869. else
  870. $param->iassign_list[$iassign->id] = 0;
  871. if (in_array($iassign->id, $array_dependency))
  872. $COURSE->iassign_list[$iassign->id]->enable = 0;
  873. else
  874. $COURSE->iassign_list[$iassign->id]->enable = 1;
  875. } // foreach ($all_others_iassign_statement as $iassign)
  876. }
  877. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  878. $param->fileold = 0;
  879. $param->file = 0;
  880. $param->filename = '';
  881. $param->grade = $iassign_statement_current->grade;
  882. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  883. $param->timeavailable = $iassign_statement_current->timeavailable;
  884. $param->timedue = $iassign_statement_current->timedue;
  885. $param->preventlate = $iassign_statement_current->preventlate;
  886. $param->test = $iassign_statement_current->test;
  887. $param->special_param1 = $iassign_statement_current->special_param1;
  888. $param->position = $iassign_statement_current->position; // oculto
  889. $param->visible = $iassign_statement_current->visible;
  890. $param->max_experiment = $iassign_statement_current->max_experiment;
  891. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  892. $param->show_answer = $iassign_statement_current->show_answer;
  893. $fs = get_file_storage();
  894. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  895. if ($files) {
  896. foreach ($files as $file) {
  897. if ($file->get_filename() != '.') {
  898. $param->filename = $file->get_filename();
  899. $param->file = $file->get_id();
  900. $param->fileold = $file->get_id();
  901. $COURSE->iassign_file_id = $file->get_id();
  902. }
  903. }
  904. }
  905. //TODO //MOOC2014 -- inicio
  906. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  907. //D if ($iassign_ilm_configs) {
  908. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  909. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  910. //D } //MOOC2014 -- fim
  911. } // if ($this_activity != null)
  912. } // elseif ($this->action == 'edit')
  913. // Get all iActivity in the iAssign block with id = $this->iassign->id
  914. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  915. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  916. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  917. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  918. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  919. $param->position = $total_of_activities;
  920. $mform = new mod_iassign_form();
  921. $mform->set_data($param);
  922. if ($mform->is_cancelled()) {
  923. $this->return_home_course('iassign_cancel');
  924. exit;
  925. }
  926. else { // if ($mform->is_cancelled())
  927. $result = $mform->get_data();
  928. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  929. if ($result) {
  930. $result->context = $context;
  931. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  932. $result->grade = 0;
  933. if ($result->type_iassign == 1) {
  934. $result->automatic_evaluate = 0;
  935. $result->show_answer = 0;
  936. }
  937. elseif ($result->automatic_evaluate == 0)
  938. $result->show_answer = 0;
  939. // $_POST['iassign_list']
  940. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  941. if ($result->iassign_list) {
  942. foreach ($result->iassign_list as $key => $value)
  943. $result->dependency .= $key . ';';
  944. }
  945. else
  946. $result->dependency = 0;
  947. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  948. //TODO Then get it directly from the form data $_POST!
  949. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  950. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  951. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  952. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  953. if ($this->action == 'add') {
  954. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  955. if ($iassign_statement_name) {
  956. $this->return_home_course('error_iassign_name');
  957. die();
  958. }
  959. // Really insert the new iActivity in table '*_iassign_statement'
  960. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  961. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  962. // Trigger module viewed event.
  963. $event = \mod_iassign\event\iassign_created::create(array(
  964. 'objectid' => $iassignid,
  965. 'context' => $context
  966. ));
  967. $event->add_record_snapshot('course', $this->course);
  968. $event->trigger();
  969. $this->return_home_course('iassign_add');
  970. } // if ($this->action == 'add')
  971. elseif ($this->action == 'edit') {
  972. $iassignid = $this->activity->update_iassign($result);
  973. $this->activity->update_calendar($iassignid, $result->oldname);
  974. // Trigger module viewed event.
  975. $event = \mod_iassign\event\iassign_updated::create(array(
  976. 'objectid' => $iassignid,
  977. 'context' => $context
  978. ));
  979. $event->add_record_snapshot('course', $this->course);
  980. $event->trigger();
  981. $this->return_home_course('iassign_update');
  982. } // elseif ($this->action == 'edit')
  983. die();
  984. } // if ($result)
  985. } // else if ($mform->is_cancelled())
  986. print $OUTPUT->header();
  987. $mform->display();
  988. print $OUTPUT->footer();
  989. die();
  990. } // function add_edit_iassign()
  991. /// Search for dependencies
  992. function search_dependency ($search_iassing_id, $iassign_statement) {
  993. global $DB, $OUTPUT;
  994. $dependency = "";
  995. if ($iassign_statement)
  996. foreach ($iassign_statement as $iassign) {
  997. $inter_dependency = explode(';', $iassign->dependency);
  998. if (in_array($search_iassing_id, $inter_dependency)) {
  999. $dependency .= $iassign->id . ";";
  1000. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1001. } // if (in_array($search_iassing_id, $inter_dependency))
  1002. } // foreach ($iassign_statement as $iassign)
  1003. return $dependency;
  1004. }
  1005. /// Search for "sub"dependency
  1006. function search_sub_dependency ($search_iassing_id) {
  1007. global $DB, $OUTPUT;
  1008. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1009. $dependency = "";
  1010. if ($iassign_statement) {
  1011. $inter_dependency = explode(';', $iassign_statement->dependency);
  1012. foreach ($inter_dependency as $tmp) {
  1013. if ($tmp != 0)
  1014. $dependency .= $tmp . ";";
  1015. $dependency .= $this->search_sub_dependency($tmp);
  1016. } // foreach ($inter_dependency as $tmp)
  1017. } // if ($iassign_statement)
  1018. return $dependency;
  1019. }
  1020. // Warning message
  1021. static function warning_message_iassign ($strcode) {
  1022. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1023. }
  1024. /// Update grade of iAssign
  1025. // Called always any iAssign activity is created
  1026. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1027. static function update_grade_iassign ($iassignid) {
  1028. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1029. require_once($CFG->libdir . '/gradelib.php');
  1030. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1031. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1032. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1033. // Each iAssign item is associated with one item on the "gradebook"
  1034. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1035. //$sum_grade = 0;
  1036. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1037. //foreach($grade as $tmp) {
  1038. // $sum_grade += $tmp->grade;
  1039. // }
  1040. //1 Solution 1
  1041. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1042. //1 $sum_grade = 0; //1
  1043. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1044. //2 Solution 2
  1045. $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
  1046. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1047. if (key($array_sum_grade))
  1048. $sum_grade = key($array_sum_grade); //2
  1049. else
  1050. $sum_grade = 0; //2
  1051. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1052. $grades = NULL;
  1053. $params = array('itemname' => $grade_iassign->name);
  1054. $params['iteminstance'] = $iassignid;
  1055. $params['gradetype'] = GRADE_TYPE_VALUE;
  1056. //2016 if ($sum_grade != 0) {
  1057. $params['grademax'] = $sum_grade;
  1058. $params['rawgrademax'] = $sum_grade;
  1059. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1060. $params['grademin'] = 0;
  1061. // @calls /lib/gradelib.php: call to grade_item->insert()
  1062. //TODO: is there any error here in Moodle version 3.0?
  1063. //TODO: Incorrect property 'grademax' found when inserting grade object
  1064. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1065. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1066. }
  1067. /// Update grade of student
  1068. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1069. global $CFG, $DB, $OUTPUT;
  1070. require_once($CFG->libdir . '/gradelib.php');
  1071. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1072. // Review all the student submission for this iAssign activity
  1073. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1074. $total_grade = 0;
  1075. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1076. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1077. if ($iassign_submission)
  1078. $total_grade += $iassign_submission->grade;
  1079. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1080. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1081. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1082. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1083. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1084. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1085. $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
  1086. if (key($array_sum_grade))
  1087. $sum_grade = key($array_sum_grade); //2
  1088. else
  1089. $sum_grade = 0; //2
  1090. $grades['userid'] = $userid;
  1091. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1092. $params = array('itemname' => $grade_iassign->name);
  1093. $params['iteminstance'] = $iassignid;
  1094. $params['gradetype'] = GRADE_TYPE_VALUE;
  1095. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1096. $params['grademax'] = $sum_grade;
  1097. $params['rawgrademax'] = $sum_grade;
  1098. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1099. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1100. }
  1101. /// Display caption of icons
  1102. function view_legend_icons () {
  1103. global $USER, $CFG, $DB, $OUTPUT;
  1104. $id = $this->cm->id;
  1105. if ($this->action == 'print')
  1106. print '<table border=1 width=100%><tr>';
  1107. else
  1108. print '<table width=100%><tr>';
  1109. print '<td >';
  1110. if ($this->action != 'print')
  1111. print $OUTPUT->help_icon('legend', 'iassign');
  1112. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1113. // $imagetext = '');
  1114. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1115. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1116. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1117. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1118. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1119. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1120. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1121. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1122. print '</td>' . "\n";
  1123. if ($this->action != 'print') {
  1124. $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>";
  1125. $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>";
  1126. $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>";
  1127. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1128. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1129. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1130. } // if ($this->action != 'print')
  1131. print '</tr></table>' . "\n";
  1132. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1133. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1134. $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>";
  1135. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1136. print '</tr></table>' . "\n";
  1137. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1138. else
  1139. print '</td></tr></table>' . "\n";
  1140. } // function view_legend_icons()
  1141. /// Display activity current
  1142. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1143. function view_iassign_current () {
  1144. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1145. $id = $this->cm->id;
  1146. $iassignid = $this->iassign->id;
  1147. $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
  1148. // 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 ...
  1149. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1150. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1151. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1152. // 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
  1153. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1154. // log record
  1155. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1156. //Trigger module viewed event.
  1157. $event = \mod_iassign\event\submission_viewed::create(array(
  1158. 'objectid' => $iassign->id,
  1159. 'context' => $this->context,
  1160. 'other' => $info
  1161. ));
  1162. $event->add_record_snapshot('course', $this->course);
  1163. $event->trigger();
  1164. print $OUTPUT->header();
  1165. // Search of iLM data used in the current activity
  1166. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1167. if ($this->action == 'viewsubmission') {
  1168. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1169. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1170. else
  1171. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1172. } else {
  1173. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1174. }
  1175. if ($iassign_submission)
  1176. $this->update_comment($iassign_submission->id);
  1177. $file = $iassign_statement_activity_item->file;
  1178. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1179. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1180. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1181. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1182. $this->bottonPost = 0; // hide submit button
  1183. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1184. $this->view_iassign = false; // disable visualization of activity
  1185. $repeat = "";
  1186. $last_iassign = "";
  1187. $student_answer = "";
  1188. $comment = "";
  1189. // *** Teacher access (view learner's submission)
  1190. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1191. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1192. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1193. // ---> access teacher for test
  1194. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1195. $this->bottonPost = 1;
  1196. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1197. $this->activity->view_dates();
  1198. $USER->iassignEdit = $this->bottonPost;
  1199. $this->activity->show_info_iassign();
  1200. if ($iassign_submission) {
  1201. //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;
  1202. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1203. } else {
  1204. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1205. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1206. }
  1207. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1208. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1209. // Prepare tags to present the iLM
  1210. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1211. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1212. // *** (end) Teacher access (view the activity)
  1213. // *** Teacher access (view learner's submission to the activity)
  1214. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1215. // It is teacher or 'nonediting teacher' that can evaluate
  1216. // ----> area teacher evaluate
  1217. $row = optional_param('row', 0, PARAM_INT);
  1218. $column = optional_param('column', 0, PARAM_INT);
  1219. $link_next = iassign_icons::insert('right_disable');
  1220. $link_previous = iassign_icons::insert('left_disable');
  1221. $link_up = iassign_icons::insert('up_disable');
  1222. $link_down = iassign_icons::insert('down_disable');
  1223. // next_activity
  1224. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1225. $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);
  1226. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1227. }
  1228. // previous_activity
  1229. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1230. $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);
  1231. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1232. }
  1233. // previous_student
  1234. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1235. $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);
  1236. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1237. }
  1238. // next_student
  1239. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1240. $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);
  1241. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1242. }
  1243. if ($iassign_submission) {
  1244. $student_answer = $iassign_submission->answer;
  1245. }
  1246. $last_iassign = get_string('last_iassign', 'iassign');
  1247. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1248. // Messages related to due date (and user role)
  1249. $this->activity->view_dates();
  1250. print $OUTPUT->box_start();
  1251. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1252. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1253. print $OUTPUT->user_picture($user_data);
  1254. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1255. print '</td>' . "\n";
  1256. print '<td width=20% align=right>' . "\n";
  1257. print '<table width=50 cellpadding="0">';
  1258. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1259. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1260. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1261. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1262. print '</table>' . "\n";
  1263. print '</td></tr></table>' . "\n";
  1264. print $OUTPUT->box_end();
  1265. print $OUTPUT->box_start();
  1266. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1267. print '<td width=60% valign="top">' . "\n";
  1268. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1269. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1270. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1271. $resp = get_string('yes');
  1272. else
  1273. $resp = get_string('no');
  1274. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1275. if ($iassign_statement_activity_item->show_answer == 1)
  1276. $resp = get_string('yes');
  1277. else
  1278. $resp = get_string('no');
  1279. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1280. print '</td>';
  1281. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1282. print '<td width=40% valign="top" align="left">';
  1283. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1284. // check status of solution sent by the student
  1285. if ($iassign_submission) {
  1286. switch ($iassign_submission->status) {
  1287. case 3 :
  1288. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1289. break;
  1290. case 2 :
  1291. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1292. break;
  1293. case 1 :
  1294. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1295. break;
  1296. default :
  1297. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1298. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1299. } // switch ($iassign_submission->status)
  1300. }
  1301. else { // if ($iassign_submission)
  1302. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1303. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1304. }
  1305. // update_status
  1306. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1307. $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);
  1308. print " <script type='text/javascript'>
  1309. //<![CDATA[
  1310. function overwriteStatus (newstatus) {
  1311. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1312. document.formEditStatus.return_status.value=newstatus;
  1313. document.formEditStatus.submit();
  1314. }
  1315. else
  1316. document.formEditStatus.return_status.value=-1;
  1317. }
  1318. //]]>
  1319. </script>";
  1320. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1321. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1322. 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";
  1323. print " <input type='hidden' name='return_status'>\n";
  1324. print "</form>\n";
  1325. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1326. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1327. $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);
  1328. print "
  1329. <script type='text/javascript'>
  1330. //<![CDATA[
  1331. function overwriteGrade (newgrade,maxgrade) {
  1332. if (newgrade<0 || newgrade>maxgrade) {
  1333. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1334. document.formEditGrade.return_grade.value=-1;
  1335. document.formEditGrade.submit();
  1336. }
  1337. else {
  1338. document.formEditGrade.return_grade.value=newgrade;
  1339. document.formEditGrade.submit();
  1340. }
  1341. }
  1342. //]]>
  1343. </script>";
  1344. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1345. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1346. print " <input type='text' name='grade' size='6'>";
  1347. print " <input type='hidden' name='return_grade'> ";
  1348. 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";
  1349. print "</form>";
  1350. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1351. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1352. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1353. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1354. if ($teacher)
  1355. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1356. } // if ($iassign_submission->experiment > 0)
  1357. print '</td>';
  1358. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1359. print '</tr></table>';
  1360. print $OUTPUT->box_end();
  1361. $USER->iassignEdit = $this->bottonPost;
  1362. if ($iassign_submission && $allow_resubmission) {
  1363. // Put the iLM to
  1364. print $OUTPUT->box_start();
  1365. print '<p><strong>' . $last_iassign . '</strong></p>';
  1366. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1367. $enderecoPOST = "";
  1368. // Prepare tags to present the iLM
  1369. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1370. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1371. print $OUTPUT->box_end();
  1372. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1373. // ATTENTION: exception used by iGeom (exercise with "script")
  1374. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1375. if (substr($ilm_name, 0, 5)=="igeom") {
  1376. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1377. $loadTeacherActivity = true;
  1378. }
  1379. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1380. if (!$enderecoPOST) $enderecoPOST = "";
  1381. // Prepare tags to present the iLM
  1382. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1383. }
  1384. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1385. $output = '';
  1386. $history_comment = '';
  1387. if ($iassign_submission) {
  1388. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1389. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1390. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1391. }
  1392. else {
  1393. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  1394. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  1395. }
  1396. $output .= $OUTPUT->box_start();
  1397. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  1398. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  1399. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  1400. $output .= "</form></center>\n";
  1401. if (!empty($history_comment)) {
  1402. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  1403. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  1404. $output .= $history_comment;
  1405. $output .= "</table>";
  1406. }
  1407. $output .= $OUTPUT->box_end();
  1408. print $output;
  1409. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1410. } // elseif (($this->action == 'viewsubmission')
  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. if ($iassign_statement_activity_item->type_iassign == 3) {
  1648. $history_comment = '';
  1649. if ($iassign_submission) {
  1650. $history_comment = $this->search_comment_submission($iassign_submission->id);
  1651. }
  1652. if (!empty($history_comment)) {
  1653. $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  1654. " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  1655. $output .= $history_comment;
  1656. $output .= "</table>\n";
  1657. }
  1658. $output .= "</form></center>\n";
  1659. $output .= $OUTPUT->box_end();
  1660. print $output;
  1661. } else { // if ($iassign_statement_activity_item->type_iassign == 3)
  1662. $output .= $OUTPUT->box_end();
  1663. print $output;
  1664. }
  1665. } // if ($this->view_iassign)
  1666. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  1667. } // if ($this->view_iassign)
  1668. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1669. else
  1670. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  1671. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  1672. print '<table width=100% border=0 valign="top">' . "\n";
  1673. print '<tr><td width=60% valign="top">' . "\n";
  1674. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1675. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1676. print '</tr></table>' . "\n";
  1677. $student_answer = "";
  1678. $enderecoPOST = "";
  1679. // Prepare tags to present the iLM
  1680. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  1681. print $output;
  1682. }
  1683. // final block 'studant'
  1684. print $OUTPUT->footer();
  1685. die();
  1686. } // function view_iassign_current()
  1687. /// Export the data from performance report into CSV file format
  1688. function export_csv () {
  1689. global $USER, $CFG, $DB, $OUTPUT;
  1690. $str = "";
  1691. $fields = "student_id, student_name";
  1692. // Finding all iassign activities for the iassign:
  1693. $id = $this->cm->id;
  1694. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id + 22), "position ASC");
  1695. $c = 1;
  1696. foreach ($iassign_list as $iassign) {
  1697. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  1698. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  1699. $c ++;
  1700. }
  1701. // Finding enrolled students:
  1702. $params = array('shortname' => 'student');
  1703. $role = $DB->get_record_sql(
  1704. "SELECT s.id, s.shortname FROM {role} s " .
  1705. " WHERE s.shortname = :shortname", $params);
  1706. $context = context_course::instance($this->course->id);
  1707. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1708. $students = $DB->get_records_sql(
  1709. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1710. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1711. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1712. foreach ($students as $student) {
  1713. $str .= $student->userid . ',';
  1714. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  1715. foreach ($iassign_list as $iassign) {
  1716. $str .= ',' . $iassign->id . ',';
  1717. $str .= '"' . $iassign->name . '",';
  1718. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  1719. $str .= $student_submissions->experiment . ',';
  1720. $str .= $student_submissions->grade . ',';
  1721. switch ($student_submissions->status) {
  1722. case 3:
  1723. $str .= '"correct",';
  1724. break;
  1725. case 2:
  1726. $str .= '"incorrect",';
  1727. break;
  1728. case 1:
  1729. $str .= '"post",';
  1730. break;
  1731. case 0:
  1732. $str .= '"not_post",';
  1733. break;
  1734. }
  1735. $str .= $iassign->iassign_ilmid . ',';
  1736. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  1737. $str .= '"' . $ilm_activity->name . '"';
  1738. }
  1739. $str .= "\n";
  1740. }
  1741. $str = $fields . "\n" . $str;
  1742. header("Content-disposition: attachment; filename=report.csv");
  1743. header("Pragma: no-cache");
  1744. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  1745. header('Content-Length: ' . strlen($str));
  1746. header('Connection: close');
  1747. echo $str;
  1748. flush();
  1749. }
  1750. /// Display report of performance
  1751. function report () {
  1752. global $USER, $CFG, $DB, $OUTPUT;
  1753. $id = $this->cm->id;
  1754. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  1755. if ($this->action != 'print') {
  1756. $title = get_string('report', 'iassign');
  1757. print $OUTPUT->header();
  1758. } // if ($this->action != 'print')
  1759. print $OUTPUT->box_start();
  1760. $this->view_legend_icons();
  1761. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  1762. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  1763. print $OUTPUT->box_end();
  1764. if ($this->action == 'print')
  1765. print '<table border=1 width="100%">' . "\n";
  1766. else
  1767. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1768. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  1769. // $num = array();
  1770. $i = 1;
  1771. $num = array();
  1772. foreach ($iassign_list as $iassign) {
  1773. $test_exercise = "";
  1774. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  1775. if (($iassign_submission) && $iassign->type_iassign < 3) {
  1776. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  1777. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  1778. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  1779. $num[$i] = new stdClass();
  1780. $num[$i]->name = $iassign->name;
  1781. $num[$i]->id = $i;
  1782. $num[$i]->iassignid = $iassign->id;
  1783. print ' <tr >' . "\n";
  1784. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  1785. print "<td class=\"cell c0 actvity\">";
  1786. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  1787. print ' </tr>' . "\n";
  1788. $i ++;
  1789. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  1790. } // foreach ($iassign_list as $iassign)
  1791. print "</table>";
  1792. print "<p></p>";
  1793. if ($this->action == 'print')
  1794. print '<table border=1 width="100%">' . "\n";
  1795. else
  1796. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  1797. $context = context_course::instance($this->course->id);
  1798. if ($i > 1) {
  1799. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  1800. $params = array('shortname' => 'student');
  1801. $role = $DB->get_record_sql(
  1802. "SELECT s.id, s.shortname FROM {role} s " .
  1803. " WHERE s.shortname = :shortname", $params);
  1804. // $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");
  1805. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  1806. $students = $DB->get_records_sql(
  1807. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  1808. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  1809. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  1810. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  1811. for ($j = 1; $j < $i; $j ++) {
  1812. $sum_iassign_correct[$j] = 0;
  1813. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  1814. }
  1815. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  1816. $sum_iassign = $j - 1;
  1817. print '</tr>' . "\n";
  1818. $total = 0;
  1819. $sum_student = 0;
  1820. $comment = iassign_icons::insert('comment_read');
  1821. $sum_comment = 0;
  1822. $sum_correct_iassign = array();
  1823. $sum_correct_student = array();
  1824. $USER->matrix_iassign = array();
  1825. if ($students) {
  1826. $w = 0;
  1827. foreach ($students as $tmp) {
  1828. $users_array[$w] = $tmp;
  1829. $w ++;
  1830. }
  1831. for ($x = 0; $x < $w; $x ++) {
  1832. print '<tr>' . "\n";
  1833. $sum_student ++;
  1834. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  1835. print ' <td >' . $name . '</td>' . "\n";
  1836. $total_student = 0;
  1837. $tentativas = 0;
  1838. for ($j = 1; $j < $i; $j ++) {
  1839. $sum_comment = 0;
  1840. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  1841. print ' <td valign="bottom" align="center">' . "\n";
  1842. if ($student_submissions) {
  1843. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  1844. $tentativas = $student_submissions->experiment;
  1845. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  1846. $params = array('iassign_submissionid' => $student_submissions->id);
  1847. $student_submissions_comment = $DB->get_record_sql(
  1848. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1849. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  1850. if ($student_submissions_comment)
  1851. foreach ($student_submissions_comment as $tmp)
  1852. $sum_comment = $tmp;
  1853. // informations to previous activities
  1854. if ($j - 1 < 1 || $j == $i)
  1855. $iassign_previous = "-1";
  1856. else
  1857. $iassign_previous = $num[$j - 1]->iassignid;
  1858. if ($x - 1 < 0 || $x == $w)
  1859. $user_previous = "-1";
  1860. else
  1861. $user_previous = $users_array[$x - 1]->userid;
  1862. // next
  1863. if ($i - 1 > $j)
  1864. $iassign_next = $num[$j + 1]->iassignid;
  1865. else
  1866. $iassign_next = "-1";
  1867. if ($w - 1 > $x)
  1868. $user_next = $users_array[$x + 1]->userid;
  1869. else
  1870. $user_next = "-1";
  1871. $position = "&row= $x&column=$j";
  1872. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  1873. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1874. $url .= $position;
  1875. // receiver=1 - message to teacher
  1876. // receiver=2 - message to student
  1877. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  1878. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  1879. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  1880. $verify_message = $DB->get_record_sql(
  1881. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  1882. "WHERE iassign_submissionid = :iassign_submissionid " .
  1883. " AND return_status= :return_status " .
  1884. " AND receiver= :receiver", $params);
  1885. if ($verify_message)
  1886. foreach ($verify_message as $tmp)
  1887. $sum_verify_message = $tmp;
  1888. if ($sum_verify_message > 0)
  1889. $comment = iassign_icons::insert('comment_unread');
  1890. else
  1891. $comment = iassign_icons::insert('comment_read');
  1892. if ($student_submissions->status == 3) {
  1893. $sum_iassign_correct[$j] ++;
  1894. $total_student ++;
  1895. $feedback = iassign_icons::insert('correct');
  1896. }
  1897. elseif ($student_submissions->status == 2) {
  1898. $feedback = iassign_icons::insert('incorrect');
  1899. }
  1900. elseif ($student_submissions->status == 1) {
  1901. $feedback = iassign_icons::insert('post');
  1902. }
  1903. elseif ($student_submissions->status == 0) {
  1904. $feedback = iassign_icons::insert('not_post');
  1905. }
  1906. if ($this->action != 'print') {
  1907. print '<table><tr>';
  1908. if ($tentativas > 0)
  1909. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  1910. else
  1911. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  1912. print '<td> &nbsp; </td>';
  1913. print '</tr>';
  1914. if ($sum_comment > 0 && $sum_verify_message > 0)
  1915. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  1916. else if ($sum_comment > 0)
  1917. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  1918. print '</table>' . "\n";
  1919. }
  1920. if ($this->action == 'print')
  1921. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1922. } // if ($student_submissions)
  1923. else { // if ($student_submissions)
  1924. // informations to browse previous activities
  1925. if ($j - 1 < 1 || $j == $i)
  1926. $iassign_previous = "-1";
  1927. else
  1928. $iassign_previous = $num[$j - 1]->iassignid;
  1929. if ($x - 1 < 0 || $x == $w)
  1930. $user_previous = "-1";
  1931. else
  1932. $user_previous = $users_array[$x - 1]->userid;
  1933. // next
  1934. if ($i - 1 > $j)
  1935. $iassign_next = $num[$j + 1]->iassignid;
  1936. else
  1937. $iassign_next = "-1";
  1938. if ($w - 1 > $x)
  1939. $user_next = $users_array[$x + 1]->userid;
  1940. else
  1941. $user_next = "-1";
  1942. $position = "&row= $x&column=$j";
  1943. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  1944. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  1945. $url .= $position;
  1946. $feedback = iassign_icons::insert('not_post');
  1947. if ($this->action == 'print')
  1948. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  1949. else {
  1950. print '<table><tr>';
  1951. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  1952. print '<td> &nbsp; </td>';
  1953. print '</tr><tr>' . "\n";
  1954. print '<td> &nbsp;</td>';
  1955. if ($sum_comment > 0)
  1956. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  1957. else
  1958. print '<td> &nbsp;</td>';
  1959. print '</tr></table>';
  1960. }
  1961. } // else if ($student_submissions)
  1962. $USER->matrix_iassign[$x][$j] = new stdClass();
  1963. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  1964. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  1965. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  1966. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  1967. if ($student_submissions)
  1968. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  1969. else
  1970. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  1971. print '</td>' . "\n";
  1972. } // for ($j=1; $j<$i; $j++)
  1973. $total = $total + $total_student;
  1974. $porcentagem = ($total_student / ($j - 1)) * 100;
  1975. if ($tentativas != 0 && $tentativas != null) {
  1976. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  1977. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  1978. }
  1979. else {
  1980. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  1981. }
  1982. print '</tr>' . "\n";
  1983. $sum_correct_student[$sum_student] = new stdClass();
  1984. $sum_correct_student[$sum_student]->name = $name;
  1985. $sum_correct_student[$sum_student]->sum = $total_student;
  1986. } // for ($x = 0; $x < $w; $x ++)
  1987. for ($i = 1; $i < $j; $i ++) {
  1988. if (is_null($sum_iassign_correct[$i]))
  1989. $sum_iassign_correct[$i] = 0;
  1990. $sum_correct_iassign[$i] = new stdClass();
  1991. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  1992. $sum_correct_iassign[$i]->name = $num[$i]->name;
  1993. }
  1994. // print '</tr></table>' . "\n";
  1995. }
  1996. } // if ($i>1)
  1997. else {
  1998. print_string('no_activity', 'iassign');
  1999. }
  2000. print "</table>\n";
  2001. if ($this->action != 'print')
  2002. print $OUTPUT->footer();
  2003. die();
  2004. } // function report()
  2005. /// Display graphics of performance
  2006. function stats () {
  2007. global $USER, $CFG, $DB, $OUTPUT;
  2008. $id = $this->cm->id;
  2009. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2010. if ($this->action != 'printstats')
  2011. $title = get_string('graphic', 'iassign');
  2012. $num = array();
  2013. $sum_correct_iassign = array();
  2014. $sum_correct_student = array();
  2015. $sum_student = 0;
  2016. $i = 1;
  2017. foreach ($iassign_list as $iassign) {
  2018. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2019. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2020. $sum_iassign_correct[$i] = 0;
  2021. $num[$i] = new stdClass();
  2022. $num[$i]->name = $iassign->name;
  2023. $num[$i]->id = $i;
  2024. $num[$i]->iassignid = $iassign->id;
  2025. $i ++;
  2026. } // if ($iassign->type_iassign == 3)
  2027. } // foreach ($iassign_list as $iassign)
  2028. $sum_iassign = $i - 1;
  2029. $context = context_course::instance($this->course->id);
  2030. if ($i > 1) {
  2031. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2032. $params = array('shortname' => 'student');
  2033. $role = $DB->get_record_sql(
  2034. "SELECT s.id, s.shortname FROM {role} s " .
  2035. " WHERE s.shortname = :shortname", $params);
  2036. // $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");
  2037. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2038. $students = $DB->get_records_sql(
  2039. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2040. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2041. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2042. $total = 0;
  2043. $sum_student = 0;
  2044. $j = 0;
  2045. $sum_correct_iassign = array();
  2046. $sum_correct_student = array();
  2047. $sum_experiment = array();
  2048. if ($students) {
  2049. foreach ($students as $users) {
  2050. $sum_student ++;
  2051. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2052. // rows
  2053. $total_student = 0;
  2054. for ($j = 1; $j < $i; $j ++) {
  2055. $total_experiment = 0;
  2056. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2057. if ($student_submissions) {
  2058. if ($student_submissions->status == 3) {
  2059. $sum_iassign_correct[$j] ++;
  2060. $total_student ++;
  2061. } // if ($student_submissions->status == 3)
  2062. $total_experiment += $student_submissions->experiment;
  2063. }
  2064. $sum_experiment[$j] = $total_experiment;
  2065. } // for ($j=1; $j<$i; $j++)
  2066. $total = $total + $total_student;
  2067. $sum_correct_student[$sum_student] = new stdClass();
  2068. $sum_correct_student[$sum_student]->name = $name;
  2069. $sum_correct_student[$sum_student]->sum = $total_student;
  2070. } // foreach ($students as $users)
  2071. }
  2072. for ($i = 1; $i < $j; $i ++) {
  2073. if (is_null($sum_iassign_correct[$i]))
  2074. $sum_iassign_correct[$i] = 0;
  2075. $sum_correct_iassign[$i] = new stdClass();
  2076. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2077. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2078. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2079. } // for ($i = 1; $i < $j; $i++)
  2080. } // if ($i > 1)
  2081. if ($this->action != 'printstats') {
  2082. $title = get_string('graphic', 'iassign');
  2083. print $OUTPUT->header();
  2084. $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>";
  2085. $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>";
  2086. print '<table width=100%><tr>';
  2087. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2088. print '<td width=15% align="right">' . $link_report . '</td>';
  2089. print '</td></tr></table>' . "\n";
  2090. print "<br><br>";
  2091. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2092. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2093. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2094. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2095. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2096. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2097. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2098. print '</tr>' . "\n";
  2099. $sum_correct = 0;
  2100. if ($sum_correct_iassign) {
  2101. foreach ($sum_correct_iassign as $iassign) {
  2102. if (is_null($iassign->experiment))
  2103. $iassign->experiment = 0;
  2104. $bar = "";
  2105. $sum = $iassign->sum;
  2106. $percent = ($sum / $sum_student) * 100;
  2107. $text = number_format($percent, 1) . '%';
  2108. $sum_correct += $sum;
  2109. if ($sum > 0) {
  2110. for ($i = 1; $i < $percent * 2; $i ++)
  2111. $bar .= iassign_icons::insert('hbar_blue');
  2112. $bar .= iassign_icons::insert('hbar_blue_r');
  2113. } // if ($sum > 0)
  2114. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2115. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2116. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2117. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2118. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2119. print '</tr>' . "\n";
  2120. } // foreach ($sum_correct_iassign as $iassign)
  2121. }
  2122. print "</table>";
  2123. print "<br><br>";
  2124. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2125. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2126. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2127. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2128. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2129. print '</tr>' . "\n";
  2130. $sum_correct = 0;
  2131. foreach ($sum_correct_student as $student) {
  2132. $bar = "";
  2133. $sum = $student->sum;
  2134. $percent = ($sum / $sum_iassign) * 100;
  2135. $text = number_format($percent, 1) . '%';
  2136. $sum_correct += $sum;
  2137. if ($sum > 0) {
  2138. for ($i = 1; $i < $percent * 2; $i ++)
  2139. $bar .= iassign_icons::insert('hbar_blue');
  2140. $bar .= iassign_icons::insert('hbar_blue_r');
  2141. } // if ($sum > 0)
  2142. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2143. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2144. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2145. print '</tr>' . "\n";
  2146. } // foreach ($sum_correct_student as $student)
  2147. print "</table>\n";
  2148. print "<br><br>\n";
  2149. $var = 0;
  2150. $cv = 0;
  2151. $dv = 0;
  2152. $avg = 0;
  2153. if ($sum_correct_student) {
  2154. $avg = $sum_correct / $sum_student;
  2155. if ($avg > 0) {
  2156. foreach ($sum_correct_student as $student)
  2157. $var += pow($student->sum - $avg, 2);
  2158. $var = $var / $sum_student;
  2159. $dv = sqrt($var);
  2160. $cv = ($dv / $avg) * 100;
  2161. }
  2162. }
  2163. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2164. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2165. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2166. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2167. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2168. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2169. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2170. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2171. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2172. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2173. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2174. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2175. print "</table>\n";
  2176. print $OUTPUT->footer();
  2177. } else {
  2178. print "<STYLE TYPE='text/css'>
  2179. <!--
  2180. .boldtable {
  2181. font-family:sans-serif;
  2182. font-size:10pt;
  2183. }
  2184. -->
  2185. </STYLE>\n";
  2186. print '<table border=1 width=100%>' . "\n";
  2187. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2188. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2189. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2190. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2191. print '</tr>' . "\n";
  2192. $sum_correct = 0;
  2193. foreach ($sum_correct_iassign as $iassign) {
  2194. $bar = "";
  2195. $sum = $iassign->sum;
  2196. $percent = ($sum / $sum_student) * 100;
  2197. $text = number_format($percent, 1) . '%';
  2198. $sum_correct += $sum;
  2199. if ($sum > 0) {
  2200. for ($i = 1; $i < $percent * 2; $i ++)
  2201. $bar .= iassign_icons::insert('hbar_blue');
  2202. $bar .= iassign_icons::insert('hbar_blue_r');
  2203. } // if ($sum > 0)
  2204. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2205. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2206. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2207. print '</tr>' . "\n";
  2208. } // foreach ($sum_correct_iassign as $iassign)
  2209. print "</table>";
  2210. print "<br><br>";
  2211. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2212. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2213. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2214. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2215. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2216. print '</tr>' . "\n";
  2217. $sum_correct = 0;
  2218. foreach ($sum_correct_student as $student) {
  2219. $bar = "";
  2220. $sum = $student->sum;
  2221. $percent = ($sum / $sum_iassign) * 100;
  2222. $text = number_format($percent, 1) . '%';
  2223. $sum_correct += $sum;
  2224. if ($sum > 0) {
  2225. for ($i = 1; $i < $percent * 2; $i ++)
  2226. $bar .= iassign_icons::insert('hbar_blue');
  2227. $bar .= iassign_icons::insert('hbar_blue_r');
  2228. } // if ($sum > 0)
  2229. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2230. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2231. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2232. print '</tr>' . "\n";
  2233. } // foreach ($sum_correct_student as $student)
  2234. print "</table>\n";
  2235. print "<br/><br/>\n";
  2236. $var = 0;
  2237. $cv = 0;
  2238. $dv = 0;
  2239. $avg = 0;
  2240. if ($sum_correct_student) {
  2241. $avg = $sum_correct / $sum_student;
  2242. if ($avg > 0) {
  2243. foreach ($sum_correct_student as $student)
  2244. $var += pow($student->sum - $avg, 2);
  2245. $var = $var / $sum_student;
  2246. $dv = sqrt($var);
  2247. $cv = ($dv / $avg) * 100;
  2248. }
  2249. }
  2250. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2251. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2252. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2253. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2254. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2255. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2256. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2257. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2258. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2259. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2260. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2261. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2262. print "</table>\n";
  2263. } // if ($this->action != 'printstats')
  2264. die();
  2265. }
  2266. /// Display graphics of performance for students
  2267. function stats_students () {
  2268. global $USER, $CFG, $DB, $OUTPUT;
  2269. $id = $this->cm->id;
  2270. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2271. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2272. $title = get_string('results', 'iassign');
  2273. $sum_correct = 0;
  2274. $sum_incorrect = 0;
  2275. $sum_post = 0;
  2276. $sum_nopost = 0;
  2277. $sum_iassign = count($iassign_statement_list);
  2278. $bar_nopost = "";
  2279. $bar_correct = "";
  2280. $bar_incorrect = "";
  2281. $bar_post = "";
  2282. $text_nopost = "";
  2283. $text_correct = "";
  2284. $text_incorrect = "";
  2285. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2286. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2287. if ($iassign_submission) {
  2288. if ($iassign_submission->status == 3)
  2289. $sum_correct ++;
  2290. elseif ($iassign_submission->status == 2)
  2291. $sum_incorrect ++;
  2292. elseif ($iassign_submission->status == 1)
  2293. $sum_post ++;
  2294. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2295. $sum_nopost ++;
  2296. } // if ($iassign_submission)
  2297. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2298. if ($sum_iassign > 0) {
  2299. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2300. $text_correct = number_format($percent_correct, 1) . '%';
  2301. }
  2302. if ($sum_correct > 0) {
  2303. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2304. $bar_correct .= iassign_icons::insert('hbar_green');
  2305. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2306. } // if ($sum_correct > 0)
  2307. if ($sum_iassign > 0) {
  2308. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2309. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2310. }
  2311. if ($sum_incorrect > 0) {
  2312. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2313. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2314. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2315. } // if ($sum_incorrect > 0)
  2316. if ($sum_iassign > 0) {
  2317. $percent_post = ($sum_post / $sum_iassign) * 100;
  2318. $text_post = number_format($percent_post, 1) . '%';
  2319. }
  2320. if ($sum_post > 0) {
  2321. for ($i = 1; $i < $percent_post * 2; $i ++)
  2322. $bar_post .= iassign_icons::insert('hbar_blue');
  2323. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2324. } // if ($sum_post > 0)
  2325. if ($sum_iassign > 0) {
  2326. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2327. $text_nopost = number_format($percent_nopost, 1) . '%';
  2328. }
  2329. if ($sum_nopost > 0) {
  2330. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2331. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2332. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2333. } // if ($sum_nopost > 0)
  2334. print $OUTPUT->header();
  2335. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2336. print '<table width=100%><tr>';
  2337. print '<td align="right">' . $link_return . '</td>' . "\n";
  2338. print '</td></tr></table>' . "\n";
  2339. print "<br/><br/>\n";
  2340. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2341. print '<tr><th colspan=3 class="header c1">' . "\n";
  2342. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2343. // $imagetext = '');
  2344. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2345. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2346. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2347. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2348. print '</tr>' . "\n";
  2349. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2350. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2351. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2352. print '</tr>' . "\n";
  2353. if ($sum_post) {
  2354. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2355. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2356. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2357. print '</tr>' . "\n";
  2358. } // if ($sum_post)
  2359. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2360. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2361. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2362. print '</tr>' . "\n";
  2363. print "</table>";
  2364. print "<br><br>";
  2365. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2366. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2367. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2368. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2369. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2370. $sum_grade = 0;
  2371. $sum_grade_student = 0;
  2372. $avg = 0;
  2373. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2374. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2375. if (!$iassign_submission) {
  2376. $iassign_submission = new stdClass();
  2377. $iassign_submission->grade = 0;
  2378. }
  2379. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2380. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2381. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2382. print '</tr>' . "\n";
  2383. $sum_grade += $iassign_statement_activity_item->grade;
  2384. $sum_grade_student += $iassign_submission->grade;
  2385. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2386. if ($sum_grade > 0)
  2387. $avg = $sum_grade_student / $sum_grade * 100;
  2388. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2389. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2390. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2391. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2392. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2393. print "</table>";
  2394. print $OUTPUT->footer();
  2395. die();
  2396. } // function stats_students()
  2397. /// Display page of iAssign's activity
  2398. function view_iassigns () {
  2399. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2400. $id = $this->cm->id;
  2401. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2402. $notice = optional_param('notice', '', PARAM_TEXT);
  2403. if (strpos($notice, 'error'))
  2404. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2405. else if ($notice != '')
  2406. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2407. print $OUTPUT->box_start();
  2408. print '<table width=100% border=0><tr>' . "\n";
  2409. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2410. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2411. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2412. $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>";
  2413. $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>";
  2414. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2415. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2416. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2417. // Has capability to see "report": teacher or up
  2418. print '<td width=10% align="left">' . "\n";
  2419. print $link_help;
  2420. print '</td>' . "\n";
  2421. print '<td width=10% align="left">' . "\n";
  2422. print $link_report;
  2423. print '</td>' . "\n";
  2424. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2425. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2426. print '<td width=15% align="left">' . "\n";
  2427. print $link_add;
  2428. print "</td>\n";
  2429. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2430. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2431. if ($iassign_list) {
  2432. print '<td align="right">' . "\n";
  2433. // $USER->iassignEdit == 0 view 'Turn editing off'
  2434. // $USER->iassignEdit == 1 view 'Turn editing on'
  2435. if (!isset($USER->iassignEdit))
  2436. $USER->iassignEdit = 0;
  2437. if ($USER->iassignEdit == 0) {
  2438. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2439. $botton = 1;
  2440. } // if ($USER->iassignEdit == 0)
  2441. elseif ($USER->iassignEdit == 1) {
  2442. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2443. $botton = 0;
  2444. } // elseif ($USER->iassignEdit == 1)
  2445. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2446. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2447. print " <input type=submit value='$bottonEdit_message'/>\n";
  2448. print "</form>\n";
  2449. print "</td>\n";
  2450. } // if ($iassign_list)
  2451. }
  2452. print '</tr></table>' . "\n";
  2453. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2454. $this->view_legend_icons();
  2455. print $OUTPUT->box_end();
  2456. $iassign_array_exercise = array();
  2457. $i_exercise = 0;
  2458. $iassign_array_test = array();
  2459. $i_test = 0;
  2460. $iassign_array_example = array();
  2461. $i_example = 0;
  2462. $iassign_array_general = array();
  2463. $i_general = 0;
  2464. if ($iassign_list) {
  2465. if ($this->iassign->activity_group == 0) {
  2466. foreach ($iassign_list as $iassign) {
  2467. $iassign_array_general[$i_general] = $iassign;
  2468. $i_general ++;
  2469. }
  2470. } // if ($this->iassign->activity_group == 0)
  2471. else {
  2472. foreach ($iassign_list as $iassign) {
  2473. if ($iassign->type_iassign == 3) {
  2474. $iassign_array_exercise[$i_exercise] = $iassign;
  2475. $i_exercise ++;
  2476. } // if ($iassign->type_iassign == 3)
  2477. if ($iassign->type_iassign == 2) {
  2478. $iassign_array_test[$i_test] = $iassign;
  2479. $i_test ++;
  2480. } // if ($iassign->type_iassign == 2)
  2481. if ($iassign->type_iassign == 1) {
  2482. $iassign_array_example[$i_example] = $iassign;
  2483. $i_example ++;
  2484. } // if ($iassign->type_iassign == 1)
  2485. }
  2486. }
  2487. if ($iassign_array_exercise) {
  2488. $title = get_string('exercise', 'iassign');
  2489. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2490. }
  2491. if ($iassign_array_test) {
  2492. $title = get_string('test', 'iassign');
  2493. $this->show_iassign($title, $iassign_array_test, $i_test);
  2494. }
  2495. if ($iassign_array_example) {
  2496. $title = get_string('example', 'iassign');
  2497. $this->show_iassign($title, $iassign_array_example, $i_example);
  2498. }
  2499. if ($iassign_array_general) {
  2500. $title = "";
  2501. $this->show_iassign($title, $iassign_array_general, $i_general);
  2502. }
  2503. } else { // if ($iassign_list)
  2504. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2505. }
  2506. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2507. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2508. print $OUTPUT->box_start();
  2509. print '<table width=100% border=0><tr>' . "\n";
  2510. print '<td width=10% align="left">' . "\n";
  2511. print $link_report;
  2512. print '</td>' . "\n";
  2513. print '</tr></table>' . "\n";
  2514. print $OUTPUT->box_end();
  2515. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2516. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2517. print $OUTPUT->box_start();
  2518. print '<table width=100% border=0><tr>' . "\n";
  2519. print '<td align="left">' . "\n";
  2520. print $link_add;
  2521. print '</td>' . "\n";
  2522. print '</tr></table>' . "\n";
  2523. print $OUTPUT->box_end();
  2524. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2525. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2526. } // function view_iassigns()
  2527. /// Display all iAssigns
  2528. function show_iassign ($title, $iassign_array, $i) {
  2529. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2530. $id = $this->cm->id;
  2531. print $OUTPUT->box_start();
  2532. print " <script type='text/javascript'>
  2533. //<![CDATA[
  2534. function validate_move () {
  2535. var radios = document.getElementsByName('iassign_destiny');
  2536. var formValid = false;
  2537. //alert('aqui validate_move()');
  2538. var i = 0;
  2539. while (!formValid && i < radios.length) {
  2540. if (radios[i].checked) formValid = true;
  2541. i++;
  2542. }
  2543. if (!formValid) {
  2544. document.getElementById('move_dest').classList.add('alert-danger');
  2545. }
  2546. return formValid;
  2547. }
  2548. var modal;
  2549. function load_move(id_ias) {
  2550. document.form_move_activity.iassign_current.value = id_ias;
  2551. modal.style.display = 'block';
  2552. var radios = document.getElementsByName('iassign_destiny');
  2553. var i = 0;
  2554. while (i < radios.length) {
  2555. radios[i].checked = false;
  2556. i++;
  2557. }
  2558. document.getElementById('move_dest').classList.remove('alert-danger');
  2559. }
  2560. function load_modal_elements() {
  2561. modal = document.getElementById('myModal');
  2562. var span = document.getElementById('close_modal');
  2563. span.onclick = function() {
  2564. modal.style.display = 'none';
  2565. }
  2566. window.onclick = function(event) {
  2567. if (event.target == modal) {
  2568. modal.style.display = 'none';
  2569. }
  2570. }
  2571. }
  2572. window.onload = load_modal_elements;
  2573. //]]>
  2574. </script>\n";
  2575. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  2576. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  2577. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  2578. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  2579. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  2580. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  2581. <input type='hidden' name='iassign_current' value='' />";
  2582. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  2583. $section = $course_sections[0];
  2584. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  2585. for ($k = 0; $k < count($ids_sections); $k++) {
  2586. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  2587. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  2588. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  2589. if ($c_cm) {
  2590. if ($ccm->instance == $c_cm->instance) {
  2591. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2592. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2593. }
  2594. else {
  2595. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  2596. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  2597. }
  2598. }
  2599. }
  2600. $radio_buttons .= "</ul>";
  2601. }
  2602. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  2603. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  2604. </form>
  2605. </div></div> </div></div>\n";
  2606. print " <style>.modal {
  2607. display: none;
  2608. position: fixed;
  2609. z-index: 1;
  2610. left: 0;
  2611. top: 0;
  2612. width: 100%;
  2613. height: 100%;
  2614. overflow: scroll;
  2615. background-color: rgb(0,0,0);
  2616. background-color: rgba(0,0,0,0.4);
  2617. }
  2618. .modal-content {
  2619. background-color: #fefefe;
  2620. margin: 15% auto;
  2621. padding: 10px 10px;
  2622. border: 1px solid #888;
  2623. width: 50%;
  2624. }
  2625. #close_modal {
  2626. color: #aaa;
  2627. float: right;
  2628. font-size: 28px;
  2629. font-weight: bold;
  2630. margin-top: -15px;
  2631. margin-right: -3px;
  2632. }
  2633. #close_modal:hover,
  2634. #close_modal:focus {
  2635. color: black;
  2636. text-decoration: none;
  2637. cursor: pointer;
  2638. }
  2639. #modal_title {
  2640. min-height: 3rem;
  2641. color: initial;
  2642. background: initial;
  2643. font-size: 1.5rem;
  2644. line-height: 1.5;
  2645. padding: 15px;
  2646. border-bottom: 1px solid #e5e5e5;
  2647. }
  2648. .input_move {
  2649. width: 90%;
  2650. padding: 2px;
  2651. }
  2652. .input_move:hover {
  2653. background: #eff0ef;
  2654. }
  2655. </style>";
  2656. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2657. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  2658. for ($j = 0; $j < $i; $j ++) {
  2659. $iassign_current = $iassign_array[$j]->id;
  2660. // receiver=1 - message to teacher
  2661. // receiver=2 - message to student
  2662. $sum_comment = 0;
  2663. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  2664. foreach ($iassign_submissions as $iassign_submission) {
  2665. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  2666. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2667. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2668. if ($verify_message)
  2669. foreach ($verify_message as $tmp)
  2670. $sum_comment += $tmp;
  2671. } // foreach ($iassign_submissions as $iassign_submission)
  2672. if ($sum_comment == 0)
  2673. $comment_unread = "";
  2674. else {
  2675. $comment_unread_message = get_string('comment_unread', 'iassign');
  2676. if ($sum_comment == 1)
  2677. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2678. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  2679. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  2680. }
  2681. if ($j == $i - 1)
  2682. $iassign_down = $iassign_array[$j]->id;
  2683. else
  2684. $iassign_down = $iassign_array[$j + 1]->id;
  2685. if ($j > 0)
  2686. $iassign_up = $iassign_array[$j - 1]->id;
  2687. else
  2688. $iassign_up = $iassign_array[$j]->id;
  2689. if ($iassign_array[$j]->visible == 0)
  2690. $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>";
  2691. else
  2692. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2693. $links .= $comment_unread;
  2694. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  2695. $aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  2696. $link_up = "&nbsp;<a href='view.php?action=up$aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  2697. $link_down = "&nbsp;<a href='view.php?action=down$aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  2698. $link_delete = "&nbsp;<a href='view.php?action=delete$aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  2699. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  2700. $link_visible_show = "&nbsp;<a href='view.php?action=visible$aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  2701. $link_edit = "&nbsp;<a href='view.php?action=edit$aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  2702. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  2703. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  2704. if (count($iassign_array) > 1) {
  2705. if ($j == 0)
  2706. $links .= $link_down;
  2707. elseif ($j == $i - 1)
  2708. $links .= $link_up;
  2709. else
  2710. $links .= $link_up . $link_down;
  2711. } // if (count($iassign_array) > 1)
  2712. $links .= $link_edit . $link_delete;
  2713. if ($iassign_array[$j]->visible == 0)
  2714. $links .= $link_visible_show;
  2715. else
  2716. $links .= $link_visible_hide;
  2717. $links .= $link_duplicate_activity . $link_move_activity;
  2718. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2719. print '<p>' . $links . '</p>' . "\n";
  2720. }
  2721. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2722. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  2723. print '<table width=100% ><tr>' . "\n";
  2724. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2725. print '</tr></table>' . "\n";
  2726. for ($j = 0; $j < $i; $j ++) {
  2727. $icon_status = "";
  2728. $icon_comment = "";
  2729. if ($iassign_array[$j]->visible == 1) {
  2730. $iassign_current = $iassign_array[$j]->id;
  2731. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  2732. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2733. $icon_status = "";
  2734. $icon_comment = "";
  2735. if ($iassign_submission) {
  2736. // receiver=1 - message to teacher
  2737. // receiver=2 - message to student
  2738. // $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");
  2739. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  2740. $verify_message = $DB->get_record_sql(
  2741. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2742. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  2743. if ($verify_message)
  2744. foreach ($verify_message as $tmp)
  2745. $sum_comment = $tmp;
  2746. if ($sum_comment > 0) {
  2747. $comment_unread_message = get_string('comment_unread', 'iassign');
  2748. if ($sum_comment == 1)
  2749. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  2750. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  2751. }
  2752. // $icon_comment = iassign_icons::insert('comment_unread');
  2753. if ($iassign_array[$j]->type_iassign == 3) {
  2754. if ($iassign_array[$j]->show_answer == 1) {
  2755. if ($iassign_submission->status == 3)
  2756. $icon_status = iassign_icons::insert('correct');
  2757. elseif ($iassign_submission->status == 2)
  2758. $icon_status = iassign_icons::insert('incorrect');
  2759. elseif ($iassign_submission->status == 1)
  2760. $icon_status = iassign_icons::insert('post');
  2761. elseif ($iassign_submission->status == 0)
  2762. $icon_status = iassign_icons::insert('not_post');
  2763. } // if ($iassign_array[$j]->show_answer==1)
  2764. else {
  2765. if ($iassign_submission->status == 0)
  2766. $icon_status = iassign_icons::insert('not_post');
  2767. else
  2768. $icon_status = iassign_icons::insert('post');
  2769. }
  2770. } // if ($iassign_array[$j]->type_iassign == 3)
  2771. } // if ($iassign_submission)
  2772. elseif ($iassign_array[$j]->type_iassign == 3) {
  2773. $icon_status = iassign_icons::insert('not_post');
  2774. } // if ($iassign_array[$j]->type_iassign == 3)
  2775. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  2776. } // if ($iassign_array[$j]->visible == 1)
  2777. } // for ($j = 0; $j < $i; $j++)
  2778. } else if (isguestuser()) {
  2779. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2780. print '<table width=100% ><tr>' . "\n";
  2781. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  2782. print '</tr></table>' . "\n";
  2783. for ($j = 0; $j < $i; $j ++) {
  2784. $icon_status = "";
  2785. $icon_comment = "";
  2786. if ($iassign_array[$j]->visible == 1) {
  2787. $iassign_current = $iassign_array[$j]->id;
  2788. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  2789. print '<p>' . $links . '</p>' . "\n";
  2790. } // if ($iassign_array[$j]->visible == 1)
  2791. }
  2792. }
  2793. print $OUTPUT->box_end();
  2794. } // function show_iassign($title, $iassign_array, $i)
  2795. /// Show message of return
  2796. function return_home_course ($message) {
  2797. //D global $DB, $OUTPUT;
  2798. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2799. //D echo $OUTPUT->box_start();
  2800. //D echo '<table width=100% border=0 valign="top">' . "\n";
  2801. //D echo '<tr><td align="left"><strong>' . "\n";
  2802. //D print_string($message, 'iassign');
  2803. //D echo '</strong></td>' . "\n";
  2804. //D echo '<td width=20% align="right">' . "\n";
  2805. //D echo $link_return;
  2806. //D echo '</td></tr></table>' . "\n";
  2807. //D echo $OUTPUT->box_end();
  2808. //D // echo $OUTPUT->footer();
  2809. redirect(new moodle_url($this->return . '&notice=' . $message));
  2810. exit;
  2811. }
  2812. /// Search comment of activity
  2813. function search_comment_submission ($iassign_submissionid) {
  2814. global $USER, $DB, $OUTPUT, $COURSE;
  2815. $context = context_course::instance($COURSE->id);
  2816. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  2817. $text = "";
  2818. if ($comments) {
  2819. foreach ($comments as $tmp) {
  2820. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  2821. if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  2822. $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2823. $text .= "$tmp->comment</td></tr>";
  2824. } else {
  2825. $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  2826. $text .= $tmp->comment . "</td></tr>\n";
  2827. }
  2828. } // foreach ($comments as $tmp)
  2829. }
  2830. return $text;
  2831. }
  2832. /// Update comment of activity
  2833. function update_comment ($iassign_submissionid) {
  2834. global $USER, $DB, $OUTPUT;
  2835. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  2836. $receiver = 1; // student message to teacher
  2837. else
  2838. $receiver = 2; // teacher message to student
  2839. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  2840. if ($verify_message) {
  2841. foreach ($verify_message as $message) {
  2842. if ($message->receiver == $receiver) {
  2843. $newentry = new stdClass();
  2844. $newentry->id = $message->id;
  2845. $newentry->return_status = 1;
  2846. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  2847. print_error('error_update', 'iassign');
  2848. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  2849. } // if ($message->receiver == $receiver)
  2850. // Trigger module viewed event.
  2851. $event = \mod_iassign\event\submission_comment_updated::create(array(
  2852. 'objectid' => $this->iassign->id,
  2853. 'context' => $this->context
  2854. ));
  2855. $event->add_record_snapshot('course', $this->course);
  2856. $event->trigger();
  2857. } // foreach ($verify_message as $message)
  2858. }
  2859. }
  2860. /// Record comment of activity
  2861. function write_comment_submission () {
  2862. global $USER, $CFG, $DB;
  2863. $id = $this->cm->id;
  2864. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  2865. $row = optional_param('row', 0, PARAM_INT);
  2866. $column = optional_param('column', 0, PARAM_INT);
  2867. $sum_comment = 0;
  2868. $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);
  2869. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  2870. $str1 = trim($submission_comment);
  2871. $str2 = trim(get_string('box_comment_message', 'iassign'));
  2872. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  2873. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  2874. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  2875. $receiver = 1; // student message to teacher
  2876. $this->action = 'view';
  2877. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  2878. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  2879. } else {
  2880. $receiver = 2; // teacher message to student
  2881. $this->action = 'viewsubmission';
  2882. //D $tousers = array(); //MOOC 2016
  2883. //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
  2884. }
  2885. //MOOC 2016: foi p/ 15 linhas acima:
  2886. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  2887. if (!$iassign_submission) {
  2888. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  2889. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  2890. $this->iassign_submission_current = $id_submission;
  2891. } else {
  2892. $id_submission = $iassign_submission->id;
  2893. } // if (!$iassign_submission)
  2894. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  2895. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  2896. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  2897. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  2898. $comments = $DB->get_record_sql(
  2899. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2900. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  2901. if ($comments)
  2902. foreach ($comments as $tmp)
  2903. $sum_comment = $tmp;
  2904. if ($sum_comment == 0) {
  2905. $newentry = new stdClass();
  2906. $newentry->iassign_submissionid = $id_submission;
  2907. $newentry->comment_authorid = $USER->id;
  2908. $newentry->timecreated = time();
  2909. $newentry->comment = $submission_comment;
  2910. $newentry->receiver = $receiver;
  2911. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  2912. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  2913. //T $eventdata = new stdClass();
  2914. //T $eventdata->component = 'mod_iassign'; //your component name
  2915. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  2916. //T $eventdata->userfrom = $USER;
  2917. //T $eventdata->userto = $touser;
  2918. //T $eventdata->subject = "Teste de Subject";
  2919. //T $eventdata->fullmessage = "Teste de Mensagem...";
  2920. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  2921. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  2922. //T $eventdata->smallmessage = "Teste de Mensagem";
  2923. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  2924. //T // alteracao tulio faria
  2925. //T //message_send($eventdata);
  2926. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  2927. // Trigger module viewed event.
  2928. $event = \mod_iassign\event\submission_comment_created::create(array(
  2929. 'objectid' => $this->iassign->id,
  2930. 'context' => $this->context
  2931. ));
  2932. $event->add_record_snapshot('course', $this->course);
  2933. $event->trigger();
  2934. }
  2935. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  2936. // if ($this->action=='viewsubmission') {
  2937. // echo $OUTPUT->header();
  2938. // $this->return_last('confirm_add_comment', $link_return);
  2939. // die;
  2940. // }
  2941. return true;
  2942. } // function write_comment_submission()
  2943. /// Writes a new submission
  2944. // The first student answer is under 'function get_answer()'
  2945. function new_submission ($iassignid, $id_user, $receiver) {
  2946. global $USER, $DB, $OUTPUT;
  2947. $newentry = new stdClass();
  2948. $newentry->iassign_statementid = $iassignid;
  2949. $newentry->userid = $id_user;
  2950. $newentry->timecreated = time();
  2951. $newentry->timemodified = time();
  2952. $newentry->answer = 0; // student only submit message
  2953. if ($receiver == 2) // teacher message to student (write id teacher)
  2954. $newentry->teacher = $USER->id;
  2955. //D echo "locallib.php: new_submission(): answer=" . $newentry->answer . "<br/>"; exit;
  2956. //D echo "locallib.php: new_submission(): id_user=$id_user<br/>";
  2957. //D exit;
  2958. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  2959. return_home_course('error_insert_submissions');
  2960. else {
  2961. // Trigger module view event
  2962. $event = \mod_iassign\event\submission_created::create(array(
  2963. 'objectid' => $this->iassign->id,
  2964. 'context' => $this->context
  2965. ));
  2966. $event->add_record_snapshot('course', $this->course);
  2967. $event->trigger();
  2968. }
  2969. return $newentry->id;
  2970. }
  2971. /// Return to a specific address of page
  2972. function return_last ($message, $link_return) {
  2973. global $DB, $OUTPUT;
  2974. print $OUTPUT->box_start();
  2975. print '<table width=100% border=0 valign="top">' . "\n";
  2976. print '<tr><td align="left"><strong>' . "\n";
  2977. print_string($message, 'iassign');
  2978. print '</strong></td>' . "\n";
  2979. print '<td width=20% align="right">' . "\n";
  2980. print $link_return;
  2981. print '</td></tr></table>' . "\n";
  2982. print $OUTPUT->box_end();
  2983. print $OUTPUT->footer();
  2984. die();
  2985. } // function return_last($message, $link_return)
  2986. } // class iassign
  2987. /// Class for manage activities
  2988. class activity {
  2989. var $activity;
  2990. /// Constructor of class.
  2991. // @param int $id Id of activity
  2992. // 3.1 update PHP 7.0 compatibility for all moodle versions
  2993. //D public function activity($id) { self::__construct($id); }
  2994. function __construct ($id) {
  2995. global $DB;
  2996. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  2997. if (empty($this->activity))
  2998. $this->activity = null;
  2999. }
  3000. /// Get an activity
  3001. // @return NULL
  3002. function get_activity () {
  3003. if ($this->activity != null)
  3004. return $this->activity;
  3005. else
  3006. return null;
  3007. }
  3008. /// Delete interactive activities
  3009. function delete ($return) {
  3010. global $USER, $CFG, $DB, $OUTPUT;
  3011. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3012. $output = $OUTPUT->header();
  3013. $output .= $OUTPUT->box_start();
  3014. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3015. if ($iassign_submission_currents) {
  3016. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3017. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3018. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3019. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3020. $output .= $OUTPUT->box_end();
  3021. $output .= $OUTPUT->footer();
  3022. print $output;
  3023. die();
  3024. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3025. } // if ($iassign_submission_currents)
  3026. else
  3027. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3028. $output .= '<table width=50% border=0>';
  3029. $output .= '<tr valign="top"><td>';
  3030. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3031. $output .= '</td><td>';
  3032. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3033. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3034. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3035. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3036. $output .= "</form>\n";
  3037. $output .= '</td><td>';
  3038. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3039. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3040. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3041. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3042. $output .= "</form>\n";
  3043. $output .= '</td></tr></table>' . "\n";
  3044. $output .= $OUTPUT->box_end();
  3045. $output .= $OUTPUT->footer();
  3046. print $output;
  3047. } // function delete($return)
  3048. /// Function for confirm the delete of activity
  3049. // @param String $return Url of return
  3050. // @param Object $iassign Object content an activity
  3051. function deleteyes ($return, $iassign) {
  3052. global $USER, $CFG, $DB, $OUTPUT;
  3053. $msg = '';
  3054. if (!empty($this->activity->id)) {
  3055. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3056. if ($iassign_submission_currents) {
  3057. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3058. foreach ($iassign_submission_currents as $iassign_submission)
  3059. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3060. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3061. } // if ($iassign_submission_currents)
  3062. }
  3063. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3064. $this->delete_calendar($this->activity->id);
  3065. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3066. iassign::update_grade_iassign($this->activity->iassignid);
  3067. if ($delete_iassign_current) {
  3068. $iassign->return_home_course('confirm_delete_iassign');
  3069. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3070. } else {
  3071. $iassign->return_home_course('error_confirm_delete_iassign');
  3072. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3073. }
  3074. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3075. }
  3076. }
  3077. /// Changes position within of interactive group activity
  3078. function move_iassign ($target, $return) {
  3079. global $DB, $OUTPUT;
  3080. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target));
  3081. $aux = $this->activity->position;
  3082. $newentry = new stdClass();
  3083. $newentry->id = $this->activity->id;
  3084. $newentry->position = $iassign_target->position;
  3085. if (!$DB->update_record('iassign_statement', $newentry)) {
  3086. print_error('error_update_move_iassign', 'iassign');
  3087. }
  3088. $newentry->id = $iassign_target->id;
  3089. $newentry->position = $aux;
  3090. if (!$DB->update_record('iassign_statement', $newentry))
  3091. print_error('error_update_move_iassign', 'iassign');
  3092. redirect($return);
  3093. }
  3094. /// Enable or disable the display of interactive activities
  3095. function visible_iassign ($return) {
  3096. global $DB;
  3097. $newentry = new stdClass();
  3098. $newentry->id = $this->activity->id;
  3099. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3100. if (!$DB->update_record('iassign_statement', $newentry))
  3101. print_error('error_update_visible_iassign', 'iassign');
  3102. redirect($return);
  3103. }
  3104. /// Add news interactive activities
  3105. function new_iassign ($param) {
  3106. global $DB;
  3107. $newentry = new stdClass();
  3108. $newentry->iassignid = $param->iassignid;
  3109. $newentry->name = $param->name;
  3110. $newentry->type_iassign = $param->type_iassign;
  3111. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3112. $proposition = $param->proposition;
  3113. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3114. else $proposition_text = $proposition;
  3115. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3116. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3117. //TODO Then get it directly from the form data $_POST!
  3118. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3119. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3120. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3121. $newentry->author_name = $param->author_name;
  3122. $newentry->author_modified_name = $param->author_modified_name;
  3123. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3124. $newentry->file = $param->file;
  3125. $newentry->grade = $param->grade;
  3126. $newentry->timemodified = time();
  3127. $newentry->timecreated = time();
  3128. if ($param->type_iassign == 1) {
  3129. $newentry->timedue = 0;
  3130. $newentry->timeavailable = 0;
  3131. } // if ($param->type_iassign == 1)
  3132. else {
  3133. $newentry->timedue = $param->timedue;
  3134. $newentry->timeavailable = $param->timeavailable;
  3135. }
  3136. $newentry->preventlate = $param->preventlate;
  3137. $newentry->test = $param->test;
  3138. $newentry->special_param1 = $param->special_param1;
  3139. $newentry->visible = $param->visible;
  3140. $newentry->position = $param->position;
  3141. $newentry->max_experiment = $param->max_experiment;
  3142. $newentry->dependency = $param->dependency;
  3143. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3144. $newentry->show_answer = $param->show_answer;
  3145. $id = $DB->insert_record("iassign_statement", $newentry);
  3146. if ($id) {
  3147. $component = 'mod_iassign';
  3148. $filearea = 'exercise';
  3149. $fs = get_file_storage();
  3150. $file = $fs->get_file_by_id($param->file);
  3151. $itemid = $file->get_itemid() + $id;
  3152. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3153. $updateentry = new stdClass();
  3154. $updateentry->id = $id;
  3155. $updateentry->file = $newfile->get_itemid();
  3156. if (!$DB->update_record("iassign_statement", $updateentry))
  3157. print_error('error_add', 'iassign');
  3158. if ($param->type_iassign == 3)
  3159. iassign::update_grade_iassign($param->iassignid);
  3160. //TODO iLM_HTML5 :: //MOOC2014
  3161. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3162. //D if ($iassign_ilm_configs) {
  3163. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3164. //D if ($iassign_ilm_config->param_type != 'static') {
  3165. //D $newentry = new stdClass();
  3166. //D $newentry->iassign_statementid = $id;
  3167. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3168. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3169. //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});
  3170. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3171. //D print_error('error_add_param', 'iassign');
  3172. //D }
  3173. //D }
  3174. //D }
  3175. // log event --------------------------------------------------------------------------------------
  3176. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3177. // log event --------------------------------------------------------------------------------------
  3178. return $id;
  3179. }
  3180. else
  3181. print_error('error_add', 'iassign');
  3182. } // function new_iassign($param)
  3183. /// Add the calendar entries for this iassign
  3184. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3185. // @return bool
  3186. static function add_calendar ($iassignid) {
  3187. global $DB, $CFG;
  3188. require_once($CFG->dirroot . '/calendar/lib.php');
  3189. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3190. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3191. $event = new stdClass();
  3192. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3193. $event->description = $iassign_statement_activity_item->name;
  3194. $event->courseid = $iassign->course;
  3195. $event->groupid = 0;
  3196. $event->userid = 0;
  3197. $event->modulename = 'iassign';
  3198. $event->instance = $iassign->id;
  3199. $event->eventtype = 'due';
  3200. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3201. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3202. calendar_event::create($event);
  3203. }
  3204. /// Update the calendar entries for this iassign
  3205. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3206. // @return bool
  3207. function update_calendar ($iassignid, $olddescription) {
  3208. global $DB, $CFG;
  3209. require_once($CFG->dirroot . '/calendar/lib.php');
  3210. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3211. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3212. $event = new stdClass();
  3213. $event->id = 0;
  3214. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3215. if ($events) {
  3216. foreach ($events as $value) {
  3217. if ($value->description == $olddescription) {
  3218. $event->id = $value->id;
  3219. }
  3220. }
  3221. }
  3222. if ($event->id != 0) {
  3223. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3224. $event->description = $iassign_statement_activity_item->name;
  3225. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3226. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3227. $calendarevent = calendar_event::load($event->id);
  3228. $calendarevent->update($event);
  3229. } else
  3230. $this->add_calendar($iassignid);
  3231. }
  3232. /// Update the calendar entries for this iassign
  3233. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3234. // @return bool
  3235. function delete_calendar ($iassignid) {
  3236. global $DB, $CFG;
  3237. require_once($CFG->dirroot . '/calendar/lib.php');
  3238. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3239. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3240. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3241. if ($events) {
  3242. foreach ($events as $value) {
  3243. if ($value->description == $iassign_statement_activity_item->name) {
  3244. $DB->delete_records('event', array('id' => $value->id));
  3245. }
  3246. }
  3247. }
  3248. }
  3249. /// Update interactive activities
  3250. function update_iassign ($param) {
  3251. global $DB;
  3252. $component = 'mod_iassign';
  3253. $filearea = 'exercise';
  3254. $fs = get_file_storage();
  3255. $file = $fs->get_file_by_id($param->file);
  3256. $fileold = $fs->get_file_by_id($param->fileold);
  3257. if ($param->file != $param->fileold) {
  3258. if ($fileold) {
  3259. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3260. foreach ($fileoldarea as $value) {
  3261. $value->delete();
  3262. }
  3263. }
  3264. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3265. $itemid = $file->get_itemid() + $param->iassign_id;
  3266. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3267. $param->file = $newfile->get_itemid();
  3268. } else
  3269. $param->file = $file->get_itemid();
  3270. } else {
  3271. $param->file = $file->get_itemid();
  3272. }
  3273. $newentry = new stdClass();
  3274. $newentry->id = $param->iassign_id;
  3275. $newentry->name = $param->name;
  3276. $newentry->type_iassign = $param->type_iassign;
  3277. //2019 $newentry->proposition = $param->proposition;
  3278. $proposition = $param->proposition;
  3279. if (is_array($proposition))
  3280. $proposition_text = $proposition['text'];
  3281. else
  3282. $proposition_text = $proposition;
  3283. $newentry->proposition = $proposition_text;
  3284. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3285. $newentry->file = $param->file;
  3286. $newentry->grade = $param->grade;
  3287. $newentry->author_modified_name = $param->author_modified_name;
  3288. $newentry->timemodified = time();
  3289. if ($param->type_iassign == 1) {
  3290. $newentry->timedue = 0;
  3291. $newentry->timeavailable = 0;
  3292. } // if ($param->type_iassign == 1)
  3293. else {
  3294. $newentry->timedue = $param->timedue;
  3295. $newentry->timeavailable = $param->timeavailable;
  3296. }
  3297. $newentry->preventlate = $param->preventlate;
  3298. $newentry->test = $param->test;
  3299. $newentry->special_param1 = $param->special_param1;
  3300. $newentry->visible = $param->visible;
  3301. $newentry->max_experiment = $param->max_experiment;
  3302. $newentry->dependency = $param->dependency;
  3303. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3304. $newentry->show_answer = $param->show_answer;
  3305. if (!$DB->update_record("iassign_statement", $newentry))
  3306. print_error('error_update', 'iassign');
  3307. if ($param->type_iassign == 3) {
  3308. iassign::update_grade_iassign($param->iassignid);
  3309. }
  3310. //$id = $newentry->id; // MOOC 2016 --- inicio
  3311. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3312. //if ($iassign_activity_item_configs) {
  3313. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3314. // $newentry = new stdClass();
  3315. // $newentry->id = $iassign_activity_item_config->id;
  3316. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3317. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3318. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3319. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3320. // print_error('error_edit_param', 'iassign');
  3321. // }
  3322. // } // MOOC 2016 --- final
  3323. // log event --------------------------------------------------------------------------------------
  3324. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3325. // log event --------------------------------------------------------------------------------------
  3326. return $newentry->id;
  3327. // if ($param->type_iassign==3)
  3328. // $this->update_grade_iassign($param->iassignid);
  3329. } // function update_iassign($param)
  3330. /// Show information of activity
  3331. function show_info_iassign () {
  3332. global $DB, $OUTPUT;
  3333. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3334. if ($this->activity->type_iassign == 3) {
  3335. if ($this->activity->dependency == 0) {
  3336. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3337. } else {
  3338. $dependencys = explode(';', $this->activity->dependency);
  3339. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3340. foreach ($dependencys as $dependency) {
  3341. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3342. if ($dependencyiassign)
  3343. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3344. } // foreach ($dependencys as $dependency)
  3345. } // if ($iassign_statement_activity_item->dependency == 0)
  3346. if ($this->activity->max_experiment == 0)
  3347. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3348. else
  3349. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3350. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3351. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3352. print $OUTPUT->box($output);
  3353. } // function show_info_iassign()
  3354. /// Shows date of opening and closing activities
  3355. function view_dates () {
  3356. global $USER, $CFG, $DB, $OUTPUT;
  3357. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3358. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3359. $status_iassign = "";
  3360. $status_iassign1 = "";
  3361. $status_iassign2 = "";
  3362. if ($this->activity->type_iassign == 1) // activity of type example
  3363. $type_iassign = get_string('example_iassign', 'iassign');
  3364. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3365. $type_iassign = get_string('test_iassign', 'iassign');
  3366. if ($this->activity->timeavailable > time()) {
  3367. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3368. } elseif ($this->activity->timedue < time()) {
  3369. $status_iassign = get_string('last_timedue', 'iassign');
  3370. }
  3371. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3372. $type_iassign = get_string('exercise_iassign', 'iassign');
  3373. if ($this->activity->timeavailable > time()) {
  3374. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3375. } elseif ($this->activity->timedue < time()) { // after delivery
  3376. $status_iassign = get_string('last_timedue', 'iassign');
  3377. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3378. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3379. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3380. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3381. if ($this->activity->test == 1) // allowed to test after of deadline
  3382. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3383. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3384. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3385. } // elseif ($iassign_statement_activity_item->test == 0)
  3386. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3387. } // elseif ($iassign_statement_activity_item->timedue < time())
  3388. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3389. $output = '<table width=100% >' . "\n";
  3390. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3391. $output .= '<tr>' . "\n";
  3392. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3393. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3394. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3395. // leo $output .= '<td width=80%>' . $type_iassign;
  3396. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3397. // $output .= '</td>' . "\n";
  3398. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3399. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3400. $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>";
  3401. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3402. } else {
  3403. $link_next = "";
  3404. $link_previous = "";
  3405. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3406. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3407. // previous_activity
  3408. if ($iassign_previous) {
  3409. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3410. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3411. } // next_activity
  3412. if ($iassign_next) {
  3413. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3414. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3415. }
  3416. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3417. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3418. $output .= '</tr></table>' . "\n";
  3419. $output .= '<table width=100% >' . "\n";
  3420. if ($this->activity->type_iassign > 1) {
  3421. if ($this->activity->timeavailable)
  3422. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3423. if ($this->activity->timedue)
  3424. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3425. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3426. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3427. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3428. $output .= '</table>' . "\n";
  3429. print $OUTPUT->box($output);
  3430. } // function view_dates()
  3431. } // class activity
  3432. /// Class to manage Interactive Learning Module (iLM)
  3433. class ilm {
  3434. var $ilm;
  3435. /// Constructor of class
  3436. // @param int $id Id of iLM
  3437. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3438. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3439. function __construct ($id) {
  3440. global $DB;
  3441. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3442. if (empty($this->ilm))
  3443. $this->ilm = null;
  3444. }
  3445. /// Shows activity in iLM
  3446. // @calledby view_iassign_current()
  3447. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3448. global $USER, $CFG, $DB;
  3449. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3450. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3451. $typec = strtolower($iassign_ilm->type);
  3452. require_once 'ilm_handlers/' . $typec . '.php';
  3453. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3454. return $retorno;
  3455. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3456. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3457. // @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);
  3458. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3459. // @param Object $file File in use in activity
  3460. // @return int Return the id of log
  3461. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3462. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3463. $newentry = new stdClass();
  3464. $newentry->iassign_statementid = $iassign_activity_itemid;
  3465. $newentry->userid = $USER->id;
  3466. $newentry->file = $content_or_id_from_ilm_security;
  3467. $newentry->timecreated = time();
  3468. $newentry->view = 1;
  3469. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3470. if (!$id_iLM_security) {
  3471. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3472. } // from (!$DB->insert_record("iassign_security", $newentry))
  3473. return $id_iLM_security;
  3474. }
  3475. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3476. // @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);
  3477. // @param int $userid
  3478. // @param int $iassign_activity_itemid Id of iassign statement
  3479. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3480. global $DB;
  3481. // 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")
  3482. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3483. }
  3484. } // class ilm
  3485. /// Class to manage settings of iLM.
  3486. class ilm_settings {
  3487. /// Function to prepare tag to load iLM (that is stored in Moodle filesystem - usually /var/moodledata/filedir/).
  3488. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3489. // @param int $ilm_id Id of iLM
  3490. // @param array $options An array with options for create dynamic tag html APPLET
  3491. // @return string Return with a tag html APPLET created
  3492. static function build_ilm_tags ($ilm_id, $options = array()) {
  3493. global $DB;
  3494. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3495. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3496. $typec = strtolower($iassign_ilm->type);
  3497. require_once 'ilm_handlers/' . $typec . '.php';
  3498. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3499. return $retorno;
  3500. } // static function build_ilm_tags($ilm_id, $options = array())
  3501. /// Function for get modified date of iLM file
  3502. // @param string $file_jar String with Ids of iLM files
  3503. // @return string Return with the filenames and modified date
  3504. static function applet_filetime ($file_jar) {
  3505. $filetime = "";
  3506. $fs = get_file_storage();
  3507. $files_jar = explode(",", $file_jar);
  3508. foreach ($files_jar as $one_file) {
  3509. $file = $fs->get_file_by_id($one_file);
  3510. if ($file)
  3511. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3512. }
  3513. return $filetime;
  3514. }
  3515. /// Function for verify an default applet
  3516. // @param String $file_jar String containing an list de ids of applet files
  3517. // @return boolean Return true or fale if applet is default
  3518. static function applet_default ($file_jar) {
  3519. $is_default = true;
  3520. $fs = get_file_storage();
  3521. $files_jar = explode(",", $file_jar);
  3522. foreach ($files_jar as $one_file) {
  3523. $file = $fs->get_file_by_id($one_file);
  3524. if ($file)
  3525. $is_default &= ($file->get_itemid() == 0);
  3526. }
  3527. return $is_default;
  3528. }
  3529. /// Function for get form variables for add, edit, or copy iLM
  3530. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  3531. // @see settings_form.php
  3532. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  3533. // @param int $ilm_id Id of iLM
  3534. // @param string $action String with the action
  3535. // @return object Return an object with forms variables
  3536. static function add_edit_copy_ilm ($ilm_id, $action) {
  3537. global $USER, $DB, $CFG;
  3538. require_once('settings_form.php'); // put the form
  3539. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3540. $param = new stdClass();
  3541. $param->action = $action;
  3542. $param->ilm_id = $ilm_id;
  3543. $CFG->action_ilm = $action;
  3544. $CFG->ilm_id = $ilm_id;
  3545. if ($action == 'add') {
  3546. $param->title = get_string('add_ilm', 'iassign');
  3547. $param->name = "";
  3548. $param->version = "";
  3549. $param->url = "";
  3550. $param->description = "";
  3551. $param->extension = "";
  3552. $param->author = $USER->id;
  3553. $param->file_jar = "";
  3554. $param->file_jar_static = "";
  3555. $param->file_class = "";
  3556. $param->width = 800;
  3557. $param->height = 600;
  3558. $param->enable = 0; // 0 - hide / 1 - show
  3559. $param->timecreated = time();
  3560. $param->timemodified = time();
  3561. $param->evaluate = 0;
  3562. $param->parent = 0;
  3563. }
  3564. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  3565. if ($iassign_ilm) {
  3566. $description = json_decode($iassign_ilm->description);
  3567. $param->title = get_string('edit_ilm', 'iassign');
  3568. $param->id = $iassign_ilm->id;
  3569. $param->name_ilm = $iassign_ilm->name;
  3570. $param->name = $iassign_ilm->name;
  3571. $param->version = $iassign_ilm->version;
  3572. $param->ilm_type = $iassign_ilm->type;
  3573. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3574. $param->url = $iassign_ilm->url;
  3575. $param->description = $description->{current_language()};
  3576. $param->description_lang = $iassign_ilm->description;
  3577. $param->extension = $iassign_ilm->extension;
  3578. $param->author = $iassign_ilm->author;
  3579. $param->file_jar = $iassign_ilm->file_jar;
  3580. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  3581. $param->file_class = $iassign_ilm->file_class;
  3582. $param->width = $iassign_ilm->width;
  3583. $param->height = $iassign_ilm->height;
  3584. $param->enable = $iassign_ilm->enable;
  3585. $param->timecreated = $iassign_ilm->timecreated;
  3586. $param->timemodified = time();
  3587. $param->evaluate = $iassign_ilm->evaluate;
  3588. $param->parent = $iassign_ilm->parent;
  3589. }
  3590. }
  3591. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  3592. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  3593. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3594. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  3595. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  3596. // echo "Sem dados<br/>"; exit;
  3597. return;
  3598. }
  3599. $description = json_decode($iassign_ilm->description);
  3600. if ($iassign_ilm) {
  3601. if ($iassign_ilm->parent == 0)
  3602. $iassign_ilm->parent = $ilm_id;
  3603. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  3604. $param->title = get_string('new_version_ilm', 'iassign');
  3605. $param->name_ilm = $iassign_ilm->name;
  3606. $param->name = $iassign_ilm->name;
  3607. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  3608. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  3609. $param->version = $iassign_ilm->version; // do not erase field 'version'
  3610. $param->ilm_type = $iassign_ilm->type;
  3611. $param->url = $iassign_ilm->url;
  3612. $param->description = $description->{current_language()};
  3613. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  3614. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3615. $param->extension = $iassign_ilm->extension;
  3616. $param->author = $USER->id;
  3617. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  3618. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  3619. $param->file_jar_static = '';
  3620. $param->file_class = $iassign_ilm->file_class;
  3621. $param->width = $iassign_ilm->width;
  3622. $param->height = $iassign_ilm->height;
  3623. $param->enable = 0;
  3624. $param->timecreated = time();
  3625. $param->timemodified = time();
  3626. $param->evaluate = $iassign_ilm->evaluate;
  3627. $param->parent = $iassign_ilm->parent;
  3628. }
  3629. }
  3630. elseif ($action == 'copy') {
  3631. $description = json_decode($iassign_ilm->description);
  3632. if ($iassign_ilm) {
  3633. if ($iassign_ilm->parent == 0)
  3634. $iassign_ilm->parent = $ilm_id;
  3635. $param->title = get_string('copy_ilm', 'iassign');
  3636. $param->id = $iassign_ilm->id;
  3637. $param->name_ilm = $iassign_ilm->name;
  3638. $param->name = $iassign_ilm->name;
  3639. $param->version = "";
  3640. $param->ilm_type = $iassign_ilm->type;
  3641. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  3642. $param->url = $iassign_ilm->url;
  3643. $param->description = $description->{current_language()};
  3644. $param->description_lang = $iassign_ilm->description;
  3645. $param->extension = $iassign_ilm->extension;
  3646. $param->author = $USER->id;
  3647. $param->file_jar = '';
  3648. $param->file_jar_static = '';
  3649. $param->file_class = $iassign_ilm->file_class;
  3650. $param->width = $iassign_ilm->width;
  3651. $param->height = $iassign_ilm->height;
  3652. $param->enable = 0;
  3653. $param->timecreated = time();
  3654. $param->timemodified = time();
  3655. $param->evaluate = $iassign_ilm->evaluate;
  3656. $param->parent = $iassign_ilm->parent;
  3657. }
  3658. }
  3659. return $param;
  3660. } // static function add_edit_copy_ilm($ilm_id, $action)
  3661. /// Function for save iLM file in moodledata
  3662. // @param int $itemid Itemid of file save in draft (upload file)
  3663. // @param int $ilm_id Id of iLM
  3664. // @return string Return an string with ids of iLM files
  3665. static function new_file_ilm ($itemid, $iassign_ilm) {
  3666. global $CFG, $USER, $DB;
  3667. $return = null;
  3668. $file_jar = array();
  3669. $fs = get_file_storage();
  3670. $contextuser = context_user::instance($USER->id);
  3671. $contextsystem = context_system::instance();
  3672. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  3673. if ($files_ilm) {
  3674. foreach ($files_ilm as $value) {
  3675. // VERIFICA SE e' DO TIPO HTML5
  3676. if ($iassign_ilm->type == 1) {
  3677. // Verifica a extensão do arquivo iLM para verificar se é ZIP
  3678. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  3679. // CASO SEJA ZIP: COPIA O ARQUIVO, PARA O ilm_debug E DESCOMPACTA no diretorio 'ilm'
  3680. if ((strtolower($ext) == 'zip')) {
  3681. // COPIA:
  3682. $destination = 'ilm_debug/' . $value->get_filename();
  3683. $value->copy_content_to($destination);
  3684. // EXTRAIR CONTEUDO:
  3685. $zip = new ZipArchive();
  3686. $extracted = './ilm';
  3687. $dir = "";
  3688. if ($zip->open($destination) === TRUE) {
  3689. $dir = './ilm/' . trim($zip->getNameIndex(0));
  3690. if (is_dir($dir)) {
  3691. $i = 1;
  3692. $previous = str_replace("/", "", $zip->getNameIndex(0));
  3693. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  3694. $i ++;
  3695. }
  3696. $name = $previous . "_" . $i;
  3697. $dir = './ilm/' . $name . "/";
  3698. $j = 0;
  3699. while ($item_name = $zip->getNameIndex($j)) {
  3700. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  3701. $j++;
  3702. }
  3703. $zip->close();
  3704. }
  3705. $zip->open($destination);
  3706. $zip->extractTo($extracted);
  3707. $zip->close();
  3708. // Apos extrair, remover do DEBUG:
  3709. unlink($destination);
  3710. } else {
  3711. // APÓS NAO CONSEGUIR EXTRAIR, apagar O ZIP:
  3712. unlink($destination);
  3713. print_error('error_add_ilm_zip', 'iassign');
  3714. }
  3715. return $dir;
  3716. }
  3717. }
  3718. if ($value->get_filename() != '.') {
  3719. $file_ilm = array(
  3720. 'userid' => $USER->id,
  3721. 'contextid' => $contextsystem->id,
  3722. 'component' => 'mod_iassign',
  3723. 'filearea' => 'ilm',
  3724. 'itemid' => rand(1, 999999999),
  3725. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  3726. 'filename' => $value->get_filename());
  3727. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  3728. array_push($file_jar, $file_ilm->get_id());
  3729. }
  3730. }
  3731. if (!empty($file_jar)) {
  3732. $return = implode(",", $file_jar);
  3733. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  3734. foreach ($old_file_jar as $value) {
  3735. $file = $fs->get_file_by_id($value);
  3736. if ($file)
  3737. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  3738. }
  3739. }
  3740. } else
  3741. $return = $iassign_ilm->file_jar;
  3742. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  3743. return $return;
  3744. } // static function new_file_ilm($itemid, $iassign_ilm)
  3745. /// Function for save in database an new iLM
  3746. // @param object $param An object with iLM params
  3747. static function new_ilm ($itemid) {
  3748. global $CFG, $USER, $OUTPUT;
  3749. // Verifica se existe algum XML anterior na pasta temp e o exclui
  3750. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  3751. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  3752. }
  3753. $pathtemp = $CFG->dataroot . '/temp/';
  3754. $contextuser = context_user::instance($USER->id);
  3755. $fs = get_file_storage();
  3756. $zip = new zip_packer();
  3757. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3758. foreach ($files as $file) {
  3759. if (!$file->is_directory())
  3760. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3761. }
  3762. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  3763. // Verifica se o pacote possui o XML
  3764. if (!$application_xml) {
  3765. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  3766. return;
  3767. } else {
  3768. $missing = "";
  3769. if (!isset($application_xml->name)) {
  3770. $missing .= "name";
  3771. }
  3772. if (!isset($application_xml->version)) {
  3773. $missing .= ", version";
  3774. }
  3775. if (!isset($application_xml->type)) {
  3776. $missing .= ", type";
  3777. }
  3778. if (!isset($application_xml->extension)) {
  3779. $missing .= ", extension";
  3780. }
  3781. if (!isset($application_xml->file_jar)) {
  3782. $missing .= ", file_jar";
  3783. }
  3784. if (!isset($application_xml->file_class)) {
  3785. $missing .= ", file_class";
  3786. }
  3787. if (!isset($application_xml->width)) {
  3788. $missing .= ", width";
  3789. }
  3790. if (!isset($application_xml->height)) {
  3791. $missing .= ", height";
  3792. }
  3793. if (!isset($application_xml->evaluate)) {
  3794. $missing .= ", evaluate";
  3795. }
  3796. if (strlen($missing) > 2) {
  3797. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  3798. return;
  3799. }
  3800. }
  3801. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3802. $typec = strtolower($application_xml->type);
  3803. require_once 'ilm_handlers/' . $typec . '.php';
  3804. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  3805. return $retorno;
  3806. } // static function new_ilm($itemid)
  3807. /// Function for save in database an iLM edit
  3808. // @param object $param An object with iLM params
  3809. static function edit_ilm ($param, $itemid) {
  3810. // Descobrir o tipo de iLM:
  3811. global $DB, $USER, $CFG;
  3812. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  3813. $pathtemp = $CFG->dataroot . '/temp/';
  3814. $contextuser = context_user::instance($USER->id);
  3815. $fs = get_file_storage();
  3816. $zip = new zip_packer();
  3817. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3818. $files_extract = null;
  3819. foreach ($files as $file) {
  3820. if (!$file->is_directory())
  3821. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3822. }
  3823. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  3824. $typec = strtolower($iassign_t->type);
  3825. require_once 'ilm_handlers/' . $typec . '.php';
  3826. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  3827. }
  3828. /// Function for register the new iLM (in database and in the directory)
  3829. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  3830. // @param object $param An object with iLM params
  3831. static function copy_new_version_ilm ($param) {
  3832. global $DB, $CFG, $USER;
  3833. $itemid = $param->file;
  3834. $pathtemp = $CFG->dataroot . '/temp/';
  3835. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  3836. //D echo "pathtemp=$pathtemp<br/>";
  3837. $contextuser = context_user::instance($USER->id);
  3838. $fs = get_file_storage();
  3839. $zip = new zip_packer();
  3840. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  3841. $files_extract = null;
  3842. foreach ($files as $file) {
  3843. if (!$file->is_directory())
  3844. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  3845. }
  3846. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3847. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  3848. $typec = strtolower($iassign_t->type);
  3849. require_once 'ilm_handlers/' . $typec . '.php';
  3850. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  3851. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  3852. } // static function copy_new_version_ilm($param)
  3853. //VER::
  3854. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  3855. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  3856. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  3857. /// Function for change visibility of iLM
  3858. // @param int $ilm_id Id of iLM
  3859. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  3860. static function visible_ilm ($ilm_id, $status) {
  3861. global $DB;
  3862. if ($status == 0)
  3863. $visible = 1;
  3864. else
  3865. $visible = 0;
  3866. $newentry = new stdClass();
  3867. $newentry->id = $ilm_id;
  3868. $newentry->enable = $visible;
  3869. if (!$DB->update_record("iassign_ilm", $newentry))
  3870. error(get_string('error_edit_ilm', 'iassign'));
  3871. }
  3872. /// Function for confirm change default iLM
  3873. // @param int $ilm_id Id of iLM
  3874. // @param int $ilm_parent Id of parent iLM
  3875. // @return string Return with an string for create default page confirmation
  3876. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  3877. global $OUTPUT, $DB;
  3878. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3879. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3880. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3881. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  3882. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  3883. return $return;
  3884. }
  3885. /// Function for change the default iLM
  3886. // @see settings_ilm.php
  3887. // @param int $ilm_id Id of iLM
  3888. // @return int Return Id of default iLM
  3889. static function default_ilm ($ilm_id) {
  3890. global $DB;
  3891. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  3892. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  3893. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  3894. $iassign_ilm_default->id = $iassign_ilm->id;
  3895. $iassign_ilm_default->parent = 0;
  3896. $iassign_ilm->parent = $iassign_ilm_default->id;
  3897. $iassign_ilm->id = 0;
  3898. $iassign_ilm_default->enable = 1;
  3899. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  3900. print_error('error_edit_ilm', 'iassign');
  3901. }
  3902. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  3903. if (!$inserted) {
  3904. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  3905. print_error($msg_error);
  3906. //xx print_error('error_add_ilm', 'iassign');
  3907. }
  3908. return $iassign_ilm_default->id;
  3909. } // static function default_ilm ($ilm_id)
  3910. /// Function for confirm delete iLM
  3911. // @param int $ilm_id Id of iLM
  3912. // @param int $ilm_parent Id of parent iLM
  3913. // @return string Return with an string for create delete page confirmation
  3914. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  3915. global $OUTPUT, $DB;
  3916. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3917. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  3918. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  3919. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  3920. }
  3921. /// Function for delete directory where the iLM is allocated.
  3922. // @param string $dirPath
  3923. // @throws InvalidArgumentException
  3924. public static function delete_dir ($dirPath) {
  3925. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  3926. $dirPath .= '/';
  3927. }
  3928. $files = glob($dirPath . '*', GLOB_MARK);
  3929. foreach ($files as $file) {
  3930. if (is_dir($file)) {
  3931. ilm_settings::delete_dir($file);
  3932. } else {
  3933. unlink($file);
  3934. }
  3935. }
  3936. rmdir($dirPath);
  3937. }
  3938. /// Function for delete iLM
  3939. // @param int $ilm_id Id of iLM
  3940. // @return int Return Id of parent iLM
  3941. static function delete_ilm ($ilm_id) {
  3942. global $DB;
  3943. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3944. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3945. $typec = strtolower($iassign_ilm->type);
  3946. require_once 'ilm_handlers/' . $typec . '.php';
  3947. $retorno = $typec::delete_ilm($ilm_id);
  3948. return $retorno;
  3949. }
  3950. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  3951. // @param int $ilm_id Id of iLM
  3952. static function export_ilm ($ilm_id) {
  3953. global $DB;
  3954. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3955. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3956. $typec = strtolower($iassign_ilm->type);
  3957. require_once 'ilm_handlers/' . $typec . '.php';
  3958. $typec::export_ilm($ilm_id);
  3959. } // static function export_ilm($ilm_id)
  3960. //TODO iLM_HTML5 :: //MOOC 2016
  3961. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  3962. // @param int $ilm_id Id of iLM
  3963. static function export_update_ilm ($ilm_id) {
  3964. global $DB, $CFG;
  3965. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3966. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  3967. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  3968. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  3969. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  3970. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  3971. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  3972. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  3973. $upgrade_descriptor .= '</upgrade>' . "\n";
  3974. file_put_contents($xml_filename, $upgrade_descriptor);
  3975. header("Pragma: public");
  3976. header("Expires: 0");
  3977. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  3978. header("Cache-Control: private", false);
  3979. header('Content-Type: application/xml; charset=utf-8');
  3980. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  3981. header("Content-Length: " . @filesize($xml_filename));
  3982. set_time_limit(0);
  3983. @readfile("$xml_filename") || die("File not found.");
  3984. unlink($xml_filename);
  3985. exit;
  3986. } // static function export_update_ilm($ilm_id) //MOOC 2016
  3987. /// Function for save iLM from XML descriptor
  3988. // @param array $application_xml Data of XML descriptor
  3989. // @param array $files_extract Filenames of extract files
  3990. // @return array Return an array content id of JAR files
  3991. static function save_ilm_by_xml ($application_xml, $files_extract) {
  3992. global $CFG, $USER;
  3993. // Tratamento diferenciado se for do tipo HTML5:
  3994. $source = "";
  3995. $diretorio = "";
  3996. if (strtolower($application_xml->type) == 'html5') {
  3997. $i = 0;
  3998. foreach ($files_extract as $key => $value) {
  3999. $file = $CFG->dataroot . '/temp/' . $key;
  4000. // Verifica se já existe a pasta no diretório dos iLM:
  4001. if ($i == 0) {
  4002. $source = $file;
  4003. if (file_exists("ilm/" . basename($file))) {
  4004. $j = 1;
  4005. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4006. $j ++;
  4007. }
  4008. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4009. // mkdir($diretorio, 0777, true);
  4010. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4011. }
  4012. else {
  4013. $diretorio = 'ilm/' . basename($file);
  4014. // mkdir($diretorio, 0777, true);
  4015. mkdir($diretorio, 0755, true);
  4016. }
  4017. break;
  4018. }
  4019. $i ++;
  4020. }
  4021. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4022. if ($item->isDir()) {
  4023. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4024. }
  4025. else {
  4026. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4027. }
  4028. }
  4029. ilm_settings::delete_dir($source);
  4030. return "./" . $diretorio;
  4031. }
  4032. $fs = get_file_storage();
  4033. $file_jar = array();
  4034. $files_ilm = explode(",", $application_xml->file_jar);
  4035. $contextsystem = context_system::instance();
  4036. foreach ($files_ilm as $value) {
  4037. $file_ilm = array(
  4038. 'userid' => $USER->id,
  4039. 'contextid' => $contextsystem->id,
  4040. 'component' => 'mod_iassign',
  4041. 'filearea' => 'ilm',
  4042. 'itemid' => rand(1, 999999999),
  4043. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4044. 'filename' => $value);
  4045. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4046. array_push($file_jar, $file_ilm->get_id());
  4047. }
  4048. foreach ($files_extract as $key => $value) {
  4049. $file = $CFG->dataroot . '/temp/' . $key;
  4050. if (file_exists($file))
  4051. unlink($file);
  4052. }
  4053. return $file_jar;
  4054. }
  4055. /// Function for import the iLM from an package
  4056. // @param int $itemid Itemid of zip file
  4057. static function import_ilm ($itemid) {
  4058. global $CFG, $USER, $OUTPUT;
  4059. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4060. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4061. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4062. }
  4063. $pathtemp = $CFG->dataroot . '/temp/';
  4064. $contextuser = context_user::instance($USER->id);
  4065. $fs = get_file_storage();
  4066. $zip = new zip_packer();
  4067. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4068. foreach ($files as $file) {
  4069. if (!$file->is_directory())
  4070. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4071. }
  4072. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4073. // Verifica se o pacote possui o XML
  4074. if (!$application_xml) {
  4075. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4076. return;
  4077. } else {
  4078. $missing = "";
  4079. if (!isset($application_xml->name)) {
  4080. $missing .= "name";
  4081. }
  4082. if (!isset($application_xml->version)) {
  4083. $missing .= ", version";
  4084. }
  4085. if (!isset($application_xml->type)) {
  4086. $missing .= ", type";
  4087. }
  4088. if (!isset($application_xml->extension)) {
  4089. $missing .= ", extension";
  4090. }
  4091. if (!isset($application_xml->file_jar)) {
  4092. $missing .= ", file_jar";
  4093. }
  4094. if (!isset($application_xml->file_class)) {
  4095. $missing .= ", file_class";
  4096. }
  4097. if (!isset($application_xml->width)) {
  4098. $missing .= ", width";
  4099. }
  4100. if (!isset($application_xml->height)) {
  4101. $missing .= ", height";
  4102. }
  4103. if (!isset($application_xml->evaluate)) {
  4104. $missing .= ", evaluate";
  4105. }
  4106. if (strlen($missing) > 2) {
  4107. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4108. return;
  4109. }
  4110. }
  4111. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4112. $typec = strtolower($application_xml->type);
  4113. require_once 'ilm_handlers/' . $typec . '.php';
  4114. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4115. } // static function import_ilm($itemid)
  4116. /// Function for list iLM defaults
  4117. // @return string Return an string with a table of iLM
  4118. static function list_ilm () {
  4119. global $DB, $OUTPUT;
  4120. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4121. $str = '';
  4122. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4123. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4124. if ($iassign_ilm) {
  4125. foreach ($iassign_ilm as $ilm) {
  4126. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4127. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4128. $str .= '<tr><td>';
  4129. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4130. $str .= '<tr>';
  4131. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4132. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4133. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4134. $str .= '</tr>';
  4135. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4136. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4137. $str .= '</table>';
  4138. $str .= '</td></tr>';
  4139. }
  4140. }
  4141. $str .= '</table>';
  4142. return $str;
  4143. }
  4144. /// Function for download and install an upgrade of an iLM
  4145. // @param int $ilm_id Id of iLM
  4146. static function upgrade_ilm ($ilm_id) {
  4147. global $DB, $CFG, $USER;
  4148. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4149. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4150. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4151. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4152. if (!$result)
  4153. print_error('error_upgrade_ilm', 'iassign');
  4154. else {
  4155. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4156. $extension = explode(".", $zip_filename);
  4157. if ($extension[count($extension) - 1] != 'ipz') {
  4158. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4159. die;
  4160. }
  4161. $zip = new zip_packer();
  4162. $fs = get_file_storage();
  4163. $contextuser = context_user::instance($USER->id);
  4164. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4165. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4166. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4167. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4168. if (file_exists($zip_filename))
  4169. unlink($zip_filename);
  4170. if (empty($file_jar)) {
  4171. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4172. print_error($msg_error);
  4173. //xx print_error('error_add_ilm', 'iassign');
  4174. }
  4175. else {
  4176. $newentry = new stdClass();
  4177. $newentry->name = (String) $application_xml->name;
  4178. $newentry->version = (String) $application_xml->version;
  4179. $newentry->url = (String) $application_xml->url;
  4180. $newentry->description = $description_str;
  4181. $newentry->extension = strtolower((String) $application_xml->extension);
  4182. $newentry->file_jar = implode(",", $file_jar);
  4183. $newentry->file_class = (String) $application_xml->file_class;
  4184. $newentry->width = (String) $application_xml->width;
  4185. $newentry->height = (String) $application_xml->height;
  4186. $newentry->enable = 0;
  4187. $newentry->timemodified = time();
  4188. $newentry->author = $USER->id;
  4189. $newentry->timecreated = time();
  4190. $newentry->evaluate = (String) $application_xml->evaluate;
  4191. $newentry->parent = $ilm_id;
  4192. }
  4193. }
  4194. return $iassign_ilm->id;
  4195. } // static function upgrade_ilm($ilm_id)
  4196. //MOOC2014 -- inicio
  4197. //TODO: REVIEW
  4198. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4199. // static function move_iassign($ilm_id)
  4200. //MOOC2014 -- final
  4201. /// Function for list iLM versions with all informations
  4202. // @return string Return an string with a table of iLM
  4203. static function view_ilm ($ilmid, $from) {
  4204. global $DB;
  4205. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4206. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4207. $typec = strtolower($iassign_ilm->type);
  4208. require_once 'ilm_handlers/' . $typec . '.php';
  4209. $retorno = $typec::view_ilm($ilmid, $from);
  4210. return $retorno;
  4211. }
  4212. /// Function for get form variables for add, edit, or copy iLM params
  4213. // @param int $ilm_param_id Id of iLM param
  4214. // @param string $action String with the action
  4215. // @return object Return an object with forms variables
  4216. static function add_edit_copy_param ($ilm_param_id, $action) {
  4217. global $DB;
  4218. require_once('params_form.php');
  4219. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4220. $param = new stdClass();
  4221. $param->action = $action;
  4222. $param->ilm_param_id = $ilm_param_id;
  4223. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4224. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4225. $type = $iassign_ilm_config->param_type;
  4226. if ($action == 'add') {
  4227. $param->title = get_string('add_ilm', 'iassign');
  4228. $param->iassign_ilmid = $ilm_param_id;
  4229. $param->param_name = "";
  4230. $param->param_value = "";
  4231. $param->description = "";
  4232. $param->visible = 1;
  4233. }
  4234. elseif ($action == 'edit') {
  4235. if ($iassign_ilm_config) {
  4236. $param->title = get_string('edit_ilm', 'iassign');
  4237. $param->id = $iassign_ilm_config->id;
  4238. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4239. $param->param_type = $type; //MOOC2014
  4240. $param->param_name = $iassign_ilm_config->param_name;
  4241. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4242. $param->param_value = $iassign_ilm_config->param_value;
  4243. else //MOOC2014
  4244. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4245. $param->param_value = $iassign_ilm_config->param_value;
  4246. $param->description = $iassign_ilm_config->description;
  4247. $param->visible = $iassign_ilm_config->visible;
  4248. }
  4249. }
  4250. elseif ($action == 'copy') {
  4251. if ($iassign_ilm_config) {
  4252. $param->title = get_string('copy_ilm', 'iassign');
  4253. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4254. $param->param_type = $type; //MOOC2014
  4255. $param->param_name = $iassign_ilm_config->param_name;
  4256. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4257. $param->param_value = $iassign_ilm_config->param_value;
  4258. else //MOOC2014
  4259. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4260. $param->description = $iassign_ilm_config->description;
  4261. $param->visible = $iassign_ilm_config->visible;
  4262. }
  4263. }
  4264. return $param;
  4265. } // static function add_edit_copy_param($ilm_param_id, $action)
  4266. /// Function for change visibility of iLM param
  4267. // @param int $ilm_param_id Id of iLM param
  4268. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4269. static function visible_param ($ilm_param_id, $status) {
  4270. global $DB, $CFG;
  4271. if ($status == 0)
  4272. $visible = 1;
  4273. else
  4274. $visible = 0;
  4275. $newentry = new stdClass();
  4276. $newentry->id = $ilm_param_id;
  4277. $newentry->visible = $visible;
  4278. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4279. error(get_string('error_edit_param', 'iassign'));
  4280. }
  4281. /// Function for save in database an new iLM param
  4282. // @param object $param An object with iLM params
  4283. static function add_param ($param) {
  4284. global $DB;
  4285. $newentry = new stdClass();
  4286. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4287. //MOOC2014 $newentry->param_name = $param->param_name;
  4288. $newentry->param_type = $param->param_type; //MOOC2014
  4289. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4290. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4291. $newentry->param_value = $param->param_value;
  4292. else //MOOC2014
  4293. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4294. $newentry->description = $param->description;
  4295. $newentry->visible = $param->visible;
  4296. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4297. if (!$newentry->id) {
  4298. print_error('error_add_param', 'iassign');
  4299. }
  4300. }
  4301. /// Function for save in database a iLM param edit
  4302. // @param object $param An object with iLM params
  4303. static function edit_param ($param) {
  4304. global $DB;
  4305. $updentry = new stdClass();
  4306. $updentry->id = $param->id;
  4307. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4308. $updentry->param_type = $param->param_type; //MOOC2014
  4309. // $updentry->param_name = $param->param_name;
  4310. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4311. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4312. $updentry->param_value = $param->param_value;
  4313. else //MOOC2014
  4314. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4315. $updentry->description = $param->description;
  4316. $updentry->visible = $param->visible;
  4317. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4318. error(get_string('error_edit_param', 'iassign'));
  4319. }
  4320. }
  4321. /// Function for save in database a iLM param copy
  4322. // @param object $param An object with iLM params
  4323. static function copy_param ($param) {
  4324. global $DB;
  4325. $newentry = new stdClass();
  4326. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4327. //$newentry->param_name = $param->param_name;
  4328. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4329. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4330. $newentry->param_value = $param->param_value;
  4331. else //MOOC2014
  4332. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4333. $newentry->description = $param->description;
  4334. $newentry->visible = $param->visible;
  4335. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4336. if (!$newentry->id) {
  4337. print_error('error_add_param', 'iassign');
  4338. }
  4339. }
  4340. /// Function for delete iLM param of database
  4341. // @param int $param_id Id of iLM param
  4342. static function delete_param ($param_id) {
  4343. global $DB;
  4344. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4345. print_error('error_delete_param', 'iassign');
  4346. }
  4347. }
  4348. } // class ilm_settings
  4349. /// Class for manage iLM files (editor).
  4350. class ilm_manager {
  4351. var $id; // course id
  4352. var $url;
  4353. var $from;
  4354. /// Constructor for the base ilm_manager class
  4355. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4356. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4357. function __construct ($id, $url, $from) {
  4358. $this->id = $id; // course id
  4359. $this->url = $url;
  4360. $this->from = $from;
  4361. }
  4362. /// Function to get iAssign content file in Moodle data (exercise)
  4363. // @calledby x function preview_ilm($iassign_ilm) :
  4364. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4365. function get_file_ilm () {
  4366. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4367. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4368. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4369. $fs = get_file_storage();
  4370. $md_file = $fs->get_file_by_id($fileid);
  4371. $ilm_content_file = $md_file->get_content();
  4372. return $ilm_content_file;
  4373. }
  4374. /// Function for creating a new file from the iLM online editor
  4375. function ilm_editor_new () {
  4376. global $CFG, $DB, $OUTPUT, $PAGE;
  4377. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4378. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4379. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4380. $context = context_course::instance($this->id);
  4381. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4382. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4383. if (!$iassign) {
  4384. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4385. die();
  4386. }
  4387. $temp = explode(",", $iassign->extension);
  4388. $extension = $temp[0]; // default extension for this iLM
  4389. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4390. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4391. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4392. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4393. if ($stringArchiveContent != NULL) {
  4394. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4395. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4396. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4397. $filename = optional_param('filename', NULL, PARAM_RAW);
  4398. //Leo $filename = iassign_utils::format_filename($filename); //
  4399. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4400. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4401. //2019/02 $arrayfilename = explode(".", $filename);
  4402. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4403. //2019/02 $count_dots = count($arrayfilename);
  4404. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4405. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4406. //2019/02 if ($last_name != $extension)
  4407. //2019/02 $filename = $filename . '.' . $extension;
  4408. //2019/02 }
  4409. //2019/02 else { // no extension...
  4410. //2019/02 $filename = $filename . '.' . $extension;
  4411. //2019/02 }
  4412. // Store the name of recent created file
  4413. $_SESSION['file_name'] = $filename;
  4414. //$this->write_file_iassign($string, $filename);
  4415. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4416. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4417. die();
  4418. }
  4419. else { // if ($stringArchiveContent != NULL)
  4420. // iLM On-line editor
  4421. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4422. $str_get_iLM = "window.frames.iLM";
  4423. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4424. }
  4425. else { // otherwise it is JAR named 'iLM'
  4426. $str_get_iLM = "document.iLM";
  4427. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4428. }
  4429. $fs = get_file_storage();
  4430. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4431. $files_array = '';
  4432. foreach ($files as $value) {
  4433. if ($value->get_filename() != ".")
  4434. $files_array .= "'" . $value->get_filename() . "',";
  4435. }
  4436. $files_array .= "''";
  4437. $file = null;
  4438. $ia_content = "";
  4439. $filename = "";
  4440. $error_files_exists = get_string('error_file_exists', 'iassign');
  4441. $output = "<script type='text/javascript'>
  4442. //<![CDATA[
  4443. //D alert('locallib.php: ilm_editor_new');
  4444. function submit_iLM_Answer () {
  4445. var docFormOnLineEditor = document.formEnvio;
  4446. var resposta_exerc = new Array(3);
  4447. var valor_resposta = new Array(3);
  4448. var sessao = new Array(3);
  4449. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4450. resposta_exerc[0] = doc_iLM.getAnswer();
  4451. valor_resposta[0] = doc_iLM.getEvaluation();
  4452. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4453. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4454. var files = new Array(" . $files_array . ");
  4455. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4456. " .
  4457. //D alert('#files = ' + files.length);
  4458. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4459. // if (resposta_exerc[0] == -1) {
  4460. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4461. // return false;
  4462. // } else {
  4463. "
  4464. if (docFormOnLineEditor.filename.value=='') {
  4465. // ERRO: O nome do arquivo está vazio.
  4466. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4467. return false;
  4468. }
  4469. // }
  4470. for (i=0; i<files.length; i++) {
  4471. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4472. alert('" . $error_files_exists . "');
  4473. return false;
  4474. }
  4475. }
  4476. docFormOnLineEditor.submit();
  4477. return true;
  4478. }
  4479. //]]>
  4480. </script>\n";
  4481. $output .= "
  4482. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4483. $output .= $OUTPUT->box_start();
  4484. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4485. $output .= "
  4486. <table width='100%' cellpadding='20'>
  4487. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4488. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4489. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4490. </tr>
  4491. </table>\n";
  4492. $output .= $OUTPUT->box_end();
  4493. $output .= "<center>\n";
  4494. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4495. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4496. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4497. $output .= $output_ilm;
  4498. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4499. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4500. </center>
  4501. </form>\n";
  4502. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4503. $PAGE->navbar->add($title);
  4504. $PAGE->set_title($title);
  4505. $PAGE->set_heading($title); // insert title above the navigation bar
  4506. print $OUTPUT->header();
  4507. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4508. print $output;
  4509. print $OUTPUT->footer();
  4510. }
  4511. die();
  4512. } // function ilm_editor_new()
  4513. /// Function for editing an file in online editor
  4514. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  4515. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  4516. global $CFG, $DB, $OUTPUT, $PAGE;
  4517. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4518. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4519. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4520. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4521. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4522. // If iLM is not registered, error!
  4523. if (!$iassign) {
  4524. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  4525. die;
  4526. }
  4527. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  4528. //2017/03/12 $fs = get_file_storage(); // from Moodle data
  4529. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  4530. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  4531. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4532. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4533. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  4534. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  4535. if ($stringArchiveContent != NULL) {
  4536. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  4537. die();
  4538. } else { // if ($stringArchiveContent != NULL)
  4539. $end_file = '';
  4540. if ($content_file) {
  4541. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  4542. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  4543. }
  4544. $temp = explode(",", $iassign->extension);
  4545. $extension = $temp[0]; // default extension for this iLM
  4546. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  4547. $str_get_iLM = "window.frames.iLM";
  4548. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4549. } else { // otherwise it is JAR named 'iLM'
  4550. $str_get_iLM = "document.iLM";
  4551. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4552. }
  4553. $output = "<script type='text/javascript'>
  4554. //<![CDATA[
  4555. function submit_iLM_Answer () {
  4556. var docFormEditor = document.formEnvio;
  4557. var activityAnswer; // to get activity answer (text)
  4558. var activityValue; // to get activity answer value (float)
  4559. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4560. //activityAnswer = doc_iLM.getAnswer();
  4561. //activityValue = doc_iLM.getEvaluation();
  4562. activityAnswer = " . $str_get_iLM . ".getAnswer();
  4563. activityValue = " . $str_get_iLM . ".getEvaluation();
  4564. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  4565. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  4566. docFormEditor.submit();
  4567. return true;
  4568. }
  4569. //]]>
  4570. </script>\n";
  4571. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  4572. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  4573. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  4574. // return true;
  4575. // }
  4576. $output .= "
  4577. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4578. $output .= $OUTPUT->box_start();
  4579. $output .= "
  4580. <table width='100%' cellpadding='20'>
  4581. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  4582. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  4583. <input type='hidden' name='filename' value='$filename'/></td>
  4584. <td>
  4585. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4586. </tr>
  4587. </table>\n";
  4588. $output .= $OUTPUT->box_end();
  4589. $output .= " <center>\n";
  4590. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  4591. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  4592. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  4593. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  4594. </center>
  4595. </form>\n";
  4596. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4597. $PAGE->navbar->add($title);
  4598. $PAGE->set_title($title);
  4599. $PAGE->set_heading($title); // insert title above the navigation bar
  4600. print $OUTPUT->header();
  4601. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4602. print $output;
  4603. print $OUTPUT->footer();
  4604. } // else if ($stringArchiveContent != NULL)
  4605. die();
  4606. } // function ilm_editor_update()
  4607. /// Function for write iAssign file in Moodle data (exercise)
  4608. // @param string $stringArchiveContent Content of iassign file
  4609. // @param string $filename Filename of iassign file
  4610. function write_file_iassign ($stringArchiveContent, $filename) {
  4611. global $USER;
  4612. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4613. $context = context_course::instance($this->id);
  4614. $fs = get_file_storage();
  4615. $dirid = $this->get_dir_ilm('dirid');
  4616. $dir = $fs->get_file_by_id($dirid);
  4617. $fileinfo = array('contextid' => $context->id, // ID of course
  4618. 'component' => 'mod_iassign', // usually = table name
  4619. 'filearea' => 'activity', // usually = table name
  4620. 'itemid' => 0, // usually = ID of row in table
  4621. 'filepath' => $dir->get_filepath(), // any path beginning and ending whith '/'
  4622. 'userid' => $USER->id,
  4623. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4624. 'filename' => $filename); // any filename
  4625. // Create file containing text. '$stringArchiveContent'
  4626. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  4627. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  4628. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  4629. // 'Activité interactive enregistrée avec succès sous le nom:';
  4630. // 'Atividade interativa gravada com sucesso sob o nome:'
  4631. $output = "
  4632. <script type='text/javascript'>
  4633. //<![CDATA[
  4634. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  4635. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4636. //]]>
  4637. </script>";
  4638. print $output;
  4639. die();
  4640. }
  4641. /// Function for write iAssign file in Moodle data (exercise)
  4642. // @param string $stringArchiveContent Content of iassign file
  4643. // @param string $filename Filename of iassign file
  4644. // @param int $itemid Itemid of iassign file
  4645. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  4646. global $OUTPUT, $USER;
  4647. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4648. $context = context_course::instance($this->id);
  4649. $dirid = $this->get_dir_ilm('dirid');
  4650. if ($stringArchiveContent != (-1)) {
  4651. $fs = get_file_storage();
  4652. $file = $fs->get_file_by_id($fileid);
  4653. if (!$file) {
  4654. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  4655. die;
  4656. }
  4657. $fileinfo = array('contextid' => $context->id, // ID of context
  4658. 'component' => 'mod_iassign', // usually = table name
  4659. 'filearea' => 'activity', // usually = table name
  4660. 'itemid' => 0, // usually = ID of row in table
  4661. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  4662. 'userid' => $USER->id,
  4663. 'author' => $USER->firstname . ' ' . $USER->lastname,
  4664. 'license' => 'allrightsreserved', // allrightsreserved
  4665. 'timecreated' => $file->get_timecreated(),
  4666. 'filename' => $file->get_filename()); // any filename
  4667. $file->delete();
  4668. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  4669. }
  4670. $output = "<script type='text/javascript'>
  4671. //<![CDATA[
  4672. alert('" . get_string('sucess_update', 'iassign') . "');\n
  4673. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  4674. //]]>
  4675. </script>";
  4676. print $output;
  4677. die();
  4678. }
  4679. /// Function for create an tag for iAssign filter
  4680. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  4681. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4682. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  4683. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  4684. // @param int $fileid Id of file
  4685. // @return string Return an string with an tag of iassign filter
  4686. function tag_ilm ($fileid) {
  4687. global $DB;
  4688. $fs = get_file_storage();
  4689. $width = '600';
  4690. $height = '400';
  4691. $file = $fs->get_file_by_id($fileid);
  4692. $filetype = explode(".", $file->get_filename());
  4693. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  4694. foreach ($iassign_ilm as $value) {
  4695. $extensions = explode(",", $value->extension);
  4696. if (in_array($filetype[1], $extensions)) {
  4697. $width = $value->width;
  4698. $height = $value->height;
  4699. }
  4700. }
  4701. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  4702. }
  4703. /// Function for delete iAssign file in Moodle data (exercise)
  4704. function delete_file_ilm () {
  4705. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4706. $fs = get_file_storage();
  4707. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  4708. $file = $fs->get_file_by_id($fileid);
  4709. if ($file)
  4710. $file->delete();
  4711. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4712. die();
  4713. }
  4714. /// Function for delete selected iAssign file in Moodle data (exercise)
  4715. function delete_selected_ilm () {
  4716. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4717. $fs = get_file_storage();
  4718. $context = context_course::instance($this->id);
  4719. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4720. $dirid = $this->get_dir_ilm('dirid');
  4721. foreach ($files_id as $file_id) {
  4722. $file = $fs->get_file_by_id($file_id);
  4723. if ($file) {
  4724. if (!$file->is_directory())
  4725. $file->delete();
  4726. else {
  4727. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4728. foreach ($files_delete as $value)
  4729. $value->delete();
  4730. $file->delete();
  4731. }
  4732. }
  4733. }
  4734. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  4735. die();
  4736. }
  4737. /// Function for duplicate iAssign file from "online" edition
  4738. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  4739. function duplicate_file_ilm () {
  4740. global $USER, $COURSE;
  4741. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4742. $fs = get_file_storage();
  4743. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4744. $filename = optional_param('filename', NULL, PARAM_RAW);
  4745. $file = $fs->get_file_by_id($fileid);
  4746. $context = context_course::instance($this->id);
  4747. $fileinfo = array(
  4748. 'contextid' => $context->id, // ID of context
  4749. 'component' => 'mod_iassign', // usually = table name
  4750. 'filearea' => 'activity', // usually = table name
  4751. 'itemid' => 0, // usually = ID of row in table
  4752. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  4753. 'userid' => $USER->id,
  4754. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  4755. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  4756. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  4757. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  4758. die();
  4759. }
  4760. /// Function for rename iAssign file
  4761. function rename_file_ilm () {
  4762. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4763. $fs = get_file_storage();
  4764. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4765. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4766. $file = $fs->get_file_by_id($fileid);
  4767. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  4768. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  4769. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4770. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  4771. die();
  4772. }
  4773. /// Function for get iassign file for iassign form
  4774. function add_ilm () {
  4775. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4776. $filename = optional_param('filename', NULL, PARAM_TEXT);
  4777. $output = "
  4778. <script type='text/javascript'>
  4779. //<![CDATA[
  4780. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  4781. iassign_file_link.innerHTML = '$filename';
  4782. window.opener.document.forms['mform1'].file.value='$fileid';
  4783. window.opener.document.forms['mform1'].filename.value='$filename';
  4784. window.close();
  4785. //]]>
  4786. </script>";
  4787. print $output;
  4788. die();
  4789. }
  4790. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  4791. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  4792. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  4793. function preview_ilm ($courseid, $iassign_ilm) {
  4794. global $OUTPUT, $CFG, $USER;
  4795. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4796. $title = get_string('modulename', 'iassign'); // iAssign
  4797. print $OUTPUT->header();
  4798. print $OUTPUT->box_start();
  4799. $javascript = "
  4800. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  4801. <script type='text/javascript'>
  4802. //<![CDATA[
  4803. function submit_close () {
  4804. window.opener.location.reload();
  4805. window.close();
  4806. }
  4807. //]]>
  4808. </script>\n";
  4809. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  4810. // to the complete "applet" tag
  4811. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  4812. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  4813. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  4814. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  4815. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  4816. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  4817. if ($ilm_name != "ivprog") {
  4818. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  4819. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  4820. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  4821. } else {
  4822. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  4823. $content_or_id_from_ilm_security = $this->get_file_ilm();
  4824. $timecreated = time();
  4825. $token = md5($timecreated);
  4826. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  4827. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  4828. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  4829. $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)
  4830. }
  4831. $html = "
  4832. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4833. <table border='1'>
  4834. <tr><td>
  4835. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  4836. <!-- iLM calls : end -->
  4837. </td></tr>
  4838. </table>
  4839. <table>
  4840. <tr>
  4841. <td align='center'>
  4842. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  4843. </td></tr>
  4844. </table>
  4845. </form>\n";
  4846. print $javascript . $html;
  4847. print $OUTPUT->box_end();
  4848. //NAO echo format_string($html); // Moodle 3.X
  4849. die();
  4850. } // function preview_ilm($courseid, $iassign_ilm)
  4851. //r_ function preview_ilm ($iassign_ilm)
  4852. //r_ /// Function for preview iassign file from iassign filter.
  4853. //r_ function preview_ilm() {
  4854. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  4855. //r_ $tag_filter = $this->tag_ilm($fileid);
  4856. //r_ $javascript = "<script type='text/javascript'>
  4857. //r_ //<![CDATA[
  4858. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  4859. //r_ //]]>
  4860. //r_ </script>";
  4861. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  4862. //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>
  4863. //r_ </table></form></body></html>";
  4864. //r_ echo $javascript . format_text($html);
  4865. //r_ die;
  4866. //r_ }
  4867. /// Function for export an package (zip) of iassign files
  4868. function export_files_ilm () {
  4869. global $CFG;
  4870. $context = context_course::instance($this->id);
  4871. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  4872. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  4873. $zip = new zip_archive();
  4874. $zip->open($zip_filename);
  4875. $fs = get_file_storage();
  4876. foreach ($files_id as $file_id) {
  4877. $file = $fs->get_file_by_id($file_id);
  4878. if (!$file->is_directory())
  4879. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  4880. else {
  4881. $zip->add_directory($file->get_filepath());
  4882. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  4883. foreach ($files_zip as $value) {
  4884. if (!$value->is_directory())
  4885. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  4886. else
  4887. $zip->add_directory($value->get_filepath());
  4888. }
  4889. }
  4890. }
  4891. $zip->close();
  4892. header("Pragma: public");
  4893. header("Expires: 0");
  4894. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4895. header("Cache-Control: private", false);
  4896. header("Content-Type: application/zip");
  4897. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  4898. header("Content-Transfer-Encoding: binary");
  4899. header("Content-Length: " . @filesize($zip_filename));
  4900. set_time_limit(0);
  4901. @readfile("$zip_filename") || die("File not found.");
  4902. unlink($zip_filename);
  4903. exit;
  4904. }
  4905. /// Function of execute a command in button editor tinymce
  4906. // @param int $fileid Id of file
  4907. function tinymce_ilm ($fileid) {
  4908. $tag_filter = $this->tag_ilm($fileid);
  4909. $output = "<script type='text/javascript'>
  4910. //<![CDATA[
  4911. var tag_filter = '$tag_filter';
  4912. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  4913. // all right, insert it
  4914. } else {
  4915. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  4916. }
  4917. // window.close();
  4918. //]]>
  4919. </script>\n";
  4920. print $output;
  4921. die();
  4922. }
  4923. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  4924. /// Function to add content to the Editor Window
  4925. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4926. // @param int $fileid Id of file
  4927. function editor_ilm ($fileid, $editor) {
  4928. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  4929. $output1 = "<script type='text/javascript'>
  4930. //<![CDATA[
  4931. var tag_filter = '$tag_filter';\n";
  4932. if ($editor == 'atto') {
  4933. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  4934. } elseif ($editor == 'tinyMCE') {
  4935. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  4936. } else
  4937. $output2 = "";
  4938. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  4939. window.close();
  4940. //]]>
  4941. </script>\n";
  4942. //D var_dump($output);
  4943. print $output1 . $output2 . $output3;
  4944. die();
  4945. }
  4946. /// Function to add content to the Atto Editor Window
  4947. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  4948. // @param int $fileid Id of file
  4949. function atto_ilm ($fileid) {
  4950. global $CFG, $DB;
  4951. $tag_filter = $this->tag_ilm($fileid);
  4952. $output = "<script type='text/javascript'>
  4953. //<![CDATA[
  4954. var tag_filter = '$tag_filter';
  4955. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  4956. // all right, insert iLM tag to this editor
  4957. } else {
  4958. // error trying to insert
  4959. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  4960. }
  4961. //window.close();
  4962. //]]>
  4963. </script>\n";
  4964. print $output;
  4965. die();
  4966. }
  4967. /// Function for get path and infos of dirs: dirid, dir_base, dir_parent, dir_home
  4968. // @param string $key Key for return information
  4969. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  4970. function get_dir_ilm ($key) {
  4971. $fs = get_file_storage();
  4972. $context = context_course::instance($this->id);
  4973. $dirid = optional_param('dirid', 0, PARAM_INT);
  4974. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  4975. if ($dirid == 0) {
  4976. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  4977. $dirid = $dir->get_id();
  4978. } else {
  4979. $dir = $fs->get_file_by_id($dirid);
  4980. $dir_base = $dir->get_filepath();
  4981. }
  4982. $dir_parent = $dir->get_parent_directory();
  4983. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  4984. return $data[$key];
  4985. }
  4986. /// Function for create an new dir
  4987. function new_dir_ilm () {
  4988. global $USER;
  4989. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4990. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  4991. $dir_base = $this->get_dir_ilm('dir_base');
  4992. $context = context_course::instance($this->id);
  4993. $fs = get_file_storage();
  4994. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  4995. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  4996. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  4997. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  4998. }
  4999. /// Function for delete an dir
  5000. function delete_dir_ilm () { //
  5001. $fs = get_file_storage();
  5002. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5003. $context = context_course::instance($this->id);
  5004. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5005. $dir_parent = $this->get_dir_ilm('dir_parent');
  5006. if ($dir) {
  5007. if ($dir->is_directory()) {
  5008. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5009. foreach ($files_delete as $value)
  5010. $value->delete();
  5011. $dir->delete();
  5012. }
  5013. }
  5014. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5015. die();
  5016. }
  5017. /// Function for rename an dir
  5018. function rename_dir_ilm () {
  5019. $fs = get_file_storage();
  5020. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5021. $context = context_course::instance($this->id);
  5022. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5023. $dir_parent = $this->get_dir_ilm('dir_parent');
  5024. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5025. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5026. if ($dir->is_directory()) {
  5027. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5028. foreach ($files_rename_path as $value)
  5029. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5030. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5031. }
  5032. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5033. die();
  5034. }
  5035. /// Function for move an dir and your content for other dir
  5036. function selected_move_ilm () {
  5037. global $PAGE, $OUTPUT, $CFG;
  5038. $fs = get_file_storage();
  5039. $context = context_course::instance($this->id);
  5040. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5041. $dirid = $this->get_dir_ilm('dirid');
  5042. $dir_base = $this->get_dir_ilm('dir_base');
  5043. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5044. $code_javascript_ilm = "
  5045. <script type='text/javascript'>
  5046. //<![CDATA[
  5047. function getRadiobutton () {
  5048. var radioButtons = document.getElementsByTagName('input');
  5049. var param = '';
  5050. for (var counter=0; counter < radioButtons.length; counter++) {
  5051. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5052. param = radioButtons[counter].value;
  5053. }
  5054. return param;
  5055. }
  5056. function move_selected_ilm () {
  5057. var msgAnswer;
  5058. if (getRadiobutton() != '') {
  5059. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5060. if (msgAnswer)
  5061. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5062. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5063. }
  5064. else
  5065. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5066. }
  5067. function cancel_selected_ilm () {
  5068. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5069. }
  5070. //]]>
  5071. </script>\n";
  5072. $title = get_string('move_files', 'iassign');
  5073. $PAGE->set_title($title);
  5074. $PAGE->set_pagelayout('base');
  5075. print $OUTPUT->header();
  5076. print $OUTPUT->heading($title);
  5077. $dir_paths = array();
  5078. print $OUTPUT->box_start();
  5079. print "<center>";
  5080. foreach ($files_id as $file_id) {
  5081. $file = $fs->get_file_by_id($file_id);
  5082. if ($file) {
  5083. if (!$file->is_directory())
  5084. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5085. else {
  5086. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5087. array_push($dir_paths, $file->get_filepath());
  5088. }
  5089. }
  5090. }
  5091. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5092. if ($dir_base != '/') {
  5093. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5094. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5095. }
  5096. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5097. foreach ($files_tree as $file) {
  5098. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5099. $is_parent = false;
  5100. foreach ($dir_paths as $dir) {
  5101. $path = explode("/", $dir);
  5102. array_pop($path);
  5103. $path[count($path) - 1] = '';
  5104. $path = implode("/", $path);
  5105. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5106. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5107. }
  5108. if ($is_parent == false) {
  5109. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5110. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5111. }
  5112. }
  5113. }
  5114. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5115. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5116. print "</center>";
  5117. print $OUTPUT->box_end();
  5118. print $OUTPUT->footer();
  5119. print $code_javascript_ilm;
  5120. die;
  5121. }
  5122. /// Function for move files for an dir
  5123. function move_files_ilm () {
  5124. $fs = get_file_storage();
  5125. $context = context_course::instance($this->id);
  5126. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5127. $dirid = $this->get_dir_ilm('dirid');
  5128. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5129. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5130. foreach ($files_id as $file_id) {
  5131. $file = $fs->get_file_by_id($file_id);
  5132. if ($file) {
  5133. if ($file->is_directory()) {
  5134. $pathname = explode("/", $file->get_filepath());
  5135. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5136. foreach ($files_move_path as $value) {
  5137. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5138. $value->rename($path_move, $value->get_filename());
  5139. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5140. }
  5141. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5142. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5143. $file->rename($path_move, $file->get_filename());
  5144. } else {
  5145. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5146. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5147. }
  5148. }
  5149. }
  5150. //die;
  5151. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5152. die();
  5153. } // function move_files_ilm()
  5154. /// Function for recover files in use on all activities of a course
  5155. function recover_files_ilm () {
  5156. global $DB, $USER;
  5157. $fs = get_file_storage();
  5158. $courseid = optional_param('id', NULL, PARAM_INT);
  5159. $dirid = $this->get_dir_ilm('dirid');
  5160. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5161. $contextfile = context_course::instance($this->id);
  5162. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5163. foreach ($iassigns as $iassign) {
  5164. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5165. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5166. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5167. $context = context_module::instance($cm->id);
  5168. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5169. if ($files) {
  5170. foreach ($files as $value) {
  5171. $extension = explode(".", $value->get_filename());
  5172. if (!$value->is_directory()) {
  5173. $fileinfo = array('contextid' => $contextfile->id,
  5174. 'component' => 'mod_iassign',
  5175. 'filearea' => 'activity',
  5176. 'itemid' => 0,
  5177. 'filepath' => $this->get_dir_ilm('dir_base'),
  5178. 'userid' => $USER->id,
  5179. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5180. 'license' => 'allrightsreserved',
  5181. 'timecreated' => time(),
  5182. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5183. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5184. }
  5185. }
  5186. } // if ($files)
  5187. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5188. } // foreach ($iassigns as $iassign)
  5189. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5190. die();
  5191. } // function recover_files_ilm()
  5192. /// List iassign files from course directory
  5193. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5194. function view_files_ilm ($iassign_ilm_class, $extension) {
  5195. global $CFG, $DB, $USER, $OUTPUT;
  5196. $fs = get_file_storage();
  5197. $context = context_course::instance($this->id);
  5198. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5199. $dirid = $this->get_dir_ilm('dirid');
  5200. $dir_base = $this->get_dir_ilm('dir_base');
  5201. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5202. $files_array = '';
  5203. foreach ($files_course as $value) {
  5204. if (!$value->is_directory())
  5205. $files_array .= "'" . $value->get_filename() . "',";
  5206. }
  5207. $files_array .= "''";
  5208. $error_files_exists = get_string('error_file_exists', 'iassign');
  5209. $dirs_array = '';
  5210. foreach ($files_course as $value) {
  5211. if ($value->is_directory()) {
  5212. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5213. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5214. }
  5215. }
  5216. $dirs_array .= "''";
  5217. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5218. // TODO Rever o preview pois só deixar ver uma vez.
  5219. $code_javascript_ilm = "
  5220. <script type='text/javascript'>
  5221. //<![CDATA[
  5222. function preview_ilm (fileid, ilmid) {
  5223. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5224. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5225. }
  5226. function update_ilm (ilmid, fileid) {
  5227. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5228. }
  5229. function delete_ilm (ilmid, fileid) {
  5230. var msgAnswer;
  5231. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5232. if (msgAnswer) {
  5233. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5234. }
  5235. }
  5236. function delete_selected_ilm () {
  5237. var msgAnswer;
  5238. var param = getCheckbox();
  5239. if (param.join() != '') {
  5240. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5241. if (msgAnswer)
  5242. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5243. }
  5244. else
  5245. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5246. }
  5247. function add_ilm_iassign (ilmid, filename, fileid) {
  5248. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5249. }
  5250. function duplicate_ilm (ilmid, filename, fileid) {
  5251. var filenamecopy;
  5252. var i;
  5253. var files = new Array($files_array);
  5254. do {
  5255. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5256. } while (filenamecopy == '');
  5257. if (filenamecopy == null)
  5258. return false;\n
  5259. else {
  5260. for (i=0;i<files.length;i++) {
  5261. if (files[i]==filenamecopy) {
  5262. alert('$error_files_exists');
  5263. return false;\n
  5264. }
  5265. }\n" .
  5266. // @see: function 'duplicate_file_ilm()' above
  5267. "
  5268. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5269. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5270. } // else
  5271. }
  5272. function rename_ilm (ilmid, filename, fileid) {
  5273. var filenamecopy;
  5274. var i;
  5275. var files = new Array($files_array);
  5276. do {
  5277. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5278. } while (filenamecopy == '');
  5279. if (filenamecopy == null)
  5280. return false;
  5281. else {
  5282. for (i=0;i<files.length;i++) {
  5283. if (files[i]==filenamecopy) {
  5284. alert('$error_files_exists');
  5285. return false;
  5286. }
  5287. }
  5288. 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;
  5289. }
  5290. }
  5291. function export_files_ilm () {
  5292. var param = getCheckbox();
  5293. if (param.join() != '')
  5294. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5295. else
  5296. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5297. }
  5298. function select_all_ilm () {
  5299. var checkBoxes = document.getElementsByTagName('input');
  5300. var selectAll = document.getElementById('select_all');
  5301. for (var counter=0; counter < checkBoxes.length; counter++) {
  5302. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5303. checkBoxes[counter].checked = selectAll.checked;
  5304. }
  5305. }
  5306. function getCheckbox () {
  5307. var checkBoxes = document.getElementsByTagName('input');
  5308. var param = new Array();
  5309. for (var counter=0; counter < checkBoxes.length; counter++) {
  5310. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5311. param.push(checkBoxes[counter].value);
  5312. }
  5313. return param;
  5314. }
  5315. function new_dir_ilm () {
  5316. var dirname = '';
  5317. var i;
  5318. var dirs = new Array($dirs_array);
  5319. do {
  5320. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5321. } while (dirname == '');
  5322. if (dirname == null)
  5323. return false;\n
  5324. else {
  5325. for (i=0;i<dirs.length;i++) {
  5326. if (dirs[i]==dirname) {
  5327. alert('$error_dir_exists');
  5328. return false;\n
  5329. }
  5330. }
  5331. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5332. }
  5333. }
  5334. function delete_dir_ilm (ilmid, dirid) {
  5335. var msgAnswer;
  5336. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5337. if (msgAnswer) {
  5338. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5339. }
  5340. }
  5341. function rename_dir_ilm (ilmid, dirname, dirid) {
  5342. var dirnamecopy;
  5343. var i;
  5344. var dirs = new Array($dirs_array);
  5345. do {
  5346. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5347. } while (dirnamecopy == '');
  5348. if (dirnamecopy == null)
  5349. return false;\n
  5350. else {
  5351. for (i=0;i<dirs.length;i++) {
  5352. if (dirs[i]==dirnamecopy) {
  5353. alert('$error_dir_exists');
  5354. return false;\n
  5355. }
  5356. }
  5357. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5358. }
  5359. }
  5360. function move_selected_ilm (ilmid) {
  5361. var param = getCheckbox();
  5362. if (param.join() != '')
  5363. 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();
  5364. else
  5365. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5366. }
  5367. function recover_files_ilm () {
  5368. var msgAnswer;
  5369. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5370. if (msgAnswer) {
  5371. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5372. }
  5373. }
  5374. window.onload = function() {
  5375. var xPosition = 0;
  5376. var yPosition = 0;
  5377. element=document.getElementById('new_file');
  5378. while(element) {
  5379. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5380. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5381. element = element.offsetParent;
  5382. }
  5383. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5384. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5385. location.hash = '#new_file';
  5386. };
  5387. //]]>
  5388. </script>\n";
  5389. $output = "";
  5390. $select_all = "";
  5391. $count_files = 0;
  5392. $extensions_allow = array();
  5393. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  5394. foreach ($iassign_ilm as $item_iassign_ilm)
  5395. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  5396. foreach ($files_course as $value) {
  5397. $filename = $value->get_filename();
  5398. $filepath = $value->get_filepath();
  5399. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  5400. $pathname = $pathname[count($pathname) - 1];
  5401. $fileid = $value->get_id();
  5402. $tmp = explode(".", $filename);
  5403. //D echo "locallib.php: view_files_ilm(...): filename=$filename, extension=$extension<br/>";
  5404. //D print_r($tmp); echo "<br/>#tmp=". sizeof($tmp) ."<br/>";
  5405. if (is_array($tmp)) {
  5406. if (sizeof($tmp)>1)
  5407. $filetype = $tmp[1];
  5408. else
  5409. $filetype = $extension;
  5410. }
  5411. else
  5412. $filetype = $extension;
  5413. $author = $value->get_author();
  5414. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  5415. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  5416. $extensions = explode(",", $extension);
  5417. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  5418. $count_files ++;
  5419. // buscar fileid nas tabelas do iassign
  5420. $list_filein_use = "";
  5421. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5422. if ($iassign_statement_activity_list) {
  5423. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5424. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  5425. }
  5426. }
  5427. $array_iassign_ilm = $DB->get_records("iassign_ilm", array('extension' => $filetype, 'parent' => '0', 'enable' => '1'));
  5428. foreach ($array_iassign_ilm as $iassign_ilm) { // get files from all iLM equivalent
  5429. if (!$iassign_ilm) {
  5430. $iassign_ilm = new stdClass();
  5431. $iassign_ilm->id = $ilmid;
  5432. }
  5433. // Do not use $var inside "..." - problem with some "unusual" operational system
  5434. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  5435. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  5436. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  5437. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  5438. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5439. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5440. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  5441. $check_select = "";
  5442. $link_rename = "";
  5443. $link_delete = "";
  5444. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5445. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5446. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5447. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  5448. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  5449. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  5450. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  5451. if ($value->get_userid() == $USER->id) {
  5452. if ($iassign_statement_activity_list) {
  5453. $check_select = "";
  5454. $link_edit = iassign_icons::insert('edit_iassign_disable');
  5455. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  5456. $link_rename = "";
  5457. }
  5458. else {
  5459. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  5460. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  5461. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  5462. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  5463. }
  5464. } // if ($value->get_userid() == $USER->id)
  5465. if (!in_array($filetype, $extensions_allow)) {
  5466. $link_edit = "";
  5467. $link_add_ilm_iassign = "";
  5468. $link_add_ilm_tinymce = "";
  5469. $link_add_ilm_atto = "";
  5470. $link_filter = "";
  5471. }
  5472. if ($value->is_directory()) {
  5473. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  5474. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  5475. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  5476. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  5477. <td><center>$author</center></td>
  5478. <td><center>$timecreated</center></td>
  5479. <td><center>$timemodified</center></td></tr>\n";
  5480. }
  5481. else if ($this->from == 'iassign') {
  5482. $new_id = "";
  5483. $new_class = "";
  5484. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  5485. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  5486. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  5487. }
  5488. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  5489. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5490. <td><center>$author</center></td>
  5491. <td><center>$timecreated</center></td>
  5492. <td><center>$timemodified</center></td></tr>\n";
  5493. }
  5494. else if ($this->from == 'block') {
  5495. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  5496. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5497. <td><center>$author</center></td>
  5498. <td><center>$timecreated</center></td>
  5499. <td><center>$timemodified</center></td></tr>\n";
  5500. }
  5501. else if ($this->from == 'tinymce') {
  5502. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  5503. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5504. <td><center>$author</center></td>
  5505. <td><center>$timecreated</center></td>
  5506. <td><center>$timemodified</center></td></tr>\n";
  5507. }
  5508. else if ($this->from == 'atto') {
  5509. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  5510. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  5511. <td><center>$author</center></td>
  5512. <td><center>$timecreated</center></td>
  5513. <td><center>$timemodified</center></td></tr>\n";
  5514. }
  5515. } // foreach ($array_iassign_ilm as $iassign_ilm)
  5516. } // if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto')
  5517. } // foreach ($files_course as $value)
  5518. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  5519. $dir_base = "";
  5520. $header = "";
  5521. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  5522. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  5523. foreach ($basename as $value) {
  5524. $dir_base .= $value . "/";
  5525. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  5526. if ($dir_id) {
  5527. if ($value == "") {
  5528. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5529. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  5530. } else {
  5531. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  5532. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  5533. }
  5534. }
  5535. } // foreach ($basename as $value)
  5536. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  5537. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  5538. $html .= "
  5539. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  5540. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  5541. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  5542. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  5543. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  5544. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  5545. </table>\n";
  5546. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  5547. $html .= "<table width='100%'><tr>\n";
  5548. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  5549. if ($count_files != 0) {
  5550. $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";
  5551. $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";
  5552. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  5553. }
  5554. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  5555. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  5556. $html .= "</form>\n";
  5557. print $code_javascript_ilm;
  5558. print $html;
  5559. } // function view_files_ilm($extension)
  5560. } // class ilm_manager
  5561. /// Class to insert of icons
  5562. class iassign_icons {
  5563. static function insert ($icon) {
  5564. global $CFG;
  5565. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  5566. return $string;
  5567. }
  5568. }
  5569. /// Class with util functions for plugin manage
  5570. class iassign_utils {
  5571. /// Function to return the filename extension
  5572. // @param string The $filename as an string
  5573. // @return string Return an string (last group after '.')
  5574. static function filename_extension ($filename) {
  5575. if ($filename == null || $filename == '') {
  5576. return null;
  5577. }
  5578. $itens = explode('.', $filename);
  5579. $num = count($itens);
  5580. if ($num < 2) {
  5581. return null;
  5582. }
  5583. return $itens[$num - 1];
  5584. }
  5585. /// Use the PHP class/package ZipArchive to create a Zip file
  5586. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  5587. // 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
  5588. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  5589. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  5590. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  5591. $zip = new zip_archive(); //2
  5592. $res = $zip->open($full_path_zip_filename);
  5593. $total_vet = count($vet_student_filename);
  5594. for ($ii=0; $ii<$total_vet; $ii++) {
  5595. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  5596. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  5597. }
  5598. $ret = $zip->close();
  5599. iassign_utils::download_file($full_path_zip_filename);
  5600. $filenameZip = $zip->filename;
  5601. return array($ret, $zip);
  5602. }
  5603. static function download_file ($zip_filename) {
  5604. header("Pragma: public");
  5605. header("Expires: 0");
  5606. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5607. header("Cache-Control: private", false);
  5608. header("Content-Type: application/zip");
  5609. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5610. header("Content-Transfer-Encoding: binary");
  5611. header("Content-Length: " . @filesize($zip_filename));
  5612. set_time_limit(0);
  5613. @readfile("$zip_filename") || die("File not found.");
  5614. unlink($zip_filename);
  5615. }
  5616. /// Function for format filename remove special caracters
  5617. // @param string $text String for clean
  5618. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  5619. // @return string Return an string in clean format
  5620. static function format_filename ($text) {
  5621. if ($text != '.') {
  5622. //D $text = htmlspecialchars(urldecode($text));
  5623. //D echo "locallib.php: format_filename: $text<br/>";
  5624. if (is_object($text)) // with iAssign did not filtered text from JSON format
  5625. $text = json_decode($text)->{current_language()};
  5626. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  5627. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  5628. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  5629. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  5630. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  5631. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  5632. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  5633. // E.g. text = "exerc_midpoint.course.geo"
  5634. // 0123456789012345678901234
  5635. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  5636. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  5637. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  5638. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  5639. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  5640. //$ext = strrpos($text, ".");
  5641. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  5642. //$text = str_replace($array1, $array2, $text);
  5643. }
  5644. return $text;
  5645. }
  5646. /// Function to filter characters to the file name to iLM content
  5647. // @param string $text String for clean
  5648. // @param string $ext String ot the extension of the iLM
  5649. // @return string Return an string in clean format
  5650. static function filter_filename_extension ($filename, $ext) {
  5651. if ($filename != '.') {
  5652. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  5653. $arrTo = array("_","","","","","","","","","","","","");
  5654. $filename = str_replace($arrFrom, $arrTo, $filename);
  5655. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  5656. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  5657. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  5658. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  5659. $index_lastposition = strlen($filenameF);
  5660. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  5661. $text = str_replace(".", "_", $text); // erase all other "."
  5662. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  5663. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  5664. }
  5665. else
  5666. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  5667. return $filenameF;
  5668. }
  5669. /// Function for format pathname remove special caracters
  5670. // @param string $text String for clean
  5671. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5672. // @return string Return an string in clean format
  5673. static function format_pathname ($text, $is_lowercase = true) {
  5674. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5675. $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", "-", "_", "", "", "");
  5676. $text = str_replace($array1, $array2, $text);
  5677. if ($is_lowercase)
  5678. $text = strtolower($text);
  5679. return $text;
  5680. }
  5681. /// Function for format file name from iLM original name
  5682. // @param string $text String to build the file neam
  5683. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  5684. // @return string Return an string in clean format
  5685. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  5686. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  5687. $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", "-", "_", "", "", "");
  5688. $index_firstposition_blank = strpos($ilm_name, " ");
  5689. if ($index_firstposition_blank) { // truncate the name!
  5690. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  5691. }
  5692. $index_firstposition_dots = strpos($ilm_name, ":");
  5693. if ($index_firstposition_dots) { // truncate the name!
  5694. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  5695. }
  5696. $namefiltered = str_replace($array1, $array2, $ilm_name);
  5697. if ($is_lowercase)
  5698. $namefiltered = strtolower($namefiltered);
  5699. return $namefiltered;
  5700. }
  5701. /// Function for insert version in the filename
  5702. // @param string $filename Name of file
  5703. // @return string Return the filename with version
  5704. static function version_filename ($filename) {
  5705. $array_filename = explode('.', $filename);
  5706. if (count($array_filename) > 1)
  5707. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  5708. else
  5709. $filename = $array_filename[0] . '-' . date("Ymd-His");
  5710. return $filename;
  5711. }
  5712. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  5713. static function remove_code_message ($string) {
  5714. $array = explode("&lt;ia_uc&gt;", $string);
  5715. return $array[0];
  5716. }
  5717. }
  5718. // class iassign_utils
  5719. /// Class with language functions for plugin manage
  5720. class iassign_language {
  5721. /// Function for return text in language or get default language (en)
  5722. // @param string $lang Code of language
  5723. // @param string $description JSON text content all languages
  5724. // @return string Return an string in the language selected
  5725. static function get_description_lang ($lang, $descriptions) {
  5726. $description_lang = "";
  5727. $description = json_decode($descriptions);
  5728. if ($description == null) {
  5729. $description_lang = $descriptions;
  5730. }
  5731. else {
  5732. if (isset($description->{$lang}))
  5733. $description_lang = $description->{$lang};
  5734. else
  5735. if (isset($description->en)) //MOOC2014
  5736. $description_lang = $description->en;
  5737. else //MOOC2014
  5738. $description_lang = "en"; //MOOC2014
  5739. }
  5740. return $description_lang;
  5741. }
  5742. /// Function for return all language supported by iLM
  5743. // @param string $descriptions JSON text content all languages
  5744. // @return string Return as string with all languages
  5745. static function get_all_lang ($descriptions) {
  5746. $langs = "";
  5747. $description = json_decode($descriptions);
  5748. if ($description) {
  5749. foreach ($description as $key => $value) {
  5750. $langs .= $key . " ; ";
  5751. }
  5752. $langs = substr($langs, 0, strlen($langs) - 3);
  5753. }
  5754. return $langs;
  5755. }
  5756. /// Function for convert json in xml //MOOC2014
  5757. // @param string $json JSON text
  5758. // @return string Return as string with xml tags
  5759. static function json_to_xml ($json) {
  5760. $xml = "";
  5761. $json = json_decode($json);
  5762. foreach ($json as $key => $value) {
  5763. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  5764. }
  5765. return $xml;
  5766. }
  5767. }
  5768. // class iassign_language
  5769. /// Class with log functions for plugin manage.
  5770. class iassign_log {
  5771. /// Function for insert log event
  5772. // @param string $action Code action of event
  5773. // @param string $information Text for describe action of event
  5774. // @param int $cmid Id of context module
  5775. // @param int $ilmid Id of iLM
  5776. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  5777. global $COURSE, $CFG, $USER, $DB;
  5778. $newentry = new stdClass();
  5779. $newentry->time = time();
  5780. $newentry->userid = $USER->id;
  5781. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  5782. $newentry->course = $COURSE->id;
  5783. $newentry->cmid = $cmid;
  5784. $newentry->ilmid = $ilmid;
  5785. $newentry->action = $action;
  5786. $newentry->info = $information;
  5787. $newentry->language = current_language();
  5788. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  5789. if (ini_get("browscap") && function_exists('get_browse')) {
  5790. $browser = get_browse(null, true);
  5791. $newentry->javascript = $browser['javascript'];
  5792. $newentry->java = $browser['javaapplets'];
  5793. }
  5794. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  5795. print_error('error_add_log', 'iassign');
  5796. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  5797. } // class iassign_log