locallib.php 355 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->get_answer();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. 'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'get_student_submission' => '$this->get_student_submission();',
  278. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  279. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  280. );
  281. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  282. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  283. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  284. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  285. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  286. }
  287. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  288. eval($action_iassign_limit[$this->action]);
  289. }
  290. else { // Student reaches this point
  291. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  292. // Arrive here with: "get_answer"; "view"
  293. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  294. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  295. }
  296. } // function action()
  297. /// This method prints the student submission to a specific exercise
  298. function get_student_submission () {
  299. global $DB;
  300. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  301. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  302. if (!$student || !$exercise) exit;
  303. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  304. if ($iassign_submission)
  305. print($iassign_submission->answer);
  306. die();
  307. }
  308. /// This method prints the teacher exercise
  309. function get_teacher_exercise () {
  310. global $DB, $COURSE;
  311. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  312. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  314. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id,
  315. 'mod_iassign',
  316. 'exercise',
  317. $iassign_statement->file);
  318. foreach ($files as $file) {
  319. if ($file->get_filename() != ".") {
  320. print($file->get_content());
  321. }
  322. }
  323. die();
  324. }
  325. /// This method receives the data from auto_eval event
  326. /// @see auto_evaluate()
  327. function post_auto_eval_result () {
  328. global $COURSE, $CFG, $USER, $DB;
  329. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  330. exit;
  331. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  332. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  333. $student = optional_param('student', -1, PARAM_INT);
  334. $grade = optional_param('grade', 0, PARAM_FLOAT);
  335. // 1: Recuperar a nota atual:
  336. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  337. // 2: Atualizar a tabela:
  338. $update_entry = new stdClass();
  339. $update_entry->id = $actual->id;
  340. $update_entry->previous_grade = $actual->grade;
  341. $update_entry->grade = $grade;
  342. // Update the iassign_submission
  343. $DB->update_record("iassign_submission", $update_entry);
  344. }
  345. /// This method runs activities auto evaluation in teacher area
  346. function auto_evaluate () {
  347. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  348. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  349. exit;
  350. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  351. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  352. // Get list of exercises in the instance:
  353. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  354. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  355. // Get list of enrolled students:
  356. $params = array('shortname' => 'student');
  357. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  358. $context = context_course::instance($this->course->id);
  359. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  360. $students_list = $DB->get_records_sql(
  361. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  362. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  363. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  364. print $OUTPUT->header();
  365. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  366. print '<ul style="list-style-type: none; margin: 1em;">';
  367. foreach ($exercises_list as $exercise) {
  368. $matches = [];
  369. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  370. if ($matches[0][0]) {
  371. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
  372. } else {
  373. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
  374. }
  375. }
  376. print '</ul>
  377. <center>
  378. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  379. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  380. <div id="evaluate_message" style="color: red"></div>
  381. <div id="evaluate_alerts"></div>
  382. <div>
  383. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  384. <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
  385. </div>
  386. </center>';
  387. print '</div>';
  388. print '<script>';
  389. print 'var submissions = [';
  390. // Get list of student id have submit for each exercise:
  391. foreach ($exercises_list as $exercise) {
  392. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  393. print '
  394. {
  395. "exerciseid": "'.$exercise->id.'",
  396. "grade": '.$exercise->grade.',
  397. "ilm": "'. $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  398. "submited": [';
  399. $params = array('iassign_statementid' => $exercise->id);
  400. $submited = $DB->get_records_sql(
  401. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  402. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  403. foreach ($submited as $ss) {
  404. print( $ss->userid . ',');
  405. }
  406. print '],';
  407. print '"allgrades": [';
  408. foreach ($submited as $ss) {
  409. print( $ss->grade . ',');
  410. }
  411. print ']
  412. },';
  413. }
  414. print '];
  415. var total_submissions = 0;
  416. var selected_exercises;
  417. var count_steps;
  418. var value_by_step;
  419. var stoped = false;
  420. function add_hover_th (id_th, id_li) {
  421. $("#"+id_th).hover(function() {
  422. $("#"+id_li).css("background-color", "#d9d8d8");
  423. $(this).css("background-color", "#d9d8d8");
  424. }, function() {
  425. $("#"+id_li).css("background-color", "");
  426. $(this).css("background-color", "");
  427. });
  428. }
  429. function start_evaluation() {
  430. stoped = false;
  431. $("#progress_bar").css("display", "none");
  432. $("#evaluate_message").text("");
  433. $("#evaluate_alerts").text("");
  434. $(".added-col").remove();
  435. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  436. selected_exercises = [];
  437. var c = 0;
  438. for (var i = 0; i < exercises.length; i++) {
  439. if($("#ex_"+exercises[i]).is(":checked") == true) {
  440. selected_exercises[c++] = exercises[i];
  441. }
  442. }
  443. if (selected_exercises.length == 0) {
  444. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  445. return;
  446. } else {
  447. for (var i = 0; i < selected_exercises.length; i++) {
  448. $("#ex_"+selected_exercises[i]).attr("disabled", true);
  449. var desc = $("#ex_"+selected_exercises[i]).data("iditem");
  450. $("#cols-exercises").append( $("<th />", {class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i]}));
  451. $("#table-results tbody tr").each(function(e) {
  452. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  453. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  454. });
  455. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  456. }
  457. $("#button_start").prop("disabled", true);
  458. $("#button_stop").prop("disabled", false);
  459. $("#progress_bar").css("display", "block");
  460. }
  461. total_submissions = selected_exercises.length * students.length;
  462. count_steps = 0;
  463. value_by_step = 100/total_submissions;
  464. actual_exercise = 0;
  465. actual_student = 0;
  466. actual_submission = 0;
  467. get_original_propositions();
  468. }
  469. var actual_exercise;
  470. var actual_student;
  471. var actual_submission;
  472. function run_individual_evaluation () {
  473. if (stoped) return;
  474. // Verificar se o aluno realmente enviou
  475. var found = false;
  476. for (var j = 0; j < submissions.length; j++) {
  477. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  478. for (var k = 0; k < submissions[j].submited.length; k++) {
  479. if (students[actual_student] == submissions[j].submited[k]) {
  480. found = true;
  481. break;
  482. }
  483. }
  484. break;
  485. }
  486. }
  487. if (found == false) {
  488. postResultAutoEval();
  489. } else {
  490. // Caso tenha enviado, buscar...
  491. var final_url = "";
  492. var student_answer = "'.$CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=".$this->cm->id.'" + "&iassign_student="+students[actual_student]+"&iassign_exercise="+selected_exercises[actual_exercise];
  493. for (var j = 0; j < submissions.length; j++) {
  494. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  495. final_url = submissions[j].ilm;
  496. break;
  497. }
  498. }
  499. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment="+encodeURIComponent(student_answer)+"&iLM_PARAM_TeacherAutoEval=true";
  500. window.frames["ifrm"].location=final_url;
  501. }
  502. }
  503. function getAutoEvalOriginalData () {
  504. return original_propositions[actual_exercise];
  505. }
  506. function updateProgressBar () {
  507. if (stoped) return;
  508. var temp = (count_steps * value_by_step)|0;
  509. count_steps ++;
  510. temp = temp > 100 ? 100 : temp;
  511. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  512. if (temp >= 100) {
  513. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  514. $("#button_start").prop("disabled", false);
  515. $("#button_stop").prop("disabled", true);
  516. for (var i = 0; i < exercises.length; i++) {
  517. $("#ex_"+exercises[i]).attr("disabled", false);
  518. }
  519. }
  520. }
  521. function postResultAutoEval (grade = null) {
  522. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  523. if (grade == null) {
  524. $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
  525. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  526. } else {
  527. // Verificar se a nota é a mesma que já está registrada:
  528. var actual_value = 0;
  529. var actual_student_grade = 0;
  530. for (var k = 0; k < submissions.length; k++) {
  531. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  532. actual_value = submissions[k].grade;
  533. for (var h = 0; h < submissions[k].submited.length; h++) {
  534. if (submissions[k].submited[h] == students[actual_student]) {
  535. actual_student_grade = submissions[k].allgrades[h];
  536. break;
  537. }
  538. }
  539. break;
  540. }
  541. }
  542. /** @FeedbackConvention **/
  543. if (grade < 0) {
  544. switch (grade) {
  545. case -1:
  546. // Casos de teste vazios:
  547. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
  548. var mm = actual_exercise;
  549. $("#"+id_t).find(".details-button").click(function(e) {
  550. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
  551. });
  552. break;
  553. case -2:
  554. // Casos de teste alterados pelo aluno:
  555. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  556. var mm = actual_exercise;
  557. $("#"+id_t).find(".details-button").click(function(e) {
  558. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>\');
  559. });
  560. $.ajax({
  561. dataType: "html",
  562. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
  563. success: function(d) {}
  564. });
  565. break;
  566. case -5:
  567. // Falha na execução:
  568. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
  569. var mm = actual_exercise;
  570. $("#"+id_t).find(".details-button").click(function(e) {
  571. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
  572. });
  573. break;
  574. }
  575. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  576. } else {
  577. if ((grade * actual_value) == (actual_student_grade)) {
  578. $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
  579. } else { // Notas diferem:
  580. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
  581. var mm = actual_exercise;
  582. $("#"+id_t).find(".details-button").click(function(e) {
  583. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+actual_student_grade+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  584. });
  585. // Enviar para o endpoint post_auto_eval_result verificar:
  586. $.ajax({
  587. dataType: "html",
  588. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  589. success: function(d) {}
  590. });
  591. }
  592. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  593. }
  594. }
  595. updateProgressBar();
  596. // Pode continuar no mesmo exercício ou para?
  597. if (actual_student < students.length) {
  598. actual_student ++;
  599. run_individual_evaluation();
  600. } else {
  601. actual_student = 0;
  602. // Pode ir para o próximo exercício ou acabou?
  603. if (actual_exercise < selected_exercises.length) {
  604. actual_exercise++;
  605. run_individual_evaluation();
  606. } else {
  607. $("#evaluate_alerts").text("'.get_string('auto_evaluate_finished', 'iassign').'");
  608. }
  609. }
  610. }
  611. var original_propositions;
  612. function get_original_propositions () {
  613. original_propositions = [];
  614. var count = 0;
  615. for (var i = 0; i < exercises.length; i++) {
  616. if($("#ex_"+exercises[i]).is(":checked") == true) {
  617. $.ajax({
  618. dataType: "html",
  619. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=get_teacher_exercise&id='.$this->cm->id.'&iassign_exercise="+exercises[i],
  620. success: function(d) {
  621. original_propositions[count] = d;
  622. count ++;
  623. if (count == selected_exercises.length) {
  624. run_individual_evaluation();
  625. }
  626. }
  627. });
  628. }
  629. }
  630. }
  631. function stop_evaluation () {
  632. stoped = true;
  633. $("#button_start").prop("disabled", false);
  634. $("#button_stop").prop("disabled", true);
  635. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  636. for (var i = 0; i < exercises.length; i++) {
  637. $("#ex_"+exercises[i]).attr("disabled", false);
  638. }
  639. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  640. }
  641. var exercises = [ ';
  642. foreach ($exercises_list as $exercise) {
  643. print $exercise->id . ',';
  644. }
  645. print ' ];';
  646. print ' var students = [ ';
  647. foreach ($students_list as $student) {
  648. print $student->userid . ',';
  649. }
  650. print '];';
  651. print ' var ilms = [';
  652. foreach ($exercises_list as $exercise) {
  653. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  654. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  655. }
  656. print ']';
  657. print '</script>';
  658. print '
  659. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  660. <div class="modal-dialog modal-dialog-centered" role="document">
  661. <div class="modal-content">
  662. <div class="modal-header">
  663. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('auto_evaluate_details', 'iassign').'</h5>
  664. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  665. <span aria-hidden="true">&times;</span>
  666. </button>
  667. </div>
  668. <div class="modal-body">
  669. ...
  670. </div>
  671. <div class="modal-footer">
  672. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('close', 'iassign').'</button>
  673. </div>
  674. </div>
  675. </div>
  676. </div>';
  677. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  678. print '<table id="table-results" class="table table-hover m-t-1">
  679. <thead>
  680. <tr id="cols-exercises">
  681. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  682. </tr>
  683. </thead>
  684. <tbody>';
  685. foreach ($students_list as $student) {
  686. $user = $DB->get_record('user', array('id' => $student->userid));
  687. $avatar = new user_picture($user);
  688. $avatar->courseid = $COURSE->id;
  689. $avatar->link = true;
  690. print
  691. '<tr data-student="'.$student->userid.'">
  692. <td>'.$OUTPUT->render($avatar). ' <span class="student-name">'.$user->firstname.' '.$user->lastname.'</span></td>
  693. </tr>';
  694. }
  695. print '</tbody>
  696. </table>';
  697. print $OUTPUT->footer();
  698. }
  699. /// This method moves an iAssign activity
  700. function move_activity () {
  701. global $USER, $CFG, $DB, $COURSE;
  702. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  703. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  704. $update_entry_new_iassign = new stdClass();
  705. $update_entry_new_iassign->id = $iassign_id;
  706. $update_entry_new_iassign->iassignid = $iassign_destiny;
  707. // Update the iassign_statement
  708. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  709. // Update file context
  710. $c_i = context_module::instance($this->cm->id);
  711. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  712. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  713. $path_module = context_course::instance($COURSE->id);
  714. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  715. if ($context_file) {
  716. $id_context = $context_file->id;
  717. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  718. $fs = get_file_storage(); // Get reference to all files in Moodle data
  719. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  720. foreach ($files as $value) {
  721. if ($value->get_filename() != ".") {
  722. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  723. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  724. $updateentry = new stdClass();
  725. $updateentry->id = $iassign_id;
  726. $updateentry->file = $newfile->get_itemid();
  727. $DB->update_record("iassign_statement", $updateentry);
  728. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  729. break;
  730. }
  731. }
  732. }
  733. $this->return_home_course('moved_activity');
  734. exit;
  735. }
  736. /// This method duplicates an iAssign activity
  737. function duplicate_activity () {
  738. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  739. $id = $this->cm->id;
  740. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  741. $context = context_module::instance($this->cm->id);
  742. $contextuser = context_user::instance($USER->id);
  743. // Get the the iAssign acitivity to be duplicated
  744. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  745. // Remove the current id of activity
  746. $iassign_statement->id=0;
  747. // Get the information about current author, and add this information in author_modified field
  748. $author = $DB->get_record("user", array('id' => $USER->id));
  749. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  750. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  751. // Store the activity in the table
  752. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  753. // Duplicate activity file
  754. $fs = get_file_storage(); // Get reference to all files in Moodle data
  755. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  756. foreach ($files as $value) {
  757. if ($value->get_filename() != ".") {
  758. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  759. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  760. $updateentry = new stdClass();
  761. $updateentry->id = $id_;
  762. $updateentry->file = $newfile->get_itemid();
  763. // Update the duplicated iLM iAssign with new file id
  764. $DB->update_record("iassign_statement", $updateentry);
  765. }
  766. }
  767. }
  768. // log event --------------------------------------------------------------------------------------
  769. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  770. $this->return_home_course('duplicated_activity');
  771. exit;
  772. }
  773. /// This method gets the content from the iLM and register it
  774. // It could be the "exercise template" (teacher) or an answer (student)
  775. function get_answer () {
  776. global $USER, $CFG, $DB, $OUTPUT;
  777. $id = $this->cm->id;
  778. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  779. $comment = false;
  780. if ($submission_comment)
  781. $comment = $this->write_comment_submission();
  782. // receives data of iLM using the current activity
  783. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  784. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  785. // receives data of submission of current activity
  786. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  787. // receives post and get
  788. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  789. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  790. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  791. $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)
  792. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  793. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  794. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  795. $msg = '';
  796. // Feedback
  797. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  798. $str_action = "view"; // repeat
  799. if (strtolower($iassign_ilm->name) == "igeom") {
  800. }
  801. $title = get_string('evaluate_iassign', 'iassign');
  802. print $OUTPUT->header();
  803. print $OUTPUT->box_start();
  804. // Action = { view ; repeat ; viewsubmission }
  805. // * '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")
  806. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  807. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  808. $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;
  809. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  810. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  811. print '<table width=100% >';
  812. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  813. //TODO alterar aqui???
  814. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  815. // empty_answer_post = No solution was posted.
  816. if ($comment)
  817. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  818. else
  819. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  820. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  821. } else {
  822. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  823. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  824. // Correct answer!!
  825. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  826. $this->write_solution = 1; //
  827. $status = 3;
  828. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  829. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  830. // log record
  831. $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;
  832. // Trigger module viewed event.
  833. $event = \mod_iassign\event\submission_created::create(array(
  834. 'objectid' => $this->iassign->id,
  835. 'context' => $this->context,
  836. 'other' => $info
  837. ));
  838. $event->add_record_snapshot('course', $this->course);
  839. $event->trigger();
  840. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  841. // Wrong answer...: get_answer_incorrect
  842. $status = 2;
  843. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  844. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  845. // log record
  846. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  847. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  848. // Trigger module viewed event.
  849. $event = \mod_iassign\event\submission_created::create(array(
  850. 'objectid' => $this->iassign->id,
  851. 'context' => $this->context,
  852. 'other' => $info
  853. ));
  854. $event->add_record_snapshot('course', $this->course);
  855. $event->trigger();
  856. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  857. // Presents to the learner the result of the automatic evaluate?
  858. if ($this->activity->get_activity()->show_answer == 0) { // no...
  859. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  860. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  861. print '<tr>';
  862. // log record
  863. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  864. // Trigger module viewed event.
  865. $event = \mod_iassign\event\submission_created::create(array(
  866. 'objectid' => $this->iassign->id,
  867. 'context' => $this->context,
  868. 'other' => $info
  869. ));
  870. $event->add_record_snapshot('course', $this->course);
  871. $event->trigger();
  872. } else { // yes!!!
  873. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  874. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  875. print '<tr>';
  876. print $msg;
  877. }
  878. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  879. $status = 1;
  880. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  881. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  882. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  883. print '<tr>';
  884. // log record
  885. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  886. $event = \mod_iassign\event\submission_created::create(array(
  887. 'objectid' => $this->iassign->id,
  888. 'context' => $this->context,
  889. 'other' => $info
  890. ));
  891. $event->add_record_snapshot('course', $this->course);
  892. $event->trigger();
  893. } // if ($iassign_ilm->evaluate == 1)
  894. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  895. print '</tr></table>';
  896. print $OUTPUT->box_end();
  897. // add or update evaluate
  898. if ($this->write_solution == 1) {
  899. $timenow = time();
  900. // new record
  901. if (!$iassign_submission) {
  902. $newentry = new stdClass();
  903. $newentry->userid = $this->userid_iassign;
  904. // $newentry->userid = $USER->id;
  905. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  906. $newentry->timecreated = $timenow;
  907. $newentry->timemodified = $timenow;
  908. $newentry->answer = $iLM_PARAM_ArchiveContent;
  909. $newentry->grade = round($grade_student, 2);
  910. $newentry->status = $status;
  911. $newentry->experiment = 1;
  912. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  913. print_error('error_insert', 'iassign');
  914. } else {
  915. // Trigger module viewed event.
  916. $event = \mod_iassign\event\submission_created::create(array(
  917. 'objectid' => $this->iassign->id,
  918. 'context' => $this->context
  919. ));
  920. $event->add_record_snapshot('course', $this->course);
  921. $event->trigger();
  922. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  923. }
  924. } elseif ($iassign_submission->status != 3) {
  925. $newentry = new stdClass();
  926. $newentry->id = $iassign_submission->id;
  927. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  928. $newentry->userid = $iassign_submission->userid;
  929. $newentry->timecreated = $iassign_submission->timecreated;
  930. $newentry->timemodified = $timenow;
  931. $newentry->answer = $iLM_PARAM_ArchiveContent;
  932. $newentry->grade = round($grade_student, 2);
  933. $newentry->status = $status;
  934. $newentry->experiment = $iassign_submission->experiment + 1;
  935. if (!$DB->update_record("iassign_submission", $newentry)) {
  936. print_error('error_update', 'iassign');
  937. //D depurar...
  938. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  939. //D $fp = fopen("teste1.txt","w");
  940. //D fwrite($fp,$stringAux);
  941. } else {
  942. // Trigger module viewed event.
  943. $event = \mod_iassign\event\submission_updated::create(array(
  944. 'objectid' => $this->iassign->id,
  945. 'context' => $this->context
  946. ));
  947. $event->add_record_snapshot('course', $this->course);
  948. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  949. }
  950. } else {
  951. if ($return_get_answer == 1) {
  952. $newentry = new stdClass();
  953. $newentry->id = $iassign_submission->id;
  954. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  955. $newentry->userid = $iassign_submission->userid;
  956. $newentry->timecreated = $iassign_submission->timecreated;
  957. $newentry->timemodified = $timenow;
  958. $newentry->answer = $iLM_PARAM_ArchiveContent;
  959. $newentry->grade = round($grade_student, 2);
  960. $newentry->status = $status;
  961. $newentry->experiment = $iassign_submission->experiment + 1;
  962. if (!$DB->update_record("iassign_submission", $newentry))
  963. print_error('error_update', 'iassign');
  964. else {
  965. $event = \mod_iassign\event\submission_updated::create(array(
  966. 'objectid' => $this->iassign->id,
  967. 'context' => $this->context
  968. ));
  969. $event->add_record_snapshot('course', $this->course);
  970. $event->trigger();
  971. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  972. print $OUTPUT->box_start();
  973. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  974. print $OUTPUT->box_end();
  975. }
  976. } elseif ($return_get_answer == 2) {
  977. print $OUTPUT->box_start();
  978. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  979. print $OUTPUT->box_end();
  980. } else {
  981. print $OUTPUT->box_start();
  982. print "
  983. <script type='text/javascript'>
  984. //<![CDATA[
  985. function overwrite () {
  986. document.formEnvio.return_get_answer.value = 1;
  987. document.formEnvio.submit();
  988. }
  989. function nooverwrite () {
  990. document.formEnvio.return_get_answer.value = 2;
  991. document.formEnvio.submit();
  992. }
  993. //]]>
  994. </script>";
  995. $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;
  996. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  997. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  998. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  999. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1000. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1001. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1002. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1003. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1004. <input type='hidden' name='return_get_answer'/> ";
  1005. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1006. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1007. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1008. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1009. print " </form>";
  1010. print $OUTPUT->box_end();
  1011. }
  1012. }
  1013. } // if ($this->write_solution == 1)
  1014. print $OUTPUT->footer();
  1015. die();
  1016. } // function get_answer()
  1017. /// Export in file the answer of student.
  1018. function export_file_answer () {
  1019. global $DB;
  1020. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1021. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1022. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1023. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1024. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1025. $extensions = explode(",", $iassign_ilm->extension);
  1026. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1027. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1028. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1029. header("Pragma: public");
  1030. header("Expires: 0");
  1031. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1032. header("Cache-Control: private", false);
  1033. header("Content-Type: document/unknown");
  1034. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1035. set_time_limit(0);
  1036. print($iassign_submission->answer);
  1037. exit;
  1038. } // function export_file_answer()
  1039. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1040. // @calledby $this->export_package_answer()
  1041. //TODO Precisa terminar! //TODO_HTML
  1042. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1043. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1044. <head>
  1045. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1046. $str_html .= " </head>
  1047. <body>\n";
  1048. $tam = sizeof($array_iassign_name);
  1049. for ($ii=0; $ii<$tam; $ii++) {
  1050. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1051. }
  1052. $str_html .= "
  1053. </body>\n</html>";
  1054. return $str_html;
  1055. }
  1056. /// Export an package (zip) with all answer of students
  1057. // @calledby $this->action()
  1058. function export_package_answer () {
  1059. global $DB, $CFG, $OUTPUT;
  1060. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1061. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1062. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1063. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1064. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1065. $userid = optional_param('userid', NULL, PARAM_INT);
  1066. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1067. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1068. //TODO_HTML echo "username=$username<br/>"; exit;
  1069. $current_date = date('Y_m_d_H');
  1070. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1071. // If temporary directory under Moodle data does not exists => create it
  1072. if (!is_dir($diretorio)) {
  1073. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1074. // created directory with permissions to be seen by everyone
  1075. }
  1076. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1077. if (!is_writable($diretorio)) { // send a highlighted message!
  1078. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1079. exit; // just in case
  1080. }
  1081. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1082. $zip = new zip_archive(); // create ZIP
  1083. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1084. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1085. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1086. $vet_student_filename = array();
  1087. $vet_student_content = array();
  1088. foreach ($iassign_statements as $iassign_statement) {
  1089. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1090. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1091. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1092. $extensions = explode(",", $iassign_ilm->extension);
  1093. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1094. if ($iassign_submission) {
  1095. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1096. $student_content = $iassign_submission->answer;
  1097. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1098. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1099. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1100. if ($resp) {
  1101. $vet_student_filename[] = $student_filename;
  1102. $vet_student_content[] = $student_content;
  1103. }
  1104. else { // send a highlighted message!
  1105. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1106. exit; // just in case
  1107. }
  1108. }
  1109. }
  1110. $zip->close(); // close the ZIP file
  1111. if (count($vet_student_filename)>0) {
  1112. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1113. $result_tf = $vet_result[0];
  1114. $filenameZip = $vet_result[1]->filename;
  1115. }
  1116. iassign_utils::download_file($zip_filename); // download the ZIP file
  1117. exit;
  1118. } // function export_package_answer()
  1119. /// Editing status of interactive activities
  1120. function edit_status () {
  1121. global $USER, $DB, $OUTPUT;
  1122. $newentry = new stdClass();
  1123. $newentry->id = $this->iassign_submission_current;
  1124. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1125. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1126. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1127. $newentry->status = $iassign_submission->status;
  1128. $newentry->teacher = $USER->id;
  1129. if (!$DB->update_record('iassign_submission', $newentry))
  1130. print_error('error_update', 'iassign');
  1131. else {
  1132. // Trigger module viewed event.
  1133. $event = \mod_iassign\event\submission_updated::create(array(
  1134. 'objectid' => $this->iassign->id,
  1135. 'context' => $this->context
  1136. ));
  1137. $event->add_record_snapshot('course', $this->course);
  1138. $event->trigger();
  1139. $this->action = 'viewsubmission';
  1140. $this->view_iassign_current();
  1141. } // if (!$DB->update_record('iassign_submission', $newentry))
  1142. } // function edit_status()
  1143. /// Editing grade of interactive activities
  1144. function edit_grade () {
  1145. global $USER, $DB, $OUTPUT;
  1146. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1147. if ($newgrade && $newgrade >= 0) {
  1148. $newentry = new stdClass();
  1149. $newentry->id = $this->iassign_submission_current;
  1150. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1151. $newentry->teacher = $USER->id;
  1152. if (!$DB->update_record('iassign_submission', $newentry))
  1153. print_error('error_update', 'iassign');
  1154. else {
  1155. // Trigger module viewed event.
  1156. $event = \mod_iassign\event\submission_updated::create(array(
  1157. 'objectid' => $this->iassign->id,
  1158. 'context' => $this->context
  1159. ));
  1160. $event->add_record_snapshot('course', $this->course);
  1161. $event->trigger();
  1162. }
  1163. } // if ($newgrade >= 0)
  1164. $this->action = 'viewsubmission';
  1165. $this->view_iassign_current();
  1166. }
  1167. /// Add or Edit interactive activities
  1168. // @calledby $this->action()
  1169. function add_edit_iassign () {
  1170. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1171. require_once('iassign_form.php');
  1172. $id = $this->cm->id;
  1173. $iassignid = $this->iassign->id;
  1174. $param = new stdClass();
  1175. $param->action = $this->action; // oculto
  1176. $param->id = $id; // oculto
  1177. $COURSE->cm = $id;
  1178. $COURSE->iassignid = $iassignid;
  1179. $COURSE->iassign_file_id = NULL;
  1180. $context = context_module::instance($this->cm->id);
  1181. $contextuser = context_user::instance($USER->id);
  1182. $component = 'mod_iassign';
  1183. $filearea = 'exercise';
  1184. if (!empty($this->iassign_current))
  1185. $COURSE->iassign_id = $this->iassign_current;
  1186. else
  1187. $COURSE->iassign_id = 0;
  1188. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1189. if ($this->action == 'add') {
  1190. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1191. $params = array('iassignid' => $iassignid);
  1192. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1193. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1194. $total_of_activities = count($iassign_statement);
  1195. $param->iassignid = $iassignid;
  1196. $param->name = "";
  1197. $param->oldname = "";
  1198. $param->type_iassign = 3;
  1199. $param->proposition = "";
  1200. $author = $DB->get_record("user", array("id" => $USER->id));
  1201. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1202. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1203. $param->author = $param->author_name;
  1204. $param->author_modified = $param->author_modified_name;
  1205. $COURSE->iassign_list = array();
  1206. $param->iassign_list = array();
  1207. if ($iassign_statement) {
  1208. foreach ($iassign_statement as $iassign) {
  1209. $iassignid = $iassign->id;
  1210. $param->iassign_list[$iassignid] = 0;
  1211. $COURSE->iassign_list[$iassignid] = new stdClass();
  1212. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1213. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1214. $COURSE->iassign_list[$iassignid]->enable = 1;
  1215. } // foreach ($iassign_statement as $iassign)
  1216. }
  1217. $param->iassign_ilmid = 0;
  1218. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1219. $param->file = 0;
  1220. $param->fileold = 0;
  1221. $param->filename = "";
  1222. $param->grade = $iassign_data->grade;
  1223. $param->timemodified = time();
  1224. $param->timecreated = time();
  1225. $param->timeavailable = $iassign_data->timeavailable;
  1226. $param->timedue = $iassign_data->timedue;
  1227. $param->preventlate = $iassign_data->preventlate;
  1228. $param->test = $iassign_data->test;
  1229. $param->special_param1 = 0;
  1230. $param->visible = 1;
  1231. $param->max_experiment = $iassign_data->max_experiment;
  1232. $param->dependency = 0;
  1233. $param->automatic_evaluate = 1;
  1234. $param->show_answer = 1;
  1235. } // if ($this->action == 'add')
  1236. elseif ($this->action == 'edit') {
  1237. $COURSE->iassign_list = array();
  1238. $this_activity = $this->activity->get_activity();
  1239. if ($this_activity != null) {
  1240. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1241. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1242. $param->iassign_id = $iassign_statement_current->id; // oculto
  1243. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1244. $param->name = $iassign_statement_current->name;
  1245. $param->oldname = $iassign_statement_current->name;
  1246. $param->type_iassign = $iassign_statement_current->type_iassign;
  1247. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1248. //2019 $param->proposition = $iassign_statement_current->proposition;
  1249. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1250. $param->author_name = $iassign_statement_current->author_name; // oculto
  1251. $param->author = $iassign_statement_current->author_name;
  1252. $author = $DB->get_record("user", array('id' => $USER->id));
  1253. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1254. $param->author_modified = $param->author_modified_name;
  1255. $dependency = explode(';', $iassign_statement_current->dependency);
  1256. $param->iassign_list = array();
  1257. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1258. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1259. $array_dependency = array();
  1260. $subdependency = "";
  1261. $sub_subdependency = "";
  1262. // dependent on this exercise
  1263. if ($iassign_statement_dependency) {
  1264. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1265. // to whom this exercise depends
  1266. foreach ($inter as $tmp)
  1267. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1268. $list_dependency = $subdependency . $sub_subdependency;
  1269. $array_dependency = explode(";", $list_dependency);
  1270. }
  1271. // Get all activity with the same iLM - iassignid
  1272. $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";
  1273. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1274. $total_of_activities = count($all_others_iassign_statement) + 1;
  1275. $inter = array();
  1276. if ($all_others_iassign_statement) {
  1277. foreach ($all_others_iassign_statement as $iassign)
  1278. if (in_array($iassign->id, $dependency))
  1279. $inter[] = $iassign->id;
  1280. }
  1281. if ($all_others_iassign_statement) {
  1282. foreach ($all_others_iassign_statement as $iassign) {
  1283. $iassignid = $iassign->id;
  1284. $COURSE->iassign_list[$iassignid] = new stdClass();
  1285. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1286. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1287. if (in_array($iassignid, $dependency))
  1288. $param->iassign_list[$iassignid] = 1;
  1289. else
  1290. $param->iassign_list[$iassignid] = 0;
  1291. if (in_array($iassignid, $array_dependency))
  1292. $COURSE->iassign_list[$iassignid]->enable = 0;
  1293. else
  1294. $COURSE->iassign_list[$iassignid]->enable = 1;
  1295. } // foreach ($all_others_iassign_statement as $iassign)
  1296. }
  1297. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1298. $param->fileold = 0;
  1299. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1300. $param->filename = '';
  1301. $param->grade = $iassign_statement_current->grade;
  1302. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1303. $param->timeavailable = $iassign_statement_current->timeavailable;
  1304. $param->timedue = $iassign_statement_current->timedue;
  1305. $param->preventlate = $iassign_statement_current->preventlate;
  1306. $param->test = $iassign_statement_current->test;
  1307. $param->special_param1 = $iassign_statement_current->special_param1;
  1308. $param->position = $iassign_statement_current->position; // oculto
  1309. $param->visible = $iassign_statement_current->visible;
  1310. $param->max_experiment = $iassign_statement_current->max_experiment;
  1311. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1312. $param->show_answer = $iassign_statement_current->show_answer;
  1313. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1314. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1315. if ($files) {
  1316. foreach ($files as $file) {
  1317. if ($file->get_filename() != '.') {
  1318. $param->filename = $file->get_filename();
  1319. $param->file = $file->get_id();
  1320. $param->fileold = $file->get_id();
  1321. $COURSE->iassign_file_id = $file->get_id();
  1322. }
  1323. }
  1324. }
  1325. //TODO //MOOC2014 -- inicio
  1326. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1327. //D if ($iassign_ilm_configs) {
  1328. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1329. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1330. //D } //MOOC2014 -- fim
  1331. } // if ($this_activity != null)
  1332. } // elseif ($this->action == 'edit')
  1333. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1334. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1335. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1336. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1337. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1338. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1339. $param->position = $total_of_activities;
  1340. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1341. $mform->set_data($param);
  1342. if ($mform->is_cancelled()) {
  1343. $this->return_home_course('iassign_cancel');
  1344. exit;
  1345. }
  1346. else { // if ($mform->is_cancelled())
  1347. $result = $mform->get_data();
  1348. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1349. if ($result) {
  1350. $result->context = $context;
  1351. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1352. $result->grade = 0;
  1353. if ($result->type_iassign == 1) {
  1354. $result->automatic_evaluate = 0;
  1355. $result->show_answer = 0;
  1356. }
  1357. elseif ($result->automatic_evaluate == 0)
  1358. $result->show_answer = 0;
  1359. // $_POST['iassign_list']
  1360. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1361. if ($result->iassign_list) {
  1362. foreach ($result->iassign_list as $key => $value)
  1363. $result->dependency .= $key . ';';
  1364. }
  1365. else
  1366. $result->dependency = 0;
  1367. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1368. //TODO Then get it directly from the form data $_POST!
  1369. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1370. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1371. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1372. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1373. if ($this->action == 'add') {
  1374. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1375. if ($iassign_statement_name) {
  1376. $this->return_home_course('error_iassign_name');
  1377. die();
  1378. }
  1379. // Really insert the new iActivity in table '*_iassign_statement'
  1380. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1381. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1382. // Trigger module viewed event.
  1383. $event = \mod_iassign\event\iassign_created::create(array(
  1384. 'objectid' => $iassignid,
  1385. 'context' => $context
  1386. ));
  1387. $event->add_record_snapshot('course', $this->course);
  1388. $event->trigger();
  1389. $this->return_home_course('iassign_add');
  1390. } // if ($this->action == 'add')
  1391. elseif ($this->action == 'edit') {
  1392. $iassignid = $this->activity->update_iassign($result);
  1393. $this->activity->update_calendar($iassignid, $result->oldname);
  1394. // Trigger module viewed event.
  1395. $event = \mod_iassign\event\iassign_updated::create(array(
  1396. 'objectid' => $iassignid,
  1397. 'context' => $context
  1398. ));
  1399. $event->add_record_snapshot('course', $this->course);
  1400. $event->trigger();
  1401. $this->return_home_course('iassign_update');
  1402. } // elseif ($this->action == 'edit')
  1403. die();
  1404. } // if ($result)
  1405. } // else if ($mform->is_cancelled())
  1406. print $OUTPUT->header();
  1407. $mform->display();
  1408. print $OUTPUT->footer();
  1409. die();
  1410. } // function add_edit_iassign()
  1411. /// Search for dependencies
  1412. function search_dependency ($search_iassing_id, $iassign_statement) {
  1413. global $DB, $OUTPUT;
  1414. $dependency = "";
  1415. if ($iassign_statement)
  1416. foreach ($iassign_statement as $iassign) {
  1417. $inter_dependency = explode(';', $iassign->dependency);
  1418. if (in_array($search_iassing_id, $inter_dependency)) {
  1419. $dependency .= $iassign->id . ";";
  1420. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1421. } // if (in_array($search_iassing_id, $inter_dependency))
  1422. } // foreach ($iassign_statement as $iassign)
  1423. return $dependency;
  1424. }
  1425. /// Search for "sub"dependency
  1426. function search_sub_dependency ($search_iassing_id) {
  1427. global $DB, $OUTPUT;
  1428. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1429. $dependency = "";
  1430. if ($iassign_statement) {
  1431. $inter_dependency = explode(';', $iassign_statement->dependency);
  1432. foreach ($inter_dependency as $tmp) {
  1433. if ($tmp != 0)
  1434. $dependency .= $tmp . ";";
  1435. $dependency .= $this->search_sub_dependency($tmp);
  1436. } // foreach ($inter_dependency as $tmp)
  1437. } // if ($iassign_statement)
  1438. return $dependency;
  1439. }
  1440. // Warning message
  1441. static function warning_message_iassign ($strcode) {
  1442. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1443. }
  1444. /// Update grade of iAssign
  1445. // Called always any iAssign activity is created
  1446. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1447. static function update_grade_iassign ($iassignid) {
  1448. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1449. require_once($CFG->libdir . '/gradelib.php');
  1450. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1451. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1452. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1453. // Each iAssign item is associated with one item on the "gradebook"
  1454. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1455. //$sum_grade = 0;
  1456. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1457. //foreach($grade as $tmp) {
  1458. // $sum_grade += $tmp->grade;
  1459. // }
  1460. //1 Solution 1
  1461. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1462. //1 $sum_grade = 0; //1
  1463. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1464. //2 Solution 2
  1465. $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
  1466. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1467. if (key($array_sum_grade))
  1468. $sum_grade = key($array_sum_grade); //2
  1469. else
  1470. $sum_grade = 0; //2
  1471. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1472. $grades = NULL;
  1473. $params = array('itemname' => $grade_iassign->name);
  1474. $params['iteminstance'] = $iassignid;
  1475. $params['gradetype'] = GRADE_TYPE_VALUE;
  1476. //2016 if ($sum_grade != 0) {
  1477. $params['grademax'] = $sum_grade;
  1478. $params['rawgrademax'] = $sum_grade;
  1479. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1480. $params['grademin'] = 0;
  1481. // @calls /lib/gradelib.php: call to grade_item->insert()
  1482. //TODO: is there any error here in Moodle version 3.0?
  1483. //TODO: Incorrect property 'grademax' found when inserting grade object
  1484. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1485. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1486. }
  1487. /// Update grade of student
  1488. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1489. global $CFG, $DB, $OUTPUT;
  1490. require_once($CFG->libdir . '/gradelib.php');
  1491. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1492. // Review all the student submission for this iAssign activity
  1493. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1494. $total_grade = 0;
  1495. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1496. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1497. if ($iassign_submission)
  1498. $total_grade += $iassign_submission->grade;
  1499. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1500. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1501. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1502. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1503. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1504. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1505. $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
  1506. if (key($array_sum_grade))
  1507. $sum_grade = key($array_sum_grade); //2
  1508. else
  1509. $sum_grade = 0; //2
  1510. $grades['userid'] = $userid;
  1511. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1512. $params = array('itemname' => $grade_iassign->name);
  1513. $params['iteminstance'] = $iassignid;
  1514. $params['gradetype'] = GRADE_TYPE_VALUE;
  1515. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1516. $params['grademax'] = $sum_grade;
  1517. $params['rawgrademax'] = $sum_grade;
  1518. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1519. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1520. }
  1521. /// Display caption of icons
  1522. function view_legend_icons () {
  1523. global $USER, $CFG, $DB, $OUTPUT;
  1524. $id = $this->cm->id;
  1525. if ($this->action == 'print')
  1526. print '<table border=1 width=100%><tr>';
  1527. else
  1528. print '<table width=100%><tr>';
  1529. print '<td >';
  1530. if ($this->action != 'print')
  1531. print $OUTPUT->help_icon('legend', 'iassign');
  1532. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1533. // $imagetext = '');
  1534. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1535. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1536. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1537. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1538. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1539. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1540. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1541. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1542. print '</td>' . "\n";
  1543. if ($this->action != 'print') {
  1544. $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>";
  1545. $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>";
  1546. $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>";
  1547. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1548. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1549. print '<td width=15% align="right">' . $link_export . '</td>' . "\n";
  1550. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1551. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1552. } // if ($this->action != 'print')
  1553. print '</tr></table>' . "\n";
  1554. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1555. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1556. $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>";
  1557. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1558. print '</tr></table>' . "\n";
  1559. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1560. else
  1561. print '</td></tr></table>' . "\n";
  1562. } // function view_legend_icons()
  1563. /// Display activity current
  1564. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1565. function view_iassign_current () {
  1566. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1567. $id = $this->cm->id;
  1568. $iassignid = $this->iassign->id;
  1569. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1570. $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
  1571. // 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 ...
  1572. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1573. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  1574. $ilm_name = '';
  1575. if ($ilm->ilm)
  1576. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  1577. // 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
  1578. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  1579. // log record
  1580. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  1581. //Trigger module viewed event.
  1582. $event = \mod_iassign\event\submission_viewed::create(array(
  1583. 'objectid' => $iassign->id,
  1584. 'context' => $this->context,
  1585. 'other' => $info
  1586. ));
  1587. $event->add_record_snapshot('course', $this->course);
  1588. $event->trigger();
  1589. // Search of iLM data used in the current activity
  1590. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  1591. // Add actual activity to navbar:
  1592. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  1593. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  1594. print $OUTPUT->header();
  1595. if ($this->action == 'viewsubmission') {
  1596. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  1597. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  1598. else
  1599. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1600. } else {
  1601. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1602. }
  1603. if ($iassign_submission)
  1604. $this->update_comment($iassign_submission->id);
  1605. $file = $iassign_statement_activity_item->file;
  1606. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  1607. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  1608. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  1609. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  1610. $this->bottonPost = 0; // hide submit button
  1611. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  1612. $this->view_iassign = false; // disable visualization of activity
  1613. $repeat = "";
  1614. $last_iassign = "";
  1615. $student_answer = "";
  1616. $comment = "";
  1617. // *** Teacher access (view learner's submission)
  1618. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1619. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  1620. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  1621. // ---> access teacher for test
  1622. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  1623. $this->bottonPost = 1;
  1624. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  1625. $this->activity->view_dates();
  1626. $USER->iassignEdit = $this->bottonPost;
  1627. $this->activity->show_info_iassign();
  1628. if ($iassign_submission) {
  1629. //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;
  1630. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1631. } else {
  1632. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1633. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  1634. }
  1635. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1636. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  1637. // Prepare tags to present the iLM
  1638. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  1639. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1640. // *** (end) Teacher access (view the activity)
  1641. // *** Teacher access (view learner's submission to the activity)
  1642. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  1643. // It is teacher or 'nonediting teacher' that can evaluate
  1644. // ----> area teacher evaluate
  1645. $row = optional_param('row', 0, PARAM_INT);
  1646. $column = optional_param('column', 0, PARAM_INT);
  1647. $link_next = iassign_icons::insert('right_disable');
  1648. $link_previous = iassign_icons::insert('left_disable');
  1649. $link_up = iassign_icons::insert('up_disable');
  1650. $link_down = iassign_icons::insert('down_disable');
  1651. // next_activity
  1652. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  1653. $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);
  1654. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  1655. }
  1656. // previous_activity
  1657. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  1658. $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);
  1659. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  1660. }
  1661. // previous_student
  1662. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  1663. $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);
  1664. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  1665. }
  1666. // next_student
  1667. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  1668. $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);
  1669. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  1670. }
  1671. if ($iassign_submission) {
  1672. $student_answer = $iassign_submission->answer;
  1673. }
  1674. $last_iassign = get_string('last_iassign', 'iassign');
  1675. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  1676. // Messages related to due date (and user role)
  1677. $this->activity->view_dates();
  1678. print $OUTPUT->box_start();
  1679. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1680. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  1681. print $OUTPUT->user_picture($user_data);
  1682. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  1683. print '</td>' . "\n";
  1684. print '<td width=20% align=right>' . "\n";
  1685. print '<table width=50 cellpadding="0">';
  1686. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  1687. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  1688. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  1689. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  1690. print '</table>' . "\n";
  1691. print '</td></tr></table>' . "\n";
  1692. print $OUTPUT->box_end();
  1693. print $OUTPUT->box_start();
  1694. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  1695. print '<td width=60% valign="top">' . "\n";
  1696. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1697. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1698. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  1699. $resp = get_string('yes');
  1700. else
  1701. $resp = get_string('no');
  1702. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1703. if ($iassign_statement_activity_item->show_answer == 1)
  1704. $resp = get_string('yes');
  1705. else
  1706. $resp = get_string('no');
  1707. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  1708. print '</td>';
  1709. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1710. print '<td width=40% valign="top" align="left">';
  1711. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1712. // check status of solution sent by the student
  1713. if ($iassign_submission) {
  1714. switch ($iassign_submission->status) {
  1715. case 3 :
  1716. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1717. break;
  1718. case 2 :
  1719. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1720. break;
  1721. case 1 :
  1722. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1723. break;
  1724. default :
  1725. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1726. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1727. } // switch ($iassign_submission->status)
  1728. }
  1729. else { // if ($iassign_submission)
  1730. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1731. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  1732. }
  1733. // update_status
  1734. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1735. $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);
  1736. print " <script type='text/javascript'>
  1737. //<![CDATA[
  1738. function overwriteStatus (newstatus) {
  1739. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  1740. document.formEditStatus.return_status.value=newstatus;
  1741. document.formEditStatus.submit();
  1742. }
  1743. else
  1744. document.formEditStatus.return_status.value=-1;
  1745. }
  1746. //]]>
  1747. </script>";
  1748. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  1749. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  1750. 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";
  1751. print " <input type='hidden' name='return_status'>\n";
  1752. print "</form>\n";
  1753. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  1754. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  1755. $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);
  1756. print "
  1757. <script type='text/javascript'>
  1758. //<![CDATA[
  1759. function overwriteGrade (newgrade,maxgrade) {
  1760. if (newgrade<0 || newgrade>maxgrade) {
  1761. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  1762. document.formEditGrade.return_grade.value=-1;
  1763. document.formEditGrade.submit();
  1764. }
  1765. else {
  1766. document.formEditGrade.return_grade.value=newgrade;
  1767. document.formEditGrade.submit();
  1768. }
  1769. }
  1770. //]]>
  1771. </script>";
  1772. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  1773. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  1774. print " <input type='text' name='grade' size='6'>";
  1775. print " <input type='hidden' name='return_grade'> ";
  1776. 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";
  1777. print "</form>";
  1778. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  1779. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  1780. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  1781. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  1782. if ($teacher)
  1783. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  1784. } // if ($iassign_submission->experiment > 0)
  1785. print '</td>';
  1786. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1787. print '</tr></table>';
  1788. print $OUTPUT->box_end();
  1789. $USER->iassignEdit = $this->bottonPost;
  1790. if ($iassign_submission && $allow_resubmission) {
  1791. // Put the iLM to
  1792. print $OUTPUT->box_start();
  1793. print '<p><strong>' . $last_iassign . '</strong></p>';
  1794. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  1795. $enderecoPOST = "";
  1796. // Prepare tags to present the iLM
  1797. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  1798. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  1799. print $OUTPUT->box_end();
  1800. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  1801. // ATTENTION: exception used by iGeom (exercise with "script")
  1802. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  1803. if (substr($ilm_name, 0, 5)=="igeom") {
  1804. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  1805. $loadTeacherActivity = true;
  1806. }
  1807. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  1808. if (!isset($enderecoPOST)) $enderecoPOST = "";
  1809. // Prepare tags to present the iLM
  1810. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  1811. }
  1812. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  1813. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1814. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  1815. //2020 Foi para final dessa funcao 'view_iassign_current()'
  1816. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  1817. // *** (end) Teacher access (view learner's submission to the activity)
  1818. // *** Student access (view the activity)
  1819. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  1820. // It could be the learner (he could send or resend the activity)
  1821. // ---> access student
  1822. $time_now = time();
  1823. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  1824. // activity of type example - not submit button for submission
  1825. $this->view_iassign = true;
  1826. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  1827. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  1828. // activity of type test - iLM automatic evaluator - submit button for submission
  1829. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  1830. $this->bottonPost = 1;
  1831. $this->view_iassign = true;
  1832. } else
  1833. $this->view_iassign = false;
  1834. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  1835. // activity of type exercise (learner can send his answer, if yet open...)
  1836. $this->view_iassign = true;
  1837. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  1838. $this->view_iassign = false;
  1839. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  1840. $this->bottonPost = 1; // allow the submit button
  1841. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  1842. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  1843. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  1844. if (!$iassign_submission) {
  1845. $str_iassign_submission_id = '';
  1846. $str_iassign_submission_answer = '';
  1847. }
  1848. else {
  1849. $str_iassign_submission_id = $iassign_submission->id;
  1850. $str_iassign_submission_answer = $iassign_submission->answer;
  1851. }
  1852. if ($this->action != 'repeat') {
  1853. $repeat = "<a href='view.php?action=repeat&id="
  1854. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  1855. . $this->activity->get_activity()->id . "&iassign_submission_current="
  1856. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  1857. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1858. }
  1859. $this->bottonPost = 1;
  1860. $this->write_solution = 1; // can register his submission
  1861. $student_answer = $str_iassign_submission_answer;
  1862. }
  1863. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  1864. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  1865. $last_iassign = get_string('last_iassign', 'iassign');
  1866. if ($iassign_submission) {
  1867. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1868. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1869. $student_answer = $iassign_submission->answer;
  1870. } else {
  1871. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1872. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1873. }
  1874. }
  1875. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  1876. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  1877. $this->bottonPost = 1;
  1878. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  1879. } else {
  1880. $last_iassign = get_string('last_iassign', 'iassign');
  1881. if ($iassign_submission) {
  1882. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1883. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1884. $student_answer = $iassign_submission->answer;
  1885. } else {
  1886. // Symbol of "redo activity"
  1887. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  1888. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  1889. }
  1890. }
  1891. } // elseif ($iassign_statement_activity_item->test == 1)
  1892. elseif ($iassign_statement_activity_item->test == 0)
  1893. $this->view_iassign = false;
  1894. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  1895. if ($iassign_submission)
  1896. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  1897. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1898. else
  1899. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  1900. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1901. $this->activity->view_dates();
  1902. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  1903. print $OUTPUT->box_start();
  1904. print '<table width=100% border=0 valign="top">' . "\n";
  1905. print '<tr><td width=60% valign="top">' . "\n";
  1906. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  1907. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  1908. $flag_dependency = true;
  1909. if ($iassign_statement_activity_item->type_iassign == 3) {
  1910. if ($iassign_statement_activity_item->dependency == 0) {
  1911. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  1912. } else {
  1913. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  1914. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  1915. foreach ($dependencys as $dependency) {
  1916. if ($dependency) {
  1917. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  1918. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  1919. if ($dependencysubmissions) {
  1920. if ($dependencysubmissions->status == 3)
  1921. $icon = iassign_icons::insert('correct');
  1922. elseif ($dependencysubmissions->status == 2) {
  1923. $icon = iassign_icons::insert('incorrect');
  1924. $flag_dependency = false;
  1925. } elseif ($dependencysubmissions->status == 1) {
  1926. $icon = iassign_icons::insert('post');
  1927. $flag_dependency = false;
  1928. } elseif ($dependencysubmissions->status == 0) {
  1929. $icon = iassign_icons::insert('not_post');
  1930. $flag_dependency = false;
  1931. }
  1932. } else {
  1933. $icon = iassign_icons::insert('not_post');
  1934. $flag_dependency = false;
  1935. } // if ($dependencysubmissions)
  1936. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  1937. } // if ($dependency)
  1938. } // foreach ($dependencys as $dependency)
  1939. } // if ($iassign_statement_activity_item->dependency == 0)
  1940. } // if ($iassign_statement_activity_item->type_iassign == 3)
  1941. if ($flag_dependency == false) {
  1942. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  1943. $this->view_iassign = false;
  1944. print '</tr></table>' . "\n";
  1945. }
  1946. else {
  1947. $this->view_iassign = true;
  1948. print '</td>' . "\n";
  1949. } // if ($flag_dependency == false)
  1950. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  1951. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  1952. // receiver=1 - message to teacher
  1953. // receiver=2 - message to student
  1954. if ($iassign_submission) {
  1955. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  1956. if ($verify_message)
  1957. $comment = iassign_icons::insert('comment_unread');
  1958. }
  1959. print '<td width=40% valign="top" align="left">';
  1960. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  1961. if ($iassign_statement_activity_item->show_answer == 1) {
  1962. // check status of solution sent by the student
  1963. if ($iassign_submission) {
  1964. switch ($iassign_submission->status) {
  1965. case 3 :
  1966. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  1967. break;
  1968. case 2 :
  1969. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  1970. break;
  1971. case 1 :
  1972. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  1973. break;
  1974. default :
  1975. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1976. $repeat = "";
  1977. $last_iassign = "";
  1978. } // switch ($iassign_submission->status)
  1979. } else {
  1980. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  1981. $repeat = "";
  1982. $last_iassign = "";
  1983. }
  1984. if ($iassign_submission && $iassign_submission->experiment > 0) {
  1985. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  1986. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  1987. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  1988. if ($iassign_statement_activity_item->max_experiment == 0)
  1989. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  1990. else {
  1991. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  1992. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  1993. $repeat = "";
  1994. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  1995. $this->bottonPost = 0;
  1996. $this->write_solution = 0;
  1997. }
  1998. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  1999. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2000. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2001. if ($teacher)
  2002. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2003. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2004. } // if ($iassign_statement_activity_item->show_answer==1)
  2005. else {
  2006. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2007. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2008. $repeat = "";
  2009. $last_iassign = "";
  2010. } elseif ($iassign_submission->status == 1) {
  2011. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2012. }
  2013. }
  2014. print '</td>';
  2015. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2016. print '</tr></table>' . "\n";
  2017. // Presents the iLM
  2018. print '<table width=100% border=0 valign="top">' . "\n";
  2019. print '<td width=80% align="left">';
  2020. 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\".
  2021. print '<td width=20% align="rigth">';
  2022. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2023. print $repeat; // symbol of "redo activity"
  2024. print '</td></tr></table>' . "\n";
  2025. //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)'
  2026. $output = '';
  2027. if (!$iassign_ilm) {
  2028. $iassign_ilm = new stdClass();
  2029. $iassign_ilm->file_jar = "";
  2030. }
  2031. $output .= $OUTPUT->box_start();
  2032. $USER->iassignEdit = $this->bottonPost;
  2033. // ---
  2034. // Presents the iLM
  2035. // Prepare tags to present the iLM
  2036. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2037. $student_answer = ""; //?
  2038. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2039. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2040. $student_answer = "";
  2041. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2042. } else {
  2043. // When student is redoing his activity
  2044. // ATTENTION: exception used by iGeom (exercise with "script")
  2045. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2046. if (substr($ilm_name, 0, 5)=="igeom") {
  2047. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2048. $loadTeacherActivity = true;
  2049. }
  2050. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2051. }
  2052. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2053. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2054. //1 $history_comment = '';
  2055. //1 if ($iassign_submission) {
  2056. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2057. //1 }
  2058. //1 if (!empty($history_comment)) {
  2059. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2060. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2061. //1 $output .= $history_comment;
  2062. //1 $output .= "</table>\n";
  2063. //1 }
  2064. //1 $output .= "</form></center>\n";
  2065. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2066. //1 }
  2067. $output .= $OUTPUT->box_end();
  2068. print $output;
  2069. } // if ($this->view_iassign)
  2070. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2071. } // if ($this->view_iassign)
  2072. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2073. else
  2074. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2075. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2076. print '<table width=100% border=0 valign="top">' . "\n";
  2077. print '<tr><td width=60% valign="top">' . "\n";
  2078. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2079. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2080. print '</tr></table>' . "\n";
  2081. $student_answer = "";
  2082. $enderecoPOST = "";
  2083. // Prepare tags to present the iLM
  2084. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2085. print $output;
  2086. }
  2087. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2088. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2089. if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2090. // Put a block with area to sent/answer comments
  2091. $output = '';
  2092. $history_comment = '';
  2093. $row = optional_param('row', 0, PARAM_INT);
  2094. $column = optional_param('column', 0, PARAM_INT);
  2095. if ($iassign_submission) {
  2096. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2097. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2098. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2099. }
  2100. else {
  2101. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2102. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2103. }
  2104. $output .= $OUTPUT->box_start();
  2105. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' method='post' action='$enderecoPOSTcomment' enctype='multipart/form-data'>\n";
  2106. $output .= "<p><textarea rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2107. $output .= "<p><input type=submit value='" . get_string('submit_comment', 'iassign') . "'\></p>\n";
  2108. $output .= "</form></center>\n";
  2109. if (!empty($history_comment)) {
  2110. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2111. $output .= " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2112. $output .= $history_comment;
  2113. $output .= "</table>";
  2114. }
  2115. $output .= $OUTPUT->box_end();
  2116. print $output;
  2117. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2118. // final block 'studant'
  2119. print $OUTPUT->footer();
  2120. die();
  2121. } // function view_iassign_current()
  2122. /// Export the data from performance report into CSV file format
  2123. function export_csv () {
  2124. global $USER, $CFG, $DB, $OUTPUT;
  2125. $str = "";
  2126. $fields = "student_id, student_name";
  2127. // Finding all iassign activities for the iassign:
  2128. $id = $this->cm->id;
  2129. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2130. $c = 1;
  2131. foreach ($iassign_list as $iassign) {
  2132. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2133. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2134. $c ++;
  2135. }
  2136. // Finding enrolled students:
  2137. $params = array('shortname' => 'student');
  2138. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2139. $context = context_course::instance($this->course->id);
  2140. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2141. $students = $DB->get_records_sql(
  2142. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2143. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2144. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2145. foreach ($students as $student) {
  2146. $str .= $student->userid . ',';
  2147. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2148. foreach ($iassign_list as $iassign) {
  2149. $str .= ',' . $iassign->id . ',';
  2150. $str .= '"' . $iassign->name . '",';
  2151. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2152. if ($student_submissions) {
  2153. $str .= $student_submissions->experiment . ',';
  2154. $str .= $student_submissions->grade . ',';
  2155. switch ($student_submissions->status) {
  2156. case 3:
  2157. $str .= '"correct",';
  2158. break;
  2159. case 2:
  2160. $str .= '"incorrect",';
  2161. break;
  2162. case 1:
  2163. $str .= '"post",';
  2164. break;
  2165. case 0:
  2166. $str .= '"not_post",';
  2167. break;
  2168. }
  2169. } else {
  2170. $str .= ',,"not_post",';
  2171. }
  2172. $str .= $iassign->iassign_ilmid . ',';
  2173. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2174. $str .= '"' . $ilm_activity->name . '"';
  2175. }
  2176. $str .= "\n";
  2177. }
  2178. $str = $fields . "\n" . $str;
  2179. header("Content-type: text/csv");
  2180. header("Content-disposition: attachment; filename=report.csv");
  2181. header("Pragma: no-cache");
  2182. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2183. header('Content-Length: ' . strlen($str));
  2184. header('Connection: close');
  2185. print $str;
  2186. flush();
  2187. } // function export_csv()
  2188. /// Display report of performance
  2189. function report () {
  2190. global $USER, $CFG, $DB, $OUTPUT;
  2191. $id = $this->cm->id;
  2192. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2193. if ($this->action != 'print') {
  2194. $title = get_string('report', 'iassign');
  2195. print $OUTPUT->header();
  2196. } // if ($this->action != 'print')
  2197. print $OUTPUT->box_start();
  2198. $this->view_legend_icons();
  2199. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2200. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2201. print $OUTPUT->box_end();
  2202. if ($this->action == 'print')
  2203. print '<table border=1 width="100%">' . "\n";
  2204. else
  2205. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2206. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2207. // $num = array();
  2208. $i = 1;
  2209. $num = array();
  2210. foreach ($iassign_list as $iassign) {
  2211. $test_exercise = "";
  2212. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2213. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2214. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2215. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2216. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2217. $num[$i] = new stdClass();
  2218. $num[$i]->name = $iassign->name;
  2219. $num[$i]->id = $i;
  2220. $num[$i]->iassignid = $iassign->id;
  2221. print ' <tr >' . "\n";
  2222. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2223. print "<td class=\"cell c0 actvity\">";
  2224. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2225. print ' </tr>' . "\n";
  2226. $i ++;
  2227. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2228. } // foreach ($iassign_list as $iassign)
  2229. print "</table>";
  2230. print "<p></p>";
  2231. if ($this->action == 'print')
  2232. print '<table border=1 width="100%">' . "\n";
  2233. else
  2234. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2235. $context = context_course::instance($this->course->id);
  2236. if ($i > 1) {
  2237. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2238. $params = array('shortname' => 'student');
  2239. $role = $DB->get_record_sql(
  2240. "SELECT s.id, s.shortname FROM {role} s " .
  2241. " WHERE s.shortname = :shortname", $params);
  2242. // $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");
  2243. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2244. $students = $DB->get_records_sql(
  2245. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2246. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2247. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2248. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2249. for ($j = 1; $j < $i; $j ++) {
  2250. $sum_iassign_correct[$j] = 0;
  2251. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2252. }
  2253. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2254. $sum_iassign = $j - 1;
  2255. print '</tr>' . "\n";
  2256. $total = 0;
  2257. $sum_student = 0;
  2258. $comment = iassign_icons::insert('comment_read');
  2259. $sum_comment = 0;
  2260. $sum_correct_iassign = array();
  2261. $sum_correct_student = array();
  2262. $USER->matrix_iassign = array();
  2263. if ($students) {
  2264. $w = 0;
  2265. foreach ($students as $tmp) {
  2266. $users_array[$w] = $tmp;
  2267. $w ++;
  2268. }
  2269. for ($x = 0; $x < $w; $x ++) {
  2270. print '<tr>' . "\n";
  2271. $sum_student ++;
  2272. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2273. print ' <td >' . $name . '</td>' . "\n";
  2274. $total_student = 0;
  2275. $tentativas = 0;
  2276. for ($j = 1; $j < $i; $j ++) {
  2277. $sum_comment = 0;
  2278. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2279. print ' <td valign="bottom" align="center">' . "\n";
  2280. if ($student_submissions) {
  2281. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2282. $tentativas = $student_submissions->experiment;
  2283. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2284. $params = array('iassign_submissionid' => $student_submissions->id);
  2285. $student_submissions_comment = $DB->get_record_sql(
  2286. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2287. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2288. if ($student_submissions_comment)
  2289. foreach ($student_submissions_comment as $tmp)
  2290. $sum_comment = $tmp;
  2291. // informations to previous activities
  2292. if ($j - 1 < 1 || $j == $i)
  2293. $iassign_previous = "-1";
  2294. else
  2295. $iassign_previous = $num[$j - 1]->iassignid;
  2296. if ($x - 1 < 0 || $x == $w)
  2297. $user_previous = "-1";
  2298. else
  2299. $user_previous = $users_array[$x - 1]->userid;
  2300. // next
  2301. if ($i - 1 > $j)
  2302. $iassign_next = $num[$j + 1]->iassignid;
  2303. else
  2304. $iassign_next = "-1";
  2305. if ($w - 1 > $x)
  2306. $user_next = $users_array[$x + 1]->userid;
  2307. else
  2308. $user_next = "-1";
  2309. $position = "&row= $x&column=$j";
  2310. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2311. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2312. $url .= $position;
  2313. // receiver=1 - message to teacher
  2314. // receiver=2 - message to student
  2315. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2316. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2317. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2318. $verify_message = $DB->get_record_sql(
  2319. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2320. "WHERE iassign_submissionid = :iassign_submissionid " .
  2321. " AND return_status= :return_status " .
  2322. " AND receiver= :receiver", $params);
  2323. if ($verify_message)
  2324. foreach ($verify_message as $tmp)
  2325. $sum_verify_message = $tmp;
  2326. if ($sum_verify_message > 0)
  2327. $comment = iassign_icons::insert('comment_unread');
  2328. else
  2329. $comment = iassign_icons::insert('comment_read');
  2330. if ($student_submissions->status == 3) {
  2331. $sum_iassign_correct[$j] ++;
  2332. $total_student ++;
  2333. $feedback = iassign_icons::insert('correct');
  2334. }
  2335. elseif ($student_submissions->status == 2) {
  2336. $feedback = iassign_icons::insert('incorrect');
  2337. }
  2338. elseif ($student_submissions->status == 1) {
  2339. $feedback = iassign_icons::insert('post');
  2340. }
  2341. elseif ($student_submissions->status == 0) {
  2342. $feedback = iassign_icons::insert('not_post');
  2343. }
  2344. if ($this->action != 'print') {
  2345. print '<table><tr>';
  2346. if ($tentativas > 0)
  2347. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2348. else
  2349. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2350. print '<td> &nbsp; </td>';
  2351. print '</tr>' . "\n";
  2352. if ($sum_comment > 0 && $sum_verify_message > 0)
  2353. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2354. else if ($sum_comment > 0)
  2355. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2356. print '</table>' . "\n";
  2357. }
  2358. if ($this->action == 'print')
  2359. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2360. } // if ($student_submissions)
  2361. else { // if ($student_submissions)
  2362. // informations to browse previous activities
  2363. if ($j - 1 < 1 || $j == $i)
  2364. $iassign_previous = "-1";
  2365. else
  2366. $iassign_previous = $num[$j - 1]->iassignid;
  2367. if ($x - 1 < 0 || $x == $w)
  2368. $user_previous = "-1";
  2369. else
  2370. $user_previous = $users_array[$x - 1]->userid;
  2371. // next
  2372. if ($i - 1 > $j)
  2373. $iassign_next = $num[$j + 1]->iassignid;
  2374. else
  2375. $iassign_next = "-1";
  2376. if ($w - 1 > $x)
  2377. $user_next = $users_array[$x + 1]->userid;
  2378. else
  2379. $user_next = "-1";
  2380. $position = "&row= $x&column=$j";
  2381. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2382. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2383. $url .= $position;
  2384. $feedback = iassign_icons::insert('not_post');
  2385. if ($this->action == 'print')
  2386. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2387. else {
  2388. print '<table><tr>';
  2389. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2390. print '<td> &nbsp; </td>';
  2391. print '</tr><tr>' . "\n";
  2392. print '<td> &nbsp;</td>';
  2393. if ($sum_comment > 0)
  2394. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2395. else
  2396. print '<td> &nbsp;</td>';
  2397. print '</tr></table>';
  2398. }
  2399. } // else if ($student_submissions)
  2400. $USER->matrix_iassign[$x][$j] = new stdClass();
  2401. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2402. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2403. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2404. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2405. if ($student_submissions)
  2406. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2407. else
  2408. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2409. print '</td>' . "\n";
  2410. } // for ($j=1; $j<$i; $j++)
  2411. $total = $total + $total_student;
  2412. $porcentagem = ($total_student / ($j - 1)) * 100;
  2413. if ($tentativas != 0 && $tentativas != null) {
  2414. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2415. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2416. }
  2417. else {
  2418. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2419. }
  2420. print '</tr>' . "\n";
  2421. $sum_correct_student[$sum_student] = new stdClass();
  2422. $sum_correct_student[$sum_student]->name = $name;
  2423. $sum_correct_student[$sum_student]->sum = $total_student;
  2424. } // for ($x = 0; $x < $w; $x ++)
  2425. for ($i = 1; $i < $j; $i ++) {
  2426. if (is_null($sum_iassign_correct[$i]))
  2427. $sum_iassign_correct[$i] = 0;
  2428. $sum_correct_iassign[$i] = new stdClass();
  2429. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2430. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2431. }
  2432. // print '</tr></table>' . "\n";
  2433. }
  2434. } // if ($i>1)
  2435. else {
  2436. print_string('no_activity', 'iassign');
  2437. }
  2438. print "</table>\n";
  2439. if ($this->action != 'print')
  2440. print $OUTPUT->footer();
  2441. die();
  2442. } // function report()
  2443. /// Display graphics of performance
  2444. function stats () {
  2445. global $USER, $CFG, $DB, $OUTPUT;
  2446. $id = $this->cm->id;
  2447. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2448. if ($this->action != 'printstats')
  2449. $title = get_string('graphic', 'iassign');
  2450. $num = array();
  2451. $sum_correct_iassign = array();
  2452. $sum_correct_student = array();
  2453. $sum_student = 0;
  2454. $i = 1;
  2455. foreach ($iassign_list as $iassign) {
  2456. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2457. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2458. $sum_iassign_correct[$i] = 0;
  2459. $num[$i] = new stdClass();
  2460. $num[$i]->name = $iassign->name;
  2461. $num[$i]->id = $i;
  2462. $num[$i]->iassignid = $iassign->id;
  2463. $i ++;
  2464. } // if ($iassign->type_iassign == 3)
  2465. } // foreach ($iassign_list as $iassign)
  2466. $sum_iassign = $i - 1;
  2467. $context = context_course::instance($this->course->id);
  2468. if ($i > 1) {
  2469. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2470. $params = array('shortname' => 'student');
  2471. $role = $DB->get_record_sql(
  2472. "SELECT s.id, s.shortname FROM {role} s " .
  2473. " WHERE s.shortname = :shortname", $params);
  2474. // $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");
  2475. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2476. $students = $DB->get_records_sql(
  2477. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2478. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2479. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2480. $total = 0;
  2481. $sum_student = 0;
  2482. $j = 0;
  2483. $sum_correct_iassign = array();
  2484. $sum_correct_student = array();
  2485. $sum_experiment = array();
  2486. if ($students) {
  2487. foreach ($students as $users) {
  2488. $sum_student ++;
  2489. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2490. // rows
  2491. $total_student = 0;
  2492. for ($j = 1; $j < $i; $j ++) {
  2493. $total_experiment = 0;
  2494. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2495. if ($student_submissions) {
  2496. if ($student_submissions->status == 3) {
  2497. $sum_iassign_correct[$j] ++;
  2498. $total_student ++;
  2499. } // if ($student_submissions->status == 3)
  2500. $total_experiment += $student_submissions->experiment;
  2501. }
  2502. $sum_experiment[$j] = $total_experiment;
  2503. } // for ($j=1; $j<$i; $j++)
  2504. $total = $total + $total_student;
  2505. $sum_correct_student[$sum_student] = new stdClass();
  2506. $sum_correct_student[$sum_student]->name = $name;
  2507. $sum_correct_student[$sum_student]->sum = $total_student;
  2508. } // foreach ($students as $users)
  2509. }
  2510. for ($i = 1; $i < $j; $i ++) {
  2511. if (is_null($sum_iassign_correct[$i]))
  2512. $sum_iassign_correct[$i] = 0;
  2513. $sum_correct_iassign[$i] = new stdClass();
  2514. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2515. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2516. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2517. } // for ($i = 1; $i < $j; $i++)
  2518. } // if ($i > 1)
  2519. if ($this->action != 'printstats') {
  2520. $title = get_string('graphic', 'iassign');
  2521. print $OUTPUT->header();
  2522. $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>";
  2523. $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>";
  2524. print '<table width=100%><tr>';
  2525. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2526. print '<td width=15% align="right">' . $link_report . '</td>';
  2527. print '</td></tr></table>' . "\n";
  2528. print "<br><br>";
  2529. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2530. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2531. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2532. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2533. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2534. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2535. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2536. print '</tr>' . "\n";
  2537. $sum_correct = 0;
  2538. if ($sum_correct_iassign) {
  2539. foreach ($sum_correct_iassign as $iassign) {
  2540. if (is_null($iassign->experiment))
  2541. $iassign->experiment = 0;
  2542. $bar = "";
  2543. $sum = $iassign->sum;
  2544. $percent = ($sum / $sum_student) * 100;
  2545. $text = number_format($percent, 1) . '%';
  2546. $sum_correct += $sum;
  2547. if ($sum > 0) {
  2548. for ($i = 1; $i < $percent * 2; $i ++)
  2549. $bar .= iassign_icons::insert('hbar_blue');
  2550. $bar .= iassign_icons::insert('hbar_blue_r');
  2551. } // if ($sum > 0)
  2552. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  2553. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2554. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  2555. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  2556. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  2557. print '</tr>' . "\n";
  2558. } // foreach ($sum_correct_iassign as $iassign)
  2559. }
  2560. print "</table>";
  2561. print "<br><br>";
  2562. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2563. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  2564. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2565. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2566. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2567. print '</tr>' . "\n";
  2568. $sum_correct = 0;
  2569. foreach ($sum_correct_student as $student) {
  2570. $bar = "";
  2571. $sum = $student->sum;
  2572. $percent = ($sum / $sum_iassign) * 100;
  2573. $text = number_format($percent, 1) . '%';
  2574. $sum_correct += $sum;
  2575. if ($sum > 0) {
  2576. for ($i = 1; $i < $percent * 2; $i ++)
  2577. $bar .= iassign_icons::insert('hbar_blue');
  2578. $bar .= iassign_icons::insert('hbar_blue_r');
  2579. } // if ($sum > 0)
  2580. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  2581. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2582. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2583. print '</tr>' . "\n";
  2584. } // foreach ($sum_correct_student as $student)
  2585. print "</table>\n";
  2586. print "<br><br>\n";
  2587. $var = 0;
  2588. $cv = 0;
  2589. $dv = 0;
  2590. $avg = 0;
  2591. if ($sum_correct_student) {
  2592. $avg = $sum_correct / $sum_student;
  2593. if ($avg > 0) {
  2594. foreach ($sum_correct_student as $student)
  2595. $var += pow($student->sum - $avg, 2);
  2596. $var = $var / $sum_student;
  2597. $dv = sqrt($var);
  2598. $cv = ($dv / $avg) * 100;
  2599. }
  2600. }
  2601. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2602. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  2603. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2604. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2605. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2606. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2607. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2608. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2609. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  2610. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2611. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2612. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2613. print "</table>\n";
  2614. print $OUTPUT->footer();
  2615. } else {
  2616. print "<STYLE TYPE='text/css'>
  2617. <!--
  2618. .boldtable {
  2619. font-family:sans-serif;
  2620. font-size:10pt;
  2621. }
  2622. -->
  2623. </STYLE>\n";
  2624. print '<table border=1 width=100%>' . "\n";
  2625. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  2626. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2627. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2628. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2629. print '</tr>' . "\n";
  2630. $sum_correct = 0;
  2631. foreach ($sum_correct_iassign as $iassign) {
  2632. $bar = "";
  2633. $sum = $iassign->sum;
  2634. $percent = ($sum / $sum_student) * 100;
  2635. $text = number_format($percent, 1) . '%';
  2636. $sum_correct += $sum;
  2637. if ($sum > 0) {
  2638. for ($i = 1; $i < $percent * 2; $i ++)
  2639. $bar .= iassign_icons::insert('hbar_blue');
  2640. $bar .= iassign_icons::insert('hbar_blue_r');
  2641. } // if ($sum > 0)
  2642. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  2643. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  2644. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  2645. print '</tr>' . "\n";
  2646. } // foreach ($sum_correct_iassign as $iassign)
  2647. print "</table>";
  2648. print "<br><br>";
  2649. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2650. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  2651. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2652. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  2653. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  2654. print '</tr>' . "\n";
  2655. $sum_correct = 0;
  2656. foreach ($sum_correct_student as $student) {
  2657. $bar = "";
  2658. $sum = $student->sum;
  2659. $percent = ($sum / $sum_iassign) * 100;
  2660. $text = number_format($percent, 1) . '%';
  2661. $sum_correct += $sum;
  2662. if ($sum > 0) {
  2663. for ($i = 1; $i < $percent * 2; $i ++)
  2664. $bar .= iassign_icons::insert('hbar_blue');
  2665. $bar .= iassign_icons::insert('hbar_blue_r');
  2666. } // if ($sum > 0)
  2667. print "<tr><td width=50%>" . $student->name . "</td>\n";
  2668. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  2669. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  2670. print '</tr>' . "\n";
  2671. } // foreach ($sum_correct_student as $student)
  2672. print "</table>\n";
  2673. print "<br/><br/>\n";
  2674. $var = 0;
  2675. $cv = 0;
  2676. $dv = 0;
  2677. $avg = 0;
  2678. if ($sum_correct_student) {
  2679. $avg = $sum_correct / $sum_student;
  2680. if ($avg > 0) {
  2681. foreach ($sum_correct_student as $student)
  2682. $var += pow($student->sum - $avg, 2);
  2683. $var = $var / $sum_student;
  2684. $dv = sqrt($var);
  2685. $cv = ($dv / $avg) * 100;
  2686. }
  2687. }
  2688. print '<table border=1 class="boldtable" width=100%>' . "\n";
  2689. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  2690. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  2691. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  2692. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  2693. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  2694. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  2695. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  2696. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  2697. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  2698. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  2699. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  2700. print "</table>\n";
  2701. } // if ($this->action != 'printstats')
  2702. die();
  2703. }
  2704. /// Display graphics of performance for students
  2705. function stats_students () {
  2706. global $USER, $CFG, $DB, $OUTPUT;
  2707. $id = $this->cm->id;
  2708. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  2709. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  2710. $title = get_string('results', 'iassign');
  2711. $sum_correct = 0;
  2712. $sum_incorrect = 0;
  2713. $sum_post = 0;
  2714. $sum_nopost = 0;
  2715. $sum_iassign = count($iassign_statement_list);
  2716. $bar_nopost = "";
  2717. $bar_correct = "";
  2718. $bar_incorrect = "";
  2719. $bar_post = "";
  2720. $text_nopost = "";
  2721. $text_correct = "";
  2722. $text_incorrect = "";
  2723. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2724. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  2725. if ($iassign_submission) {
  2726. if ($iassign_submission->status == 3)
  2727. $sum_correct ++;
  2728. elseif ($iassign_submission->status == 2)
  2729. $sum_incorrect ++;
  2730. elseif ($iassign_submission->status == 1)
  2731. $sum_post ++;
  2732. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  2733. $sum_nopost ++;
  2734. } // if ($iassign_submission)
  2735. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2736. if ($sum_iassign > 0) {
  2737. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  2738. $text_correct = number_format($percent_correct, 1) . '%';
  2739. }
  2740. if ($sum_correct > 0) {
  2741. for ($i = 1; $i < $percent_correct * 2; $i ++)
  2742. $bar_correct .= iassign_icons::insert('hbar_green');
  2743. $bar_correct .= iassign_icons::insert('hbar_green_r');
  2744. } // if ($sum_correct > 0)
  2745. if ($sum_iassign > 0) {
  2746. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  2747. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  2748. }
  2749. if ($sum_incorrect > 0) {
  2750. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  2751. $bar_incorrect .= iassign_icons::insert('hbar_red');
  2752. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  2753. } // if ($sum_incorrect > 0)
  2754. if ($sum_iassign > 0) {
  2755. $percent_post = ($sum_post / $sum_iassign) * 100;
  2756. $text_post = number_format($percent_post, 1) . '%';
  2757. }
  2758. if ($sum_post > 0) {
  2759. for ($i = 1; $i < $percent_post * 2; $i ++)
  2760. $bar_post .= iassign_icons::insert('hbar_blue');
  2761. $bar_post .= iassign_icons::insert('hbar_blue_r');
  2762. } // if ($sum_post > 0)
  2763. if ($sum_iassign > 0) {
  2764. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  2765. $text_nopost = number_format($percent_nopost, 1) . '%';
  2766. }
  2767. if ($sum_nopost > 0) {
  2768. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  2769. $bar_nopost .= iassign_icons::insert('hbar_orange');
  2770. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  2771. } // if ($sum_nopost > 0)
  2772. print $OUTPUT->header();
  2773. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  2774. print '<table width=100%><tr>';
  2775. print '<td align="right">' . $link_return . '</td>' . "\n";
  2776. print '</td></tr></table>' . "\n";
  2777. print "<br/><br/>\n";
  2778. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  2779. print '<tr><th colspan=3 class="header c1">' . "\n";
  2780. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  2781. // $imagetext = '');
  2782. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2783. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  2784. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  2785. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  2786. print '</tr>' . "\n";
  2787. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  2788. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  2789. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  2790. print '</tr>' . "\n";
  2791. if ($sum_post) {
  2792. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  2793. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  2794. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  2795. print '</tr>' . "\n";
  2796. } // if ($sum_post)
  2797. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  2798. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  2799. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  2800. print '</tr>' . "\n";
  2801. print "</table>";
  2802. print "<br><br>";
  2803. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2804. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  2805. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2806. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  2807. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  2808. $sum_grade = 0;
  2809. $sum_grade_student = 0;
  2810. $avg = 0;
  2811. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  2812. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  2813. if (!$iassign_submission) {
  2814. $iassign_submission = new stdClass();
  2815. $iassign_submission->grade = 0;
  2816. }
  2817. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  2818. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  2819. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  2820. print '</tr>' . "\n";
  2821. $sum_grade += $iassign_statement_activity_item->grade;
  2822. $sum_grade_student += $iassign_submission->grade;
  2823. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  2824. if ($sum_grade > 0)
  2825. $avg = $sum_grade_student / $sum_grade * 100;
  2826. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  2827. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  2828. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  2829. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2830. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  2831. print "</table>";
  2832. print $OUTPUT->footer();
  2833. die();
  2834. } // function stats_students()
  2835. /// Display page of iAssign's activity
  2836. function view_iassigns () {
  2837. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  2838. $id = $this->cm->id;
  2839. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  2840. $notice = optional_param('notice', '', PARAM_TEXT);
  2841. if (strpos($notice, 'error'))
  2842. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  2843. else if ($notice != '')
  2844. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  2845. print $OUTPUT->box_start();
  2846. print '<table width=100% border=0><tr>' . "\n";
  2847. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  2848. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  2849. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  2850. $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>";
  2851. $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>";
  2852. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  2853. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2854. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  2855. // Has capability to see "report": teacher or up
  2856. print '<td width=10% align="left">' . "\n";
  2857. print $link_help;
  2858. print '</td>' . "\n";
  2859. print '<td width=10% align="left">' . "\n";
  2860. print $link_report;
  2861. print '</td>' . "\n";
  2862. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2863. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2864. print '<td width=15% align="left">' . "\n";
  2865. print $link_add;
  2866. print "</td>\n";
  2867. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2868. //print '</tr></table>' . "\n";
  2869. print '<div style="float: right;">';
  2870. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2871. if ($iassign_list) {
  2872. print '<td align="right">' . "\n";
  2873. // $USER->iassignEdit == 0 view 'Turn editing off'
  2874. // $USER->iassignEdit == 1 view 'Turn editing on'
  2875. if (!isset($USER->iassignEdit))
  2876. $USER->iassignEdit = 0;
  2877. if ($USER->iassignEdit == 0) {
  2878. $bottonEdit_message = get_string('turneditingon', 'iassign');
  2879. $botton = 1;
  2880. } // if ($USER->iassignEdit == 0)
  2881. elseif ($USER->iassignEdit == 1) {
  2882. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  2883. $botton = 0;
  2884. } // elseif ($USER->iassignEdit == 1)
  2885. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  2886. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  2887. print " <input type=submit value='$bottonEdit_message'/>\n";
  2888. print "</form>\n";
  2889. print "</td>\n";
  2890. } // if ($iassign_list)
  2891. }
  2892. print '</tr></table>' . "\n";
  2893. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2894. // $this->view_legend_icons();
  2895. print $OUTPUT->box_end();
  2896. $iassign_array_exercise = array();
  2897. $i_exercise = 0;
  2898. $iassign_array_test = array();
  2899. $i_test = 0;
  2900. $iassign_array_example = array();
  2901. $i_example = 0;
  2902. $iassign_array_general = array();
  2903. $i_general = 0;
  2904. if ($iassign_list) {
  2905. if ($this->iassign->activity_group == 0) {
  2906. foreach ($iassign_list as $iassign) {
  2907. $iassign_array_general[$i_general] = $iassign;
  2908. $i_general ++;
  2909. }
  2910. } // if ($this->iassign->activity_group == 0)
  2911. else {
  2912. foreach ($iassign_list as $iassign) {
  2913. if ($iassign->type_iassign == 3) {
  2914. $iassign_array_exercise[$i_exercise] = $iassign;
  2915. $i_exercise ++;
  2916. } // if ($iassign->type_iassign == 3)
  2917. if ($iassign->type_iassign == 2) {
  2918. $iassign_array_test[$i_test] = $iassign;
  2919. $i_test ++;
  2920. } // if ($iassign->type_iassign == 2)
  2921. if ($iassign->type_iassign == 1) {
  2922. $iassign_array_example[$i_example] = $iassign;
  2923. $i_example ++;
  2924. } // if ($iassign->type_iassign == 1)
  2925. }
  2926. }
  2927. if ($iassign_array_exercise) {
  2928. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  2929. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  2930. }
  2931. if ($iassign_array_test) {
  2932. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  2933. $this->show_iassign($title, $iassign_array_test, $i_test);
  2934. }
  2935. if ($iassign_array_example) {
  2936. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  2937. $this->show_iassign($title, $iassign_array_example, $i_example);
  2938. }
  2939. if ($iassign_array_general) {
  2940. $title = "";
  2941. $this->show_iassign($title, $iassign_array_general, $i_general);
  2942. }
  2943. } else { // if ($iassign_list)
  2944. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  2945. }
  2946. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  2947. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  2948. print $OUTPUT->box_start();
  2949. print '<table width=100% border=0><tr>' . "\n";
  2950. print '<td width=10% align="left">' . "\n";
  2951. print $link_report;
  2952. print '</td>' . "\n";
  2953. print '</tr></table>' . "\n";
  2954. print $OUTPUT->box_end();
  2955. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  2956. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  2957. print $OUTPUT->box_start();
  2958. print '<table width=100% border=0><tr>' . "\n";
  2959. print '<td align="left">' . "\n";
  2960. print $link_add;
  2961. print '</td>' . "\n";
  2962. print '</tr></table>' . "\n";
  2963. print $OUTPUT->box_end();
  2964. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  2965. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  2966. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  2967. $this->view_legend_icons();
  2968. } // function view_iassigns()
  2969. /// Display all iAssigns
  2970. function show_iassign ($title, $iassign_array, $i) {
  2971. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  2972. $id = $this->cm->id;
  2973. print $OUTPUT->box_start();
  2974. print " <script type='text/javascript'>
  2975. //<![CDATA[
  2976. function validate_move () {
  2977. var radios = document.getElementsByName('iassign_destiny');
  2978. var formValid = false;
  2979. //alert('aqui validate_move()');
  2980. var i = 0;
  2981. while (!formValid && i < radios.length) {
  2982. if (radios[i].checked) formValid = true;
  2983. i++;
  2984. }
  2985. if (!formValid) {
  2986. document.getElementById('move_dest').classList.add('alert-danger');
  2987. }
  2988. return formValid;
  2989. }
  2990. var modal;
  2991. function load_move(id_ias) {
  2992. document.form_move_activity.iassign_current.value = id_ias;
  2993. modal.style.display = 'block';
  2994. var radios = document.getElementsByName('iassign_destiny');
  2995. var i = 0;
  2996. while (i < radios.length) {
  2997. radios[i].checked = false;
  2998. i++;
  2999. }
  3000. document.getElementById('move_dest').classList.remove('alert-danger');
  3001. }
  3002. function load_modal_elements() {
  3003. modal = document.getElementById('myModal');
  3004. var span = document.getElementById('close_modal');
  3005. span.onclick = function() {
  3006. modal.style.display = 'none';
  3007. }
  3008. window.onclick = function(event) {
  3009. if (event.target == modal) {
  3010. modal.style.display = 'none';
  3011. }
  3012. }
  3013. }
  3014. window.onload = load_modal_elements;
  3015. //]]>
  3016. </script>\n";
  3017. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3018. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3019. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3020. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3021. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3022. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3023. <input type='hidden' name='iassign_current' value='' />";
  3024. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3025. $section = $course_sections[0];
  3026. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3027. for ($k = 0; $k < count($ids_sections); $k++) {
  3028. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3029. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3030. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3031. if ($c_cm) {
  3032. if ($ccm->instance == $c_cm->instance) {
  3033. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3034. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3035. }
  3036. else {
  3037. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3038. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3039. }
  3040. }
  3041. }
  3042. $radio_buttons .= "</ul>";
  3043. }
  3044. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3045. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3046. </form>
  3047. </div></div> </div></div>\n";
  3048. print " <style>.modal {
  3049. display: none;
  3050. position: fixed;
  3051. z-index: 1;
  3052. left: 0;
  3053. top: 0;
  3054. width: 100%;
  3055. height: 100%;
  3056. overflow: scroll;
  3057. background-color: rgb(0,0,0);
  3058. background-color: rgba(0,0,0,0.4);
  3059. }
  3060. .modal-content {
  3061. background-color: #fefefe;
  3062. margin: 15% auto;
  3063. padding: 10px 10px;
  3064. border: 1px solid #888;
  3065. width: 50%;
  3066. }
  3067. #close_modal {
  3068. color: #aaa;
  3069. float: right;
  3070. font-size: 28px;
  3071. font-weight: bold;
  3072. margin-top: -15px;
  3073. margin-right: -3px;
  3074. }
  3075. #close_modal:hover,
  3076. #close_modal:focus {
  3077. color: black;
  3078. text-decoration: none;
  3079. cursor: pointer;
  3080. }
  3081. #modal_title {
  3082. min-height: 3rem;
  3083. color: initial;
  3084. background: initial;
  3085. font-size: 1.5rem;
  3086. line-height: 1.5;
  3087. padding: 15px;
  3088. border-bottom: 1px solid #e5e5e5;
  3089. }
  3090. .input_move {
  3091. width: 90%;
  3092. padding: 2px;
  3093. }
  3094. .input_move:hover {
  3095. background: #eff0ef;
  3096. }
  3097. </style>";
  3098. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3099. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3100. for ($j = 0; $j < $i; $j ++) {
  3101. $iassign_current = $iassign_array[$j]->id;
  3102. // receiver=1 - message to teacher
  3103. // receiver=2 - message to student
  3104. $sum_comment = 0;
  3105. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3106. foreach ($iassign_submissions as $iassign_submission) {
  3107. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3108. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3109. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3110. if ($verify_message)
  3111. foreach ($verify_message as $tmp)
  3112. $sum_comment += $tmp;
  3113. } // foreach ($iassign_submissions as $iassign_submission)
  3114. if ($sum_comment == 0)
  3115. $comment_unread = "";
  3116. else {
  3117. $comment_unread_message = get_string('comment_unread', 'iassign');
  3118. if ($sum_comment == 1)
  3119. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3120. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3121. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3122. }
  3123. if ($j == $i - 1)
  3124. $iassign_down = $iassign_array[$j]->id;
  3125. else
  3126. $iassign_down = $iassign_array[$j + 1]->id;
  3127. if ($j > 0)
  3128. $iassign_up = $iassign_array[$j - 1]->id;
  3129. else
  3130. $iassign_up = $iassign_array[$j]->id;
  3131. if ($iassign_array[$j]->visible == 0)
  3132. $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>";
  3133. else
  3134. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3135. $links .= $comment_unread;
  3136. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3137. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3138. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3139. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3140. if ($j==0) // first activity
  3141. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3142. else
  3143. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3144. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3145. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3146. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3147. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3148. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3149. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3150. if (count($iassign_array) > 1) {
  3151. if ($j == 0)
  3152. $links .= $link_down;
  3153. elseif ($j == $i - 1)
  3154. $links .= $link_up;
  3155. else
  3156. $links .= $link_up . $link_down;
  3157. } // if (count($iassign_array) > 1)
  3158. $links .= $link_edit . $link_delete;
  3159. if ($iassign_array[$j]->visible == 0)
  3160. $links .= $link_visible_show;
  3161. else
  3162. $links .= $link_visible_hide;
  3163. $links .= $link_duplicate_activity . $link_move_activity;
  3164. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3165. print '<p>' . $links . '</p>' . "\n";
  3166. }
  3167. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3168. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3169. print '<table width=100% ><tr>' . "\n";
  3170. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3171. print '</tr></table>' . "\n";
  3172. for ($j = 0; $j < $i; $j ++) {
  3173. $icon_status = "";
  3174. $icon_comment = "";
  3175. if ($iassign_array[$j]->visible == 1) {
  3176. $iassign_current = $iassign_array[$j]->id;
  3177. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3178. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3179. $icon_status = "";
  3180. $icon_comment = "";
  3181. if ($iassign_submission) {
  3182. // receiver=1 - message to teacher
  3183. // receiver=2 - message to student
  3184. // $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");
  3185. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3186. $verify_message = $DB->get_record_sql(
  3187. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3188. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3189. if ($verify_message)
  3190. foreach ($verify_message as $tmp)
  3191. $sum_comment = $tmp;
  3192. if ($sum_comment > 0) {
  3193. $comment_unread_message = get_string('comment_unread', 'iassign');
  3194. if ($sum_comment == 1)
  3195. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3196. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3197. }
  3198. // $icon_comment = iassign_icons::insert('comment_unread');
  3199. if ($iassign_array[$j]->type_iassign == 3) {
  3200. if ($iassign_array[$j]->show_answer == 1) {
  3201. if ($iassign_submission->status == 3)
  3202. $icon_status = iassign_icons::insert('correct');
  3203. elseif ($iassign_submission->status == 2)
  3204. $icon_status = iassign_icons::insert('incorrect');
  3205. elseif ($iassign_submission->status == 1)
  3206. $icon_status = iassign_icons::insert('post');
  3207. elseif ($iassign_submission->status == 0)
  3208. $icon_status = iassign_icons::insert('not_post');
  3209. } // if ($iassign_array[$j]->show_answer==1)
  3210. else {
  3211. if ($iassign_submission->status == 0)
  3212. $icon_status = iassign_icons::insert('not_post');
  3213. else
  3214. $icon_status = iassign_icons::insert('post');
  3215. }
  3216. } // if ($iassign_array[$j]->type_iassign == 3)
  3217. } // if ($iassign_submission)
  3218. elseif ($iassign_array[$j]->type_iassign == 3) {
  3219. $icon_status = iassign_icons::insert('not_post');
  3220. } // if ($iassign_array[$j]->type_iassign == 3)
  3221. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3222. } // if ($iassign_array[$j]->visible == 1)
  3223. } // for ($j = 0; $j < $i; $j++)
  3224. } else if (isguestuser()) {
  3225. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3226. print '<table width=100% ><tr>' . "\n";
  3227. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3228. print '</tr></table>' . "\n";
  3229. for ($j = 0; $j < $i; $j ++) {
  3230. $icon_status = "";
  3231. $icon_comment = "";
  3232. if ($iassign_array[$j]->visible == 1) {
  3233. $iassign_current = $iassign_array[$j]->id;
  3234. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3235. print '<p>' . $links . '</p>' . "\n";
  3236. } // if ($iassign_array[$j]->visible == 1)
  3237. }
  3238. }
  3239. print $OUTPUT->box_end();
  3240. } // function show_iassign($title, $iassign_array, $i)
  3241. /// Show message of return
  3242. function return_home_course ($message) {
  3243. //D global $DB, $OUTPUT;
  3244. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3245. //D echo $OUTPUT->box_start();
  3246. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3247. //D echo '<tr><td align="left"><strong>' . "\n";
  3248. //D print_string($message, 'iassign');
  3249. //D echo '</strong></td>' . "\n";
  3250. //D echo '<td width=20% align="right">' . "\n";
  3251. //D echo $link_return;
  3252. //D echo '</td></tr></table>' . "\n";
  3253. //D echo $OUTPUT->box_end();
  3254. //D // echo $OUTPUT->footer();
  3255. redirect(new moodle_url($this->return . '&notice=' . $message));
  3256. exit;
  3257. }
  3258. /// Search comment of activity
  3259. function search_comment_submission ($iassign_submissionid) {
  3260. global $USER, $DB, $OUTPUT, $COURSE;
  3261. // $context = context_course::instance($COURSE->id);
  3262. $colorEdit1 = "#a7bede"; // "#dce7ec"
  3263. $colorEdit2 = "#b7ceee";
  3264. $has_capability = 0;
  3265. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3266. $text = "";
  3267. if ($comments) {
  3268. $even = 1;
  3269. foreach ($comments as $tmp) {
  3270. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3271. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3272. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3273. // $text .= $tmp->comment . "</td></tr>";
  3274. //} else {
  3275. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3276. if ($even) {
  3277. $text .= "<tr><td bgcolor='" . $colorEdit1 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3278. $even = 0;
  3279. } else {
  3280. $text .= "<tr><td bgcolor='" . $colorEdit2 . "'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3281. $even = 1;
  3282. }
  3283. $text .= $tmp->comment . "</td></tr>\n";
  3284. } // foreach ($comments as $tmp)
  3285. }
  3286. return $text;
  3287. }
  3288. /// Update comment of activity
  3289. function update_comment ($iassign_submissionid) {
  3290. global $USER, $DB, $OUTPUT;
  3291. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3292. $receiver = 1; // student message to teacher
  3293. else
  3294. $receiver = 2; // teacher message to student
  3295. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3296. if ($verify_message) {
  3297. foreach ($verify_message as $message) {
  3298. if ($message->receiver == $receiver) {
  3299. $newentry = new stdClass();
  3300. $newentry->id = $message->id;
  3301. $newentry->return_status = 1;
  3302. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3303. print_error('error_update', 'iassign');
  3304. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3305. } // if ($message->receiver == $receiver)
  3306. // Trigger module viewed event.
  3307. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3308. 'objectid' => $this->iassign->id,
  3309. 'context' => $this->context
  3310. ));
  3311. $event->add_record_snapshot('course', $this->course);
  3312. $event->trigger();
  3313. } // foreach ($verify_message as $message)
  3314. }
  3315. }
  3316. /// Record comment of activity
  3317. function write_comment_submission () {
  3318. global $USER, $CFG, $DB;
  3319. $id = $this->cm->id;
  3320. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3321. $row = optional_param('row', 0, PARAM_INT);
  3322. $column = optional_param('column', 0, PARAM_INT);
  3323. $sum_comment = 0;
  3324. $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);
  3325. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3326. $str1 = trim($submission_comment);
  3327. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3328. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3329. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3330. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3331. $receiver = 1; // student message to teacher
  3332. $this->action = 'view';
  3333. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3334. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3335. } else {
  3336. $receiver = 2; // teacher message to student
  3337. $this->action = 'viewsubmission';
  3338. //D $tousers = array(); //MOOC 2016
  3339. //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
  3340. }
  3341. //MOOC 2016: foi p/ 15 linhas acima:
  3342. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3343. if (!$iassign_submission) {
  3344. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3345. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3346. $this->iassign_submission_current = $id_submission;
  3347. } else {
  3348. $id_submission = $iassign_submission->id;
  3349. } // if (!$iassign_submission)
  3350. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3351. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3352. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3353. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3354. $comments = $DB->get_record_sql(
  3355. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3356. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3357. if ($comments)
  3358. foreach ($comments as $tmp)
  3359. $sum_comment = $tmp;
  3360. if ($sum_comment == 0) {
  3361. $newentry = new stdClass();
  3362. $newentry->iassign_submissionid = $id_submission;
  3363. $newentry->comment_authorid = $USER->id;
  3364. $newentry->timecreated = time();
  3365. $newentry->comment = $submission_comment;
  3366. $newentry->receiver = $receiver;
  3367. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3368. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3369. //T $eventdata = new stdClass();
  3370. //T $eventdata->component = 'mod_iassign'; //your component name
  3371. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3372. //T $eventdata->userfrom = $USER;
  3373. //T $eventdata->userto = $touser;
  3374. //T $eventdata->subject = "Teste de Subject";
  3375. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3376. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3377. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3378. //T $eventdata->smallmessage = "Teste de Mensagem";
  3379. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3380. //T // alteracao tulio faria
  3381. //T //message_send($eventdata);
  3382. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3383. // Trigger module viewed event.
  3384. $event = \mod_iassign\event\submission_comment_created::create(array(
  3385. 'objectid' => $this->iassign->id,
  3386. 'context' => $this->context
  3387. ));
  3388. $event->add_record_snapshot('course', $this->course);
  3389. $event->trigger();
  3390. }
  3391. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3392. // if ($this->action=='viewsubmission') {
  3393. // echo $OUTPUT->header();
  3394. // $this->return_last('confirm_add_comment', $link_return);
  3395. // die;
  3396. // }
  3397. return true;
  3398. } // function write_comment_submission()
  3399. /// Writes a new submission
  3400. // The first student answer is under 'function get_answer()'
  3401. function new_submission ($iassignid, $id_user, $receiver) {
  3402. global $USER, $DB, $OUTPUT;
  3403. $newentry = new stdClass();
  3404. $newentry->iassign_statementid = $iassignid;
  3405. $newentry->userid = $id_user;
  3406. $newentry->timecreated = time();
  3407. $newentry->timemodified = time();
  3408. $newentry->answer = 0; // student only submit message
  3409. if ($receiver == 2) // teacher message to student (write id teacher)
  3410. $newentry->teacher = $USER->id;
  3411. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3412. return_home_course('error_insert_submissions');
  3413. else {
  3414. // Trigger module view event
  3415. $event = \mod_iassign\event\submission_created::create(array(
  3416. 'objectid' => $this->iassign->id,
  3417. 'context' => $this->context
  3418. ));
  3419. $event->add_record_snapshot('course', $this->course);
  3420. $event->trigger();
  3421. }
  3422. return $newentry->id;
  3423. }
  3424. /// Return to a specific address of page
  3425. function return_last ($message, $link_return) {
  3426. global $DB, $OUTPUT;
  3427. print $OUTPUT->box_start();
  3428. print '<table width=100% border=0 valign="top">' . "\n";
  3429. print '<tr><td align="left"><strong>' . "\n";
  3430. print_string($message, 'iassign');
  3431. print '</strong></td>' . "\n";
  3432. print '<td width=20% align="right">' . "\n";
  3433. print $link_return;
  3434. print '</td></tr></table>' . "\n";
  3435. print $OUTPUT->box_end();
  3436. print $OUTPUT->footer();
  3437. die();
  3438. } // function return_last($message, $link_return)
  3439. } // class iassign
  3440. /// Class for manage activities
  3441. class activity {
  3442. var $activity;
  3443. /// Constructor of class.
  3444. // @param int $id Id of activity
  3445. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3446. //D public function activity($id) { self::__construct($id); }
  3447. function __construct ($id) {
  3448. global $DB;
  3449. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3450. if (empty($this->activity))
  3451. $this->activity = null;
  3452. }
  3453. /// Get an activity
  3454. // @return NULL
  3455. function get_activity () {
  3456. if ($this->activity != null)
  3457. return $this->activity;
  3458. else
  3459. return null;
  3460. }
  3461. /// Delete interactive activities
  3462. function delete ($return) {
  3463. global $USER, $CFG, $DB, $OUTPUT;
  3464. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3465. $output = $OUTPUT->header();
  3466. $output .= $OUTPUT->box_start();
  3467. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3468. if ($iassign_submission_currents) {
  3469. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3470. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3471. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3472. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3473. $output .= $OUTPUT->box_end();
  3474. $output .= $OUTPUT->footer();
  3475. print $output;
  3476. die();
  3477. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3478. } // if ($iassign_submission_currents)
  3479. else
  3480. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3481. $output .= '<table width=50% border=0>';
  3482. $output .= '<tr valign="top"><td>';
  3483. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3484. $output .= '</td><td>';
  3485. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3486. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3487. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3488. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3489. $output .= "</form>\n";
  3490. $output .= '</td><td>';
  3491. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3492. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3493. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3494. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3495. $output .= "</form>\n";
  3496. $output .= '</td></tr></table>' . "\n";
  3497. $output .= $OUTPUT->box_end();
  3498. $output .= $OUTPUT->footer();
  3499. print $output;
  3500. } // function delete($return)
  3501. /// Function for confirm the delete of activity
  3502. // @param String $return Url of return
  3503. // @param Object $iassign Object content an activity
  3504. function deleteyes ($return, $iassign) {
  3505. global $USER, $CFG, $DB, $OUTPUT;
  3506. $msg = '';
  3507. if (!empty($this->activity->id)) {
  3508. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3509. if ($iassign_submission_currents) {
  3510. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3511. foreach ($iassign_submission_currents as $iassign_submission)
  3512. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3513. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3514. } // if ($iassign_submission_currents)
  3515. }
  3516. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3517. $this->delete_calendar($this->activity->id);
  3518. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3519. iassign::update_grade_iassign($this->activity->iassignid);
  3520. if ($delete_iassign_current) {
  3521. $iassign->return_home_course('confirm_delete_iassign');
  3522. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3523. } else {
  3524. $iassign->return_home_course('error_confirm_delete_iassign');
  3525. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3526. }
  3527. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3528. }
  3529. }
  3530. /// Changes position of activities (between those inside a group of interactive activities)
  3531. // @param $move_action = must be "up" or "down"
  3532. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  3533. function move_iassign ($move_action, $target, $return) {
  3534. global $DB, $OUTPUT;
  3535. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  3536. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  3537. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  3538. if ($move_action=="firstdown") {
  3539. $final_position_source = 2;
  3540. $final_position_target = 1;
  3541. }
  3542. else
  3543. if ($move_action=="down") {
  3544. $final_position_target = $this->activity->position;
  3545. $final_position_source = $final_position_target + 1;
  3546. }
  3547. else
  3548. if ($move_action=="up") {
  3549. $final_position_target = $this->activity->position;
  3550. $final_position_source = $final_position_target - 1;
  3551. }
  3552. else { // error:
  3553. print_error('error_update_move_iassign', 'iassign');
  3554. exit;
  3555. }
  3556. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  3557. $newentry->id = $this->activity->id; // ID of the "source activity"
  3558. $newentry->position = $final_position_source;
  3559. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  3560. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  3561. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  3562. print_error('error_update_move_iassign', 'iassign');
  3563. }
  3564. else { // first update performed successfully
  3565. $newentry->id = $iassign_target->id;
  3566. $newentry->position = $final_position_target;
  3567. if (!$DB->update_record('iassign_statement', $newentry))
  3568. print_error('error_update_move_iassign', 'iassign');
  3569. }
  3570. redirect($return);
  3571. }
  3572. /// Enable or disable the display of interactive activities
  3573. function visible_iassign ($return) {
  3574. global $DB;
  3575. $newentry = new stdClass();
  3576. $newentry->id = $this->activity->id;
  3577. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  3578. if (!$DB->update_record('iassign_statement', $newentry))
  3579. print_error('error_update_visible_iassign', 'iassign');
  3580. redirect($return);
  3581. }
  3582. /// Add news interactive activities (register in table 'iassign_statement')
  3583. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  3584. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  3585. function new_iassign ($param) {
  3586. global $DB;
  3587. $newentry = new stdClass();
  3588. $newentry->iassignid = $param->iassignid;
  3589. $newentry->name = $param->name;
  3590. $newentry->type_iassign = $param->type_iassign;
  3591. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  3592. $proposition = $param->proposition;
  3593. if (is_array($proposition)) $proposition_text = $proposition['text'];
  3594. else $proposition_text = $proposition;
  3595. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  3596. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  3597. //TODO Then get it directly from the form data $_POST!
  3598. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  3599. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  3600. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  3601. $newentry->author_name = $param->author_name;
  3602. $newentry->author_modified_name = $param->author_modified_name;
  3603. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3604. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3605. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  3606. $newentry->grade = $param->grade;
  3607. $newentry->timemodified = time();
  3608. $newentry->timecreated = time();
  3609. if ($param->type_iassign == 1) {
  3610. $newentry->timedue = 0;
  3611. $newentry->timeavailable = 0;
  3612. } // if ($param->type_iassign == 1)
  3613. else {
  3614. $newentry->timedue = $param->timedue;
  3615. $newentry->timeavailable = $param->timeavailable;
  3616. }
  3617. $newentry->preventlate = $param->preventlate;
  3618. $newentry->test = $param->test;
  3619. $newentry->special_param1 = $param->special_param1;
  3620. $newentry->visible = $param->visible;
  3621. $newentry->position = $param->position;
  3622. $newentry->max_experiment = $param->max_experiment;
  3623. $newentry->dependency = $param->dependency;
  3624. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3625. $newentry->show_answer = $param->show_answer;
  3626. $id = $DB->insert_record("iassign_statement", $newentry);
  3627. if ($id) {
  3628. $component = 'mod_iassign';
  3629. $filearea = 'exercise';
  3630. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3631. $file = $fs->get_file_by_id($param->file);
  3632. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  3633. // File already inserted in other context!
  3634. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  3635. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3636. $updateentry = new stdClass();
  3637. $updateentry->id = $id;
  3638. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  3639. $updateentry->file = $newfile->get_itemid();
  3640. if (!$DB->update_record("iassign_statement", $updateentry))
  3641. print_error('error_add', 'iassign');
  3642. if ($param->type_iassign == 3)
  3643. iassign::update_grade_iassign($param->iassignid);
  3644. //TODO iLM_HTML5 :: //MOOC2014
  3645. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  3646. //D if ($iassign_ilm_configs) {
  3647. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  3648. //D if ($iassign_ilm_config->param_type != 'static') {
  3649. //D $newentry = new stdClass();
  3650. //D $newentry->iassign_statementid = $id;
  3651. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  3652. //D $newentry->param_name = $iassign_ilm_config->param_name;
  3653. //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});
  3654. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  3655. //D print_error('error_add_param', 'iassign');
  3656. //D }
  3657. //D }
  3658. //D }
  3659. // log event --------------------------------------------------------------------------------------
  3660. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  3661. // log event --------------------------------------------------------------------------------------
  3662. return $id;
  3663. }
  3664. else
  3665. print_error('error_add', 'iassign');
  3666. } // function new_iassign($param)
  3667. /// Add the calendar entries for this iassign
  3668. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3669. // @return bool
  3670. static function add_calendar ($iassignid) {
  3671. global $DB, $CFG;
  3672. require_once($CFG->dirroot . '/calendar/lib.php');
  3673. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3674. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3675. $event = new stdClass();
  3676. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3677. $event->description = $iassign_statement_activity_item->name;
  3678. $event->courseid = $iassign->course;
  3679. $event->groupid = 0;
  3680. $event->userid = 0;
  3681. $event->modulename = 'iassign';
  3682. $event->instance = $iassign->id;
  3683. $event->eventtype = 'due';
  3684. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3685. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3686. calendar_event::create($event);
  3687. }
  3688. /// Update the calendar entries for this iassign
  3689. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3690. // @return bool
  3691. function update_calendar ($iassignid, $olddescription) {
  3692. global $DB, $CFG;
  3693. require_once($CFG->dirroot . '/calendar/lib.php');
  3694. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3695. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3696. $event = new stdClass();
  3697. $event->id = 0;
  3698. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3699. if ($events) {
  3700. foreach ($events as $value) {
  3701. if ($value->description == $olddescription) {
  3702. $event->id = $value->id;
  3703. }
  3704. }
  3705. }
  3706. if ($event->id != 0) {
  3707. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  3708. $event->description = $iassign_statement_activity_item->name;
  3709. $event->timestart = $iassign_statement_activity_item->timeavailable;
  3710. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  3711. $calendarevent = calendar_event::load($event->id);
  3712. $calendarevent->update($event);
  3713. } else
  3714. $this->add_calendar($iassignid);
  3715. }
  3716. /// Update the calendar entries for this iassign
  3717. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  3718. // @return bool
  3719. function delete_calendar ($iassignid) {
  3720. global $DB, $CFG;
  3721. require_once($CFG->dirroot . '/calendar/lib.php');
  3722. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  3723. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  3724. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  3725. if ($events) {
  3726. foreach ($events as $value) {
  3727. if ($value->description == $iassign_statement_activity_item->name) {
  3728. $DB->delete_records('event', array('id' => $value->id));
  3729. }
  3730. }
  3731. }
  3732. }
  3733. /// Update interactive activities
  3734. function update_iassign ($param) {
  3735. global $DB;
  3736. $component = 'mod_iassign';
  3737. $filearea = 'exercise';
  3738. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3739. $file = $fs->get_file_by_id($param->file);
  3740. $fileold = $fs->get_file_by_id($param->fileold);
  3741. if ($param->file != $param->fileold) {
  3742. if ($fileold) {
  3743. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  3744. foreach ($fileoldarea as $value) {
  3745. $value->delete();
  3746. }
  3747. }
  3748. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  3749. $itemid = $file->get_itemid() + $param->iassign_id;
  3750. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  3751. $param->file = $newfile->get_itemid();
  3752. } else
  3753. $param->file = $file->get_itemid();
  3754. } else {
  3755. $param->file = $file->get_itemid();
  3756. }
  3757. $newentry = new stdClass();
  3758. $newentry->id = $param->iassign_id;
  3759. $newentry->name = $param->name;
  3760. $newentry->type_iassign = $param->type_iassign;
  3761. //2019 $newentry->proposition = $param->proposition;
  3762. $proposition = $param->proposition;
  3763. if (is_array($proposition))
  3764. $proposition_text = $proposition['text'];
  3765. else
  3766. $proposition_text = $proposition;
  3767. $newentry->proposition = $proposition_text;
  3768. $newentry->iassign_ilmid = $param->iassign_ilmid;
  3769. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  3770. $newentry->grade = $param->grade;
  3771. $newentry->author_modified_name = $param->author_modified_name;
  3772. $newentry->timemodified = time();
  3773. if ($param->type_iassign == 1) {
  3774. $newentry->timedue = 0;
  3775. $newentry->timeavailable = 0;
  3776. } // if ($param->type_iassign == 1)
  3777. else {
  3778. $newentry->timedue = $param->timedue;
  3779. $newentry->timeavailable = $param->timeavailable;
  3780. }
  3781. $newentry->preventlate = $param->preventlate;
  3782. $newentry->test = $param->test;
  3783. $newentry->special_param1 = $param->special_param1;
  3784. $newentry->visible = $param->visible;
  3785. $newentry->max_experiment = $param->max_experiment;
  3786. $newentry->dependency = $param->dependency;
  3787. $newentry->automatic_evaluate = $param->automatic_evaluate;
  3788. $newentry->show_answer = $param->show_answer;
  3789. if (!$DB->update_record("iassign_statement", $newentry))
  3790. print_error('error_update', 'iassign');
  3791. if ($param->type_iassign == 3) {
  3792. iassign::update_grade_iassign($param->iassignid);
  3793. }
  3794. //$id = $newentry->id; // MOOC 2016 --- inicio
  3795. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  3796. //if ($iassign_activity_item_configs) {
  3797. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  3798. // $newentry = new stdClass();
  3799. // $newentry->id = $iassign_activity_item_config->id;
  3800. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3801. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  3802. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  3803. // if (!$DB->update_record("iassign_statement_config", $newentry))
  3804. // print_error('error_edit_param', 'iassign');
  3805. // }
  3806. // } // MOOC 2016 --- final
  3807. // log event --------------------------------------------------------------------------------------
  3808. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  3809. // log event --------------------------------------------------------------------------------------
  3810. return $newentry->id;
  3811. // if ($param->type_iassign==3)
  3812. // $this->update_grade_iassign($param->iassignid);
  3813. } // function update_iassign($param)
  3814. /// Show information of activity
  3815. function show_info_iassign () {
  3816. global $DB, $OUTPUT;
  3817. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  3818. if ($this->activity->type_iassign == 3) {
  3819. if ($this->activity->dependency == 0) {
  3820. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  3821. } else {
  3822. $dependencys = explode(';', $this->activity->dependency);
  3823. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  3824. foreach ($dependencys as $dependency) {
  3825. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  3826. if ($dependencyiassign)
  3827. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  3828. } // foreach ($dependencys as $dependency)
  3829. } // if ($iassign_statement_activity_item->dependency == 0)
  3830. if ($this->activity->max_experiment == 0)
  3831. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  3832. else
  3833. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  3834. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  3835. } // if ($iassign_statement_activity_item->type_iassign == 3)
  3836. print $OUTPUT->box($output);
  3837. } // function show_info_iassign()
  3838. /// Shows date of opening and closing activities
  3839. function view_dates () {
  3840. global $USER, $CFG, $DB, $OUTPUT;
  3841. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  3842. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3843. $status_iassign = "";
  3844. $status_iassign1 = "";
  3845. $status_iassign2 = "";
  3846. if ($this->activity->type_iassign == 1) // activity of type example
  3847. $type_iassign = get_string('example_iassign', 'iassign');
  3848. elseif ($this->activity->type_iassign == 2) { // activity of type test
  3849. $type_iassign = get_string('test_iassign', 'iassign');
  3850. if ($this->activity->timeavailable > time()) {
  3851. $status_iassign = get_string('previous_timeavailable', 'iassign');
  3852. } elseif ($this->activity->timedue < time()) {
  3853. $status_iassign = get_string('last_timedue', 'iassign');
  3854. }
  3855. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  3856. $type_iassign = get_string('exercise_iassign', 'iassign');
  3857. if ($this->activity->timeavailable > time()) {
  3858. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  3859. } elseif ($this->activity->timedue < time()) { // after delivery
  3860. $status_iassign = get_string('last_timedue', 'iassign');
  3861. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  3862. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  3863. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  3864. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  3865. if ($this->activity->test == 1) // allowed to test after of deadline
  3866. $status_iassign2 = get_string('test_preventlate', 'iassign');
  3867. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  3868. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  3869. } // elseif ($iassign_statement_activity_item->test == 0)
  3870. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  3871. } // elseif ($iassign_statement_activity_item->timedue < time())
  3872. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  3873. $output = '<table width=100% >' . "\n";
  3874. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  3875. $output .= '<tr>' . "\n";
  3876. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  3877. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  3878. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  3879. // leo $output .= '<td width=80%>' . $type_iassign;
  3880. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  3881. // $output .= '</td>' . "\n";
  3882. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  3883. // Link (with icon) to report survey of this batch of these insteractivy exercises
  3884. $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>";
  3885. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  3886. } else {
  3887. $link_next = "";
  3888. $link_previous = "";
  3889. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  3890. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  3891. // previous_activity
  3892. if ($iassign_previous) {
  3893. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  3894. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  3895. } // next_activity
  3896. if ($iassign_next) {
  3897. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  3898. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  3899. }
  3900. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  3901. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  3902. $output .= '</tr></table>' . "\n";
  3903. $output .= '<table width=100% >' . "\n";
  3904. if ($this->activity->type_iassign > 1) {
  3905. if ($this->activity->timeavailable)
  3906. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  3907. if ($this->activity->timedue)
  3908. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  3909. } // if ($iassign_statement_activity_item->type_iassign > 1)
  3910. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  3911. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  3912. $output .= '</table>' . "\n";
  3913. print $OUTPUT->box($output);
  3914. } // function view_dates()
  3915. } // class activity
  3916. /// Class to manage Interactive Learning Module (iLM)
  3917. class ilm {
  3918. var $ilm;
  3919. /// Constructor of class
  3920. // @param int $id Id of iLM
  3921. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  3922. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  3923. function __construct ($id) {
  3924. global $DB;
  3925. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  3926. if (empty($this->ilm))
  3927. $this->ilm = null;
  3928. }
  3929. /// Shows activity in iLM
  3930. // @calledby view_iassign_current()
  3931. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  3932. global $USER, $CFG, $DB;
  3933. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  3934. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3935. $typec = strtolower($iassign_ilm->type);
  3936. require_once 'ilm_handlers/' . $typec . '.php';
  3937. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  3938. return $retorno;
  3939. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  3940. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  3941. // @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);
  3942. // @param int $iassign_statement_activity_itemid Id of iassign statement
  3943. // @param Object $file File in use in activity
  3944. // @return int Return the id of log
  3945. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  3946. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  3947. $newentry = new stdClass();
  3948. $newentry->iassign_statementid = $iassign_activity_itemid;
  3949. $newentry->userid = $USER->id;
  3950. $newentry->file = $content_or_id_from_ilm_security;
  3951. $newentry->timecreated = time();
  3952. $newentry->view = 1;
  3953. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  3954. if (!$id_iLM_security) {
  3955. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  3956. } // from (!$DB->insert_record("iassign_security", $newentry))
  3957. return $id_iLM_security;
  3958. }
  3959. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  3960. // @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);
  3961. // @param int $userid
  3962. // @param int $iassign_activity_itemid Id of iassign statement
  3963. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  3964. global $DB;
  3965. // 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")
  3966. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  3967. }
  3968. } // class ilm
  3969. /// Class to manage settings of iLM.
  3970. class ilm_settings {
  3971. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  3972. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  3973. // @param int $ilm_id Id of iLM
  3974. // @param array $options An array with options for create dynamic tag html APPLET
  3975. // @return string Return with a tag html APPLET created
  3976. static function build_ilm_tags ($ilm_id, $options = array()) {
  3977. global $DB;
  3978. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  3979. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  3980. $typec = strtolower($iassign_ilm->type);
  3981. require_once 'ilm_handlers/' . $typec . '.php';
  3982. $retorno = $typec::build_ilm_tags($ilm_id, $options);
  3983. return $retorno;
  3984. } // static function build_ilm_tags($ilm_id, $options = array())
  3985. /// Function for get modified date of iLM file
  3986. // @param string $file_jar String with Ids of iLM files
  3987. // @return string Return with the filenames and modified date
  3988. static function applet_filetime ($file_jar) {
  3989. $filetime = "";
  3990. $fs = get_file_storage(); // Get reference to all files in Moodle data
  3991. $files_jar = explode(",", $file_jar);
  3992. foreach ($files_jar as $one_file) {
  3993. $file = $fs->get_file_by_id($one_file);
  3994. if ($file)
  3995. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  3996. }
  3997. return $filetime;
  3998. }
  3999. /// Function for verify an default applet
  4000. // @param String $file_jar String containing an list de ids of applet files
  4001. // @return boolean Return true or fale if applet is default
  4002. static function applet_default ($file_jar) {
  4003. $is_default = true;
  4004. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4005. $files_jar = explode(",", $file_jar);
  4006. foreach ($files_jar as $one_file) {
  4007. $file = $fs->get_file_by_id($one_file);
  4008. if ($file)
  4009. $is_default &= ($file->get_itemid() == 0);
  4010. }
  4011. return $is_default;
  4012. }
  4013. /// Function for get form variables for add, edit, or copy iLM
  4014. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4015. // @see settings_form.php
  4016. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4017. // @param int $ilm_id Id of iLM
  4018. // @param string $action String with the action
  4019. // @return object Return an object with forms variables
  4020. static function add_edit_copy_ilm ($ilm_id, $action) {
  4021. global $USER, $DB, $CFG;
  4022. require_once('settings_form.php'); // put the form
  4023. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4024. $param = new stdClass();
  4025. $param->action = $action;
  4026. $param->ilm_id = $ilm_id;
  4027. $CFG->action_ilm = $action;
  4028. $CFG->ilm_id = $ilm_id;
  4029. if ($action == 'add') {
  4030. $param->title = get_string('add_ilm', 'iassign');
  4031. $param->name = "";
  4032. $param->version = "";
  4033. $param->url = "";
  4034. $param->description = "";
  4035. $param->extension = "";
  4036. $param->author = $USER->id;
  4037. $param->file_jar = "";
  4038. $param->file_jar_static = "";
  4039. $param->file_class = "";
  4040. $param->width = 800;
  4041. $param->height = 600;
  4042. $param->enable = 0; // 0 - hide / 1 - show
  4043. $param->timecreated = time();
  4044. $param->timemodified = time();
  4045. $param->evaluate = 0;
  4046. $param->parent = 0;
  4047. }
  4048. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4049. if ($iassign_ilm) {
  4050. $description = json_decode($iassign_ilm->description);
  4051. $param->title = get_string('edit_ilm', 'iassign');
  4052. $param->id = $iassign_ilm->id;
  4053. $param->name_ilm = $iassign_ilm->name;
  4054. $param->name = $iassign_ilm->name;
  4055. $param->version = $iassign_ilm->version;
  4056. $param->ilm_type = $iassign_ilm->type;
  4057. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4058. $param->url = $iassign_ilm->url;
  4059. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4060. if (!isset($description->{current_language()})) {
  4061. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4062. else
  4063. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4064. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4065. }
  4066. else
  4067. $param->description = $description->{current_language()};
  4068. $param->description_lang = $iassign_ilm->description;
  4069. $param->extension = $iassign_ilm->extension;
  4070. $param->author = $iassign_ilm->author;
  4071. $param->file_jar = $iassign_ilm->file_jar;
  4072. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4073. $param->file_class = $iassign_ilm->file_class;
  4074. $param->width = $iassign_ilm->width;
  4075. $param->height = $iassign_ilm->height;
  4076. $param->enable = $iassign_ilm->enable;
  4077. $param->timecreated = $iassign_ilm->timecreated;
  4078. $param->timemodified = time();
  4079. $param->evaluate = $iassign_ilm->evaluate;
  4080. $param->parent = $iassign_ilm->parent;
  4081. }
  4082. }
  4083. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4084. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4085. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4086. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4087. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4088. // echo "Sem dados<br/>"; exit;
  4089. return;
  4090. }
  4091. $description = json_decode($iassign_ilm->description);
  4092. if ($iassign_ilm) {
  4093. if ($iassign_ilm->parent == 0)
  4094. $iassign_ilm->parent = $ilm_id;
  4095. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4096. $param->title = get_string('new_version_ilm', 'iassign');
  4097. $param->name_ilm = $iassign_ilm->name;
  4098. $param->name = $iassign_ilm->name;
  4099. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4100. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4101. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4102. $param->ilm_type = $iassign_ilm->type;
  4103. $param->url = $iassign_ilm->url;
  4104. $param->description = $description->{current_language()};
  4105. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4106. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4107. $param->extension = $iassign_ilm->extension;
  4108. $param->author = $USER->id;
  4109. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4110. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4111. $param->file_jar_static = '';
  4112. $param->file_class = $iassign_ilm->file_class;
  4113. $param->width = $iassign_ilm->width;
  4114. $param->height = $iassign_ilm->height;
  4115. $param->enable = 0;
  4116. $param->timecreated = time();
  4117. $param->timemodified = time();
  4118. $param->evaluate = $iassign_ilm->evaluate;
  4119. $param->parent = $iassign_ilm->parent;
  4120. }
  4121. }
  4122. elseif ($action == 'copy') {
  4123. $description = json_decode($iassign_ilm->description);
  4124. if ($iassign_ilm) {
  4125. if ($iassign_ilm->parent == 0)
  4126. $iassign_ilm->parent = $ilm_id;
  4127. $param->title = get_string('copy_ilm', 'iassign');
  4128. $param->id = $iassign_ilm->id;
  4129. $param->name_ilm = $iassign_ilm->name;
  4130. $param->name = $iassign_ilm->name;
  4131. $param->version = "";
  4132. $param->ilm_type = $iassign_ilm->type;
  4133. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4134. $param->url = $iassign_ilm->url;
  4135. $param->description = $description->{current_language()};
  4136. $param->description_lang = $iassign_ilm->description;
  4137. $param->extension = $iassign_ilm->extension;
  4138. $param->author = $USER->id;
  4139. $param->file_jar = '';
  4140. $param->file_jar_static = '';
  4141. $param->file_class = $iassign_ilm->file_class;
  4142. $param->width = $iassign_ilm->width;
  4143. $param->height = $iassign_ilm->height;
  4144. $param->enable = 0;
  4145. $param->timecreated = time();
  4146. $param->timemodified = time();
  4147. $param->evaluate = $iassign_ilm->evaluate;
  4148. $param->parent = $iassign_ilm->parent;
  4149. }
  4150. }
  4151. return $param;
  4152. } // static function add_edit_copy_ilm($ilm_id, $action)
  4153. /// Function for save iLM file in moodledata
  4154. // @param int $itemid Itemid of file save in draft (upload file)
  4155. // @param int $ilm_id Id of iLM
  4156. // @return string Return an string with ids of iLM files
  4157. static function new_file_ilm ($itemid, $iassign_ilm) {
  4158. global $CFG, $USER, $DB;
  4159. $return = null;
  4160. $file_jar = array();
  4161. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4162. $contextuser = context_user::instance($USER->id);
  4163. $contextsystem = context_system::instance();
  4164. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4165. if ($files_ilm) {
  4166. foreach ($files_ilm as $value) {
  4167. // CHECK IF file is HTML type
  4168. if ($iassign_ilm->type == 1) {
  4169. // Check if the file extension is ZIP
  4170. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4171. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4172. if ((strtolower($ext) == 'zip')) {
  4173. // Coping...:
  4174. $destination = 'ilm_debug/' . $value->get_filename();
  4175. $value->copy_content_to($destination);
  4176. // Extracting content...:
  4177. $zip = new ZipArchive();
  4178. $extracted = './ilm';
  4179. $dir = "";
  4180. if ($zip->open($destination) === TRUE) {
  4181. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4182. if (is_dir($dir)) {
  4183. $i = 1;
  4184. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4185. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4186. $i ++;
  4187. }
  4188. $name = $previous . "_" . $i;
  4189. $dir = './ilm/' . $name . "/";
  4190. $j = 0;
  4191. while ($item_name = $zip->getNameIndex($j)) {
  4192. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4193. $j++;
  4194. }
  4195. $zip->close();
  4196. }
  4197. $zip->open($destination);
  4198. $zip->extractTo($extracted);
  4199. $zip->close();
  4200. // After the extraction, remove it from DEBUG
  4201. unlink($destination);
  4202. } else { // Error trying to open destination...
  4203. // After the extraction error, also remove it from DEBUG
  4204. unlink($destination);
  4205. print_error('error_add_ilm_zip', 'iassign');
  4206. }
  4207. return $dir;
  4208. }
  4209. } // if ($iassign_ilm->type == 1)
  4210. if ($value->get_filename() != '.') {
  4211. $file_ilm = array(
  4212. 'userid' => $USER->id,
  4213. 'contextid' => $contextsystem->id,
  4214. 'component' => 'mod_iassign',
  4215. 'filearea' => 'ilm',
  4216. 'itemid' => rand(1, 999999999),
  4217. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4218. 'filename' => $value->get_filename());
  4219. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4220. array_push($file_jar, $file_ilm->get_id());
  4221. }
  4222. }
  4223. if (!empty($file_jar)) {
  4224. $return = implode(",", $file_jar);
  4225. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4226. foreach ($old_file_jar as $value) {
  4227. $file = $fs->get_file_by_id($value);
  4228. if ($file)
  4229. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4230. }
  4231. }
  4232. }
  4233. else // if ($files_ilm)
  4234. $return = $iassign_ilm->file_jar;
  4235. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4236. return $return;
  4237. } // static function new_file_ilm($itemid, $iassign_ilm)
  4238. /// Function for save in database an new iLM
  4239. // @param object $param An object with iLM params
  4240. static function new_ilm ($itemid) {
  4241. global $CFG, $USER, $OUTPUT;
  4242. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4243. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4244. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4245. }
  4246. $pathtemp = $CFG->dataroot . '/temp/';
  4247. $contextuser = context_user::instance($USER->id);
  4248. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4249. $zip = new zip_packer();
  4250. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4251. foreach ($files as $file) {
  4252. if (!$file->is_directory())
  4253. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4254. }
  4255. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4256. // Verifica se o pacote possui o XML
  4257. if (!$application_xml) {
  4258. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4259. return;
  4260. } else {
  4261. $missing = "";
  4262. if (!isset($application_xml->name)) {
  4263. $missing .= "name";
  4264. }
  4265. if (!isset($application_xml->version)) {
  4266. $missing .= ", version";
  4267. }
  4268. if (!isset($application_xml->type)) {
  4269. $missing .= ", type";
  4270. }
  4271. if (!isset($application_xml->extension)) {
  4272. $missing .= ", extension";
  4273. }
  4274. if (!isset($application_xml->file_jar)) {
  4275. $missing .= ", file_jar";
  4276. }
  4277. if (!isset($application_xml->file_class)) {
  4278. $missing .= ", file_class";
  4279. }
  4280. if (!isset($application_xml->width)) {
  4281. $missing .= ", width";
  4282. }
  4283. if (!isset($application_xml->height)) {
  4284. $missing .= ", height";
  4285. }
  4286. if (!isset($application_xml->evaluate)) {
  4287. $missing .= ", evaluate";
  4288. }
  4289. if (strlen($missing) > 2) {
  4290. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4291. return;
  4292. }
  4293. }
  4294. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4295. $typec = strtolower($application_xml->type);
  4296. require_once 'ilm_handlers/' . $typec . '.php';
  4297. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4298. return $retorno;
  4299. } // static function new_ilm($itemid)
  4300. /// Function for save in database an iLM edit
  4301. // @param object $param An object with iLM params
  4302. static function edit_ilm ($param, $itemid) {
  4303. // Descobrir o tipo de iLM:
  4304. global $DB, $USER, $CFG;
  4305. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4306. $pathtemp = $CFG->dataroot . '/temp/';
  4307. $contextuser = context_user::instance($USER->id);
  4308. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4309. $zip = new zip_packer();
  4310. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4311. $files_extract = null;
  4312. foreach ($files as $file) {
  4313. if (!$file->is_directory())
  4314. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4315. }
  4316. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4317. $typec = strtolower($iassign_t->type);
  4318. require_once 'ilm_handlers/' . $typec . '.php';
  4319. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4320. }
  4321. /// Function for register the new iLM (in database and in the directory)
  4322. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4323. // @param object $param An object with iLM params
  4324. static function copy_new_version_ilm ($param) {
  4325. global $DB, $CFG, $USER;
  4326. $itemid = $param->file;
  4327. $pathtemp = $CFG->dataroot . '/temp/';
  4328. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4329. //D echo "pathtemp=$pathtemp<br/>";
  4330. $contextuser = context_user::instance($USER->id);
  4331. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4332. $zip = new zip_packer();
  4333. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4334. $files_extract = null;
  4335. foreach ($files as $file) {
  4336. if (!$file->is_directory())
  4337. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4338. }
  4339. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4340. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4341. $typec = strtolower($iassign_t->type);
  4342. require_once 'ilm_handlers/' . $typec . '.php';
  4343. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4344. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4345. } // static function copy_new_version_ilm($param)
  4346. //VER::
  4347. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4348. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4349. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4350. /// Function for change visibility of iLM
  4351. // @param int $ilm_id Id of iLM
  4352. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4353. static function visible_ilm ($ilm_id, $status) {
  4354. global $DB;
  4355. if ($status == 0)
  4356. $visible = 1;
  4357. else
  4358. $visible = 0;
  4359. $newentry = new stdClass();
  4360. $newentry->id = $ilm_id;
  4361. $newentry->enable = $visible;
  4362. if (!$DB->update_record("iassign_ilm", $newentry))
  4363. error(get_string('error_edit_ilm', 'iassign'));
  4364. }
  4365. /// Function for confirm change default iLM
  4366. // @param int $ilm_id Id of iLM
  4367. // @param int $ilm_parent Id of parent iLM
  4368. // @return string Return with an string for create default page confirmation
  4369. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4370. global $OUTPUT, $DB;
  4371. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4372. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4373. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4374. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4375. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4376. return $return;
  4377. }
  4378. /// Function for change the default iLM
  4379. // @see settings_ilm.php
  4380. // @param int $ilm_id Id of iLM
  4381. // @return int Return Id of default iLM
  4382. static function default_ilm ($ilm_id) {
  4383. global $DB;
  4384. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4385. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4386. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4387. $iassign_ilm_default->id = $iassign_ilm->id;
  4388. $iassign_ilm_default->parent = 0;
  4389. $iassign_ilm->parent = $iassign_ilm_default->id;
  4390. $iassign_ilm->id = 0;
  4391. $iassign_ilm_default->enable = 1;
  4392. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4393. print_error('error_edit_ilm', 'iassign');
  4394. }
  4395. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4396. if (!$inserted) {
  4397. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4398. print_error($msg_error);
  4399. //xx print_error('error_add_ilm', 'iassign');
  4400. }
  4401. return $iassign_ilm_default->id;
  4402. } // static function default_ilm ($ilm_id)
  4403. /// Function for confirm delete iLM
  4404. // @param int $ilm_id Id of iLM
  4405. // @param int $ilm_parent Id of parent iLM
  4406. // @return string Return with an string for create delete page confirmation
  4407. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4408. global $OUTPUT, $DB;
  4409. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4410. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4411. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4412. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4413. }
  4414. /// Function for delete directory where the iLM is allocated.
  4415. // @param string $dirPath
  4416. // @throws InvalidArgumentException
  4417. public static function delete_dir ($dirPath) {
  4418. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4419. $dirPath .= '/';
  4420. }
  4421. $files = glob($dirPath . '*', GLOB_MARK);
  4422. foreach ($files as $file) {
  4423. if (is_dir($file)) {
  4424. ilm_settings::delete_dir($file);
  4425. } else {
  4426. unlink($file);
  4427. }
  4428. }
  4429. rmdir($dirPath);
  4430. }
  4431. /// Function for delete iLM
  4432. // @param int $ilm_id Id of iLM
  4433. // @return int Return Id of parent iLM
  4434. static function delete_ilm ($ilm_id) {
  4435. global $DB;
  4436. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4437. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4438. $typec = strtolower($iassign_ilm->type);
  4439. require_once 'ilm_handlers/' . $typec . '.php';
  4440. $retorno = $typec::delete_ilm($ilm_id);
  4441. return $retorno;
  4442. }
  4443. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4444. // @param int $ilm_id Id of iLM
  4445. static function export_ilm ($ilm_id) {
  4446. global $DB;
  4447. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4448. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4449. $typec = strtolower($iassign_ilm->type);
  4450. require_once 'ilm_handlers/' . $typec . '.php';
  4451. $typec::export_ilm($ilm_id);
  4452. } // static function export_ilm($ilm_id)
  4453. //TODO iLM_HTML5 :: //MOOC 2016
  4454. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4455. // @param int $ilm_id Id of iLM
  4456. static function export_update_ilm ($ilm_id) {
  4457. global $DB, $CFG;
  4458. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4459. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4460. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4461. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4462. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4463. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4464. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4465. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4466. $upgrade_descriptor .= '</upgrade>' . "\n";
  4467. file_put_contents($xml_filename, $upgrade_descriptor);
  4468. header("Pragma: public");
  4469. header("Expires: 0");
  4470. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4471. header("Cache-Control: private", false);
  4472. header('Content-Type: application/xml; charset=utf-8');
  4473. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4474. header("Content-Length: " . @filesize($xml_filename));
  4475. set_time_limit(0);
  4476. @readfile("$xml_filename") || die("File not found.");
  4477. unlink($xml_filename);
  4478. exit;
  4479. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4480. /// Function for save iLM from XML descriptor
  4481. // @param array $application_xml Data of XML descriptor
  4482. // @param array $files_extract Filenames of extract files
  4483. // @return array Return an array content id of JAR files
  4484. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4485. global $CFG, $USER;
  4486. // Tratamento diferenciado se for do tipo HTML5:
  4487. $source = "";
  4488. $diretorio = "";
  4489. if (strtolower($application_xml->type) == 'html5') {
  4490. $i = 0;
  4491. foreach ($files_extract as $key => $value) {
  4492. $file = $CFG->dataroot . '/temp/' . $key;
  4493. // Verifica se já existe a pasta no diretório dos iLM:
  4494. if ($i == 0) {
  4495. $source = $file;
  4496. if (file_exists("ilm/" . basename($file))) {
  4497. $j = 1;
  4498. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4499. $j ++;
  4500. }
  4501. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4502. // mkdir($diretorio, 0777, true);
  4503. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4504. }
  4505. else {
  4506. $diretorio = 'ilm/' . basename($file);
  4507. // mkdir($diretorio, 0777, true);
  4508. mkdir($diretorio, 0755, true);
  4509. }
  4510. break;
  4511. }
  4512. $i ++;
  4513. }
  4514. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4515. if ($item->isDir()) {
  4516. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4517. }
  4518. else {
  4519. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4520. }
  4521. }
  4522. ilm_settings::delete_dir($source);
  4523. return "./" . $diretorio;
  4524. }
  4525. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4526. $file_jar = array();
  4527. $files_ilm = explode(",", $application_xml->file_jar);
  4528. $contextsystem = context_system::instance();
  4529. foreach ($files_ilm as $value) {
  4530. $file_ilm = array(
  4531. 'userid' => $USER->id,
  4532. 'contextid' => $contextsystem->id,
  4533. 'component' => 'mod_iassign',
  4534. 'filearea' => 'ilm',
  4535. 'itemid' => rand(1, 999999999),
  4536. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  4537. 'filename' => $value);
  4538. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  4539. array_push($file_jar, $file_ilm->get_id());
  4540. }
  4541. foreach ($files_extract as $key => $value) {
  4542. $file = $CFG->dataroot . '/temp/' . $key;
  4543. if (file_exists($file))
  4544. unlink($file);
  4545. }
  4546. return $file_jar;
  4547. } // static function save_ilm_by_xml($application_xml, $files_extract)
  4548. /// Function for import the iLM from an package
  4549. // @param int $itemid Itemid of zip file
  4550. static function import_ilm ($itemid) {
  4551. global $CFG, $USER, $OUTPUT;
  4552. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4553. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4554. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4555. }
  4556. $pathtemp = $CFG->dataroot . '/temp/';
  4557. $contextuser = context_user::instance($USER->id);
  4558. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4559. $zip = new zip_packer();
  4560. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4561. foreach ($files as $file) {
  4562. if (!$file->is_directory())
  4563. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4564. }
  4565. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4566. // Verifica se o pacote possui o XML
  4567. if (!$application_xml) {
  4568. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4569. return;
  4570. } else {
  4571. $missing = "";
  4572. if (!isset($application_xml->name)) {
  4573. $missing .= "name";
  4574. }
  4575. if (!isset($application_xml->version)) {
  4576. $missing .= ", version";
  4577. }
  4578. if (!isset($application_xml->type)) {
  4579. $missing .= ", type";
  4580. }
  4581. if (!isset($application_xml->extension)) {
  4582. $missing .= ", extension";
  4583. }
  4584. if (!isset($application_xml->file_jar)) {
  4585. $missing .= ", file_jar";
  4586. }
  4587. if (!isset($application_xml->file_class)) {
  4588. $missing .= ", file_class";
  4589. }
  4590. if (!isset($application_xml->width)) {
  4591. $missing .= ", width";
  4592. }
  4593. if (!isset($application_xml->height)) {
  4594. $missing .= ", height";
  4595. }
  4596. if (!isset($application_xml->evaluate)) {
  4597. $missing .= ", evaluate";
  4598. }
  4599. if (strlen($missing) > 2) {
  4600. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4601. return;
  4602. }
  4603. }
  4604. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4605. $typec = strtolower($application_xml->type);
  4606. require_once 'ilm_handlers/' . $typec . '.php';
  4607. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4608. } // static function import_ilm($itemid)
  4609. /// Function for list iLM defaults
  4610. // @return string Return an string with a table of iLM
  4611. static function list_ilm () {
  4612. global $DB, $OUTPUT;
  4613. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  4614. $str = '';
  4615. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  4616. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  4617. if ($iassign_ilm) {
  4618. foreach ($iassign_ilm as $ilm) {
  4619. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  4620. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  4621. $str .= '<tr><td>';
  4622. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  4623. $str .= '<tr>';
  4624. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  4625. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  4626. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  4627. $str .= '</tr>';
  4628. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  4629. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  4630. $str .= '</table>';
  4631. $str .= '</td></tr>';
  4632. }
  4633. }
  4634. $str .= '</table>';
  4635. return $str;
  4636. }
  4637. /// Function for download and install an upgrade of an iLM
  4638. // @param int $ilm_id Id of iLM
  4639. static function upgrade_ilm ($ilm_id) {
  4640. global $DB, $CFG, $USER;
  4641. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4642. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  4643. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  4644. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  4645. if (!$result)
  4646. print_error('error_upgrade_ilm', 'iassign');
  4647. else {
  4648. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  4649. $extension = explode(".", $zip_filename);
  4650. if ($extension[count($extension) - 1] != 'ipz') {
  4651. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  4652. die;
  4653. }
  4654. $zip = new zip_packer();
  4655. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4656. $contextuser = context_user::instance($USER->id);
  4657. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  4658. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4659. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  4660. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  4661. if (file_exists($zip_filename))
  4662. unlink($zip_filename);
  4663. if (empty($file_jar)) {
  4664. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  4665. print_error($msg_error);
  4666. //xx print_error('error_add_ilm', 'iassign');
  4667. }
  4668. else {
  4669. $newentry = new stdClass();
  4670. $newentry->name = (String) $application_xml->name;
  4671. $newentry->version = (String) $application_xml->version;
  4672. $newentry->url = (String) $application_xml->url;
  4673. $newentry->description = $description_str;
  4674. $newentry->extension = strtolower((String) $application_xml->extension);
  4675. $newentry->file_jar = implode(",", $file_jar);
  4676. $newentry->file_class = (String) $application_xml->file_class;
  4677. $newentry->width = (String) $application_xml->width;
  4678. $newentry->height = (String) $application_xml->height;
  4679. $newentry->enable = 0;
  4680. $newentry->timemodified = time();
  4681. $newentry->author = $USER->id;
  4682. $newentry->timecreated = time();
  4683. $newentry->evaluate = (String) $application_xml->evaluate;
  4684. $newentry->parent = $ilm_id;
  4685. }
  4686. }
  4687. return $iassign_ilm->id;
  4688. } // static function upgrade_ilm($ilm_id)
  4689. //MOOC2014 -- inicio
  4690. //TODO: REVIEW
  4691. // static function confirm_move_iassign($ilmid, $ilm_parent)
  4692. // static function move_iassign($ilm_id)
  4693. //MOOC2014 -- final
  4694. /// Function for list iLM versions with all informations
  4695. // @return string Return an string with a table of iLM
  4696. static function view_ilm ($ilmid, $from) {
  4697. global $DB;
  4698. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  4699. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4700. $typec = strtolower($iassign_ilm->type);
  4701. require_once 'ilm_handlers/' . $typec . '.php';
  4702. $retorno = $typec::view_ilm($ilmid, $from);
  4703. return $retorno;
  4704. }
  4705. /// Function for get form variables for add, edit, or copy iLM params
  4706. // @param int $ilm_param_id Id of iLM param
  4707. // @param string $action String with the action
  4708. // @return object Return an object with forms variables
  4709. static function add_edit_copy_param ($ilm_param_id, $action) {
  4710. global $DB;
  4711. require_once('params_form.php');
  4712. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  4713. $param = new stdClass();
  4714. $param->action = $action;
  4715. $param->ilm_param_id = $ilm_param_id;
  4716. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  4717. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  4718. $type = $iassign_ilm_config->param_type;
  4719. if ($action == 'add') {
  4720. $param->title = get_string('add_ilm', 'iassign');
  4721. $param->iassign_ilmid = $ilm_param_id;
  4722. $param->param_name = "";
  4723. $param->param_value = "";
  4724. $param->description = "";
  4725. $param->visible = 1;
  4726. }
  4727. elseif ($action == 'edit') {
  4728. if ($iassign_ilm_config) {
  4729. $param->title = get_string('edit_ilm', 'iassign');
  4730. $param->id = $iassign_ilm_config->id;
  4731. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4732. $param->param_type = $type; //MOOC2014
  4733. $param->param_name = $iassign_ilm_config->param_name;
  4734. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4735. $param->param_value = $iassign_ilm_config->param_value;
  4736. else //MOOC2014
  4737. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4738. $param->param_value = $iassign_ilm_config->param_value;
  4739. $param->description = $iassign_ilm_config->description;
  4740. $param->visible = $iassign_ilm_config->visible;
  4741. }
  4742. }
  4743. elseif ($action == 'copy') {
  4744. if ($iassign_ilm_config) {
  4745. $param->title = get_string('copy_ilm', 'iassign');
  4746. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  4747. $param->param_type = $type; //MOOC2014
  4748. $param->param_name = $iassign_ilm_config->param_name;
  4749. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  4750. $param->param_value = $iassign_ilm_config->param_value;
  4751. else //MOOC2014
  4752. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  4753. $param->description = $iassign_ilm_config->description;
  4754. $param->visible = $iassign_ilm_config->visible;
  4755. }
  4756. }
  4757. return $param;
  4758. } // static function add_edit_copy_param($ilm_param_id, $action)
  4759. /// Function for change visibility of iLM param
  4760. // @param int $ilm_param_id Id of iLM param
  4761. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4762. static function visible_param ($ilm_param_id, $status) {
  4763. global $DB, $CFG;
  4764. if ($status == 0)
  4765. $visible = 1;
  4766. else
  4767. $visible = 0;
  4768. $newentry = new stdClass();
  4769. $newentry->id = $ilm_param_id;
  4770. $newentry->visible = $visible;
  4771. if (!$DB->update_record("iassign_ilm_config", $newentry))
  4772. error(get_string('error_edit_param', 'iassign'));
  4773. }
  4774. /// Function for save in database an new iLM param
  4775. // @param object $param An object with iLM params
  4776. static function add_param ($param) {
  4777. global $DB;
  4778. $newentry = new stdClass();
  4779. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4780. //MOOC2014 $newentry->param_name = $param->param_name;
  4781. $newentry->param_type = $param->param_type; //MOOC2014
  4782. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4783. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4784. $newentry->param_value = $param->param_value;
  4785. else //MOOC2014
  4786. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4787. $newentry->description = $param->description;
  4788. $newentry->visible = $param->visible;
  4789. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4790. if (!$newentry->id) {
  4791. print_error('error_add_param', 'iassign');
  4792. }
  4793. }
  4794. /// Function for save in database a iLM param edit
  4795. // @param object $param An object with iLM params
  4796. static function edit_param ($param) {
  4797. global $DB;
  4798. $updentry = new stdClass();
  4799. $updentry->id = $param->id;
  4800. $updentry->iassign_ilmid = $param->iassign_ilmid;
  4801. $updentry->param_type = $param->param_type; //MOOC2014
  4802. // $updentry->param_name = $param->param_name;
  4803. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4804. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  4805. $updentry->param_value = $param->param_value;
  4806. else //MOOC2014
  4807. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4808. $updentry->description = $param->description;
  4809. $updentry->visible = $param->visible;
  4810. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  4811. error(get_string('error_edit_param', 'iassign'));
  4812. }
  4813. }
  4814. /// Function for save in database a iLM param copy
  4815. // @param object $param An object with iLM params
  4816. static function copy_param ($param) {
  4817. global $DB;
  4818. $newentry = new stdClass();
  4819. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4820. //$newentry->param_name = $param->param_name;
  4821. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  4822. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  4823. $newentry->param_value = $param->param_value;
  4824. else //MOOC2014
  4825. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  4826. $newentry->description = $param->description;
  4827. $newentry->visible = $param->visible;
  4828. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  4829. if (!$newentry->id) {
  4830. print_error('error_add_param', 'iassign');
  4831. }
  4832. }
  4833. /// Function for delete iLM param of database
  4834. // @param int $param_id Id of iLM param
  4835. static function delete_param ($param_id) {
  4836. global $DB;
  4837. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  4838. print_error('error_delete_param', 'iassign');
  4839. }
  4840. }
  4841. } // class ilm_settings
  4842. /// Class for manage iLM files (editor).
  4843. class ilm_manager {
  4844. var $id; // course id
  4845. var $url;
  4846. var $from;
  4847. /// Constructor for the base ilm_manager class
  4848. // 3.1 update PHP 7.0 compatibility for all moodle versions
  4849. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  4850. function __construct ($id, $url, $from) {
  4851. $this->id = $id; // course id
  4852. $this->url = $url;
  4853. $this->from = $from;
  4854. }
  4855. /// Function to get iAssign content file in Moodle data (exercise)
  4856. // @calledby x function preview_ilm($iassign_ilm) :
  4857. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  4858. function get_file_ilm () {
  4859. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  4860. $fileid = optional_param('fileid', NULL, PARAM_INT);
  4861. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  4862. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4863. $md_file = $fs->get_file_by_id($fileid);
  4864. $ilm_content_file = $md_file->get_content();
  4865. return $ilm_content_file;
  4866. }
  4867. /// Function for creating a new file from the iLM online editor
  4868. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  4869. function ilm_editor_new () {
  4870. global $CFG, $DB, $OUTPUT, $PAGE;
  4871. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  4872. $dirid = optional_param('dirid', NULL, PARAM_INT);
  4873. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  4874. $context = context_course::instance($this->id);
  4875. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  4876. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  4877. if (!$iassign) {
  4878. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  4879. die();
  4880. }
  4881. $temp = explode(",", $iassign->extension);
  4882. $extension = $temp[0]; // default extension for this iLM
  4883. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  4884. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  4885. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  4886. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  4887. if ($stringArchiveContent != NULL) {
  4888. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  4889. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  4890. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  4891. $filename = optional_param('filename', NULL, PARAM_RAW);
  4892. //Leo $filename = iassign_utils::format_filename($filename); //
  4893. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  4894. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  4895. //2019/02 $arrayfilename = explode(".", $filename);
  4896. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  4897. //2019/02 $count_dots = count($arrayfilename);
  4898. //2019/02 if ($count_dots > 0) { // at least one dot mark
  4899. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  4900. //2019/02 if ($last_name != $extension)
  4901. //2019/02 $filename = $filename . '.' . $extension;
  4902. //2019/02 }
  4903. //2019/02 else { // no extension...
  4904. //2019/02 $filename = $filename . '.' . $extension;
  4905. //2019/02 }
  4906. // Store the name of recent created file
  4907. $_SESSION['file_name'] = $filename;
  4908. //$this->write_file_iassign($string, $filename);
  4909. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  4910. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  4911. die();
  4912. }
  4913. else { // if ($stringArchiveContent != NULL)
  4914. // iLM On-line editor
  4915. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  4916. $str_get_iLM = "window.frames.iLM";
  4917. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  4918. }
  4919. else { // otherwise it is JAR named 'iLM'
  4920. $str_get_iLM = "document.iLM";
  4921. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  4922. }
  4923. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4924. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  4925. $files_array = '';
  4926. foreach ($files as $value) {
  4927. if ($value->get_filename() != ".")
  4928. $files_array .= "'" . $value->get_filename() . "',";
  4929. }
  4930. $files_array .= "''";
  4931. $file = null;
  4932. $ia_content = "";
  4933. $filename = "";
  4934. $error_files_exists = get_string('error_file_exists', 'iassign');
  4935. $output = "<script type='text/javascript'>
  4936. //<![CDATA[
  4937. //D alert('locallib.php: ilm_editor_new');
  4938. function submit_iLM_Answer () {
  4939. var docFormOnLineEditor = document.formEnvio;
  4940. var resposta_exerc = new Array(3);
  4941. var valor_resposta = new Array(3);
  4942. var sessao = new Array(3);
  4943. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  4944. resposta_exerc[0] = doc_iLM.getAnswer();
  4945. valor_resposta[0] = doc_iLM.getEvaluation();
  4946. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  4947. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  4948. var files = new Array(" . $files_array . ");
  4949. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  4950. if (docFormOnLineEditor.filename.value=='') {
  4951. // ERROR: the file name is empty
  4952. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  4953. return false;
  4954. }
  4955. // }
  4956. for (i=0; i<files.length; i++) {
  4957. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  4958. alert('" . $error_files_exists . "');
  4959. return false;
  4960. }
  4961. }
  4962. docFormOnLineEditor.submit();
  4963. return true;
  4964. }
  4965. //]]>
  4966. </script>\n";
  4967. $output .= "
  4968. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  4969. $output .= $OUTPUT->box_start();
  4970. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  4971. $output .= "
  4972. <table width='100%' cellpadding='20'>
  4973. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  4974. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  4975. <td><input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  4976. </tr>
  4977. </table>\n";
  4978. $output .= $OUTPUT->box_end();
  4979. $output .= "<center>\n";
  4980. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4981. // Since it is the activity file, it is not necessary to use 'ilm_security'
  4982. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  4983. $output .= $output_ilm;
  4984. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  4985. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  4986. </center>
  4987. </form>\n";
  4988. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  4989. $PAGE->navbar->add($title);
  4990. $PAGE->set_title($title);
  4991. $PAGE->set_heading($title); // insert title above the navigation bar
  4992. print $OUTPUT->header();
  4993. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  4994. print $output;
  4995. print $OUTPUT->footer();
  4996. }
  4997. die();
  4998. } // function ilm_editor_new()
  4999. /// Function for editing an file in online editor
  5000. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5001. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5002. global $CFG, $DB, $OUTPUT, $PAGE;
  5003. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5004. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5005. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5006. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5007. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5008. // If iLM is not registered, error!
  5009. if (!$iassign) {
  5010. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5011. die;
  5012. }
  5013. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5014. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5015. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5016. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5017. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5018. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5019. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5020. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5021. if ($stringArchiveContent != NULL) {
  5022. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5023. die();
  5024. } else { // if ($stringArchiveContent != NULL)
  5025. $end_file = '';
  5026. if ($content_file) {
  5027. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5028. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5029. }
  5030. $temp = explode(",", $iassign->extension);
  5031. $extension = $temp[0]; // default extension for this iLM
  5032. if ($extension == "html" || $extension == "ivph") { // if iLM is HTML5 is inside a frame
  5033. $str_get_iLM = "window.frames.iLM";
  5034. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5035. } else { // otherwise it is JAR named 'iLM'
  5036. $str_get_iLM = "document.iLM";
  5037. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5038. }
  5039. $output = "<script type='text/javascript'>
  5040. //<![CDATA[
  5041. function submit_iLM_Answer () {
  5042. var docFormEditor = document.formEnvio;
  5043. var activityAnswer; // to get activity answer (text)
  5044. var activityValue; // to get activity answer value (float)
  5045. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5046. //activityAnswer = doc_iLM.getAnswer();
  5047. //activityValue = doc_iLM.getEvaluation();
  5048. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5049. activityValue = " . $str_get_iLM . ".getEvaluation();
  5050. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5051. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5052. docFormEditor.submit();
  5053. return true;
  5054. }
  5055. //]]>
  5056. </script>\n";
  5057. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5058. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5059. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5060. // return true;
  5061. // }
  5062. $output .= "
  5063. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5064. $output .= $OUTPUT->box_start();
  5065. $output .= "
  5066. <table width='100%' cellpadding='20'>
  5067. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5068. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5069. <input type='hidden' name='filename' value='$filename'/></td>
  5070. <td>
  5071. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5072. </tr>
  5073. </table>\n";
  5074. $output .= $OUTPUT->box_end();
  5075. $output .= " <center>\n";
  5076. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5077. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5078. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5079. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5080. </center>
  5081. </form>\n";
  5082. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5083. $PAGE->navbar->add($title);
  5084. $PAGE->set_title($title);
  5085. $PAGE->set_heading($title); // insert title above the navigation bar
  5086. print $OUTPUT->header();
  5087. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5088. print $output;
  5089. print $OUTPUT->footer();
  5090. } // else if ($stringArchiveContent != NULL)
  5091. die();
  5092. } // function ilm_editor_update()
  5093. /// Function for write iAssign file in Moodle data (exercise)
  5094. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5095. // @param string $stringArchiveContent Content of iassign file
  5096. // @param string $filename Filename of iassign file
  5097. function write_file_iassign ($stringArchiveContent, $filename) {
  5098. global $USER;
  5099. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5100. $context = context_course::instance($this->id);
  5101. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5102. $dirid = $this->get_dir_ilm('dirid');
  5103. $dir = $fs->get_file_by_id($dirid);
  5104. $fileinfo = array('contextid' => $context->id, // ID of course
  5105. 'component' => 'mod_iassign', // usually = table name
  5106. 'filearea' => 'activity', // usually = table name
  5107. 'itemid' => 0, // usually = ID of row in table
  5108. 'filepath' => '/', // any path beginning and ending whith '/'
  5109. 'userid' => $USER->id,
  5110. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5111. 'filename' => $filename); // any filename
  5112. // Create file containing text. '$stringArchiveContent'
  5113. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5114. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5115. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5116. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5117. // 'Activité interactive enregistrée avec succès sous le nom:';
  5118. // 'Atividade interativa gravada com sucesso sob o nome:'
  5119. $output = "
  5120. <script type='text/javascript'>
  5121. //<![CDATA[
  5122. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5123. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5124. //]]>
  5125. </script>";
  5126. print $output;
  5127. die();
  5128. }
  5129. /// Function for write iAssign file in Moodle data (exercise)
  5130. // @param string $stringArchiveContent Content of iassign file
  5131. // @param string $filename Filename of iassign file
  5132. // @param int $itemid Itemid of iassign file
  5133. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5134. global $OUTPUT, $USER;
  5135. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5136. $context = context_course::instance($this->id);
  5137. $dirid = $this->get_dir_ilm('dirid');
  5138. if ($stringArchiveContent != (-1)) {
  5139. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5140. $file = $fs->get_file_by_id($fileid);
  5141. if (!$file) {
  5142. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5143. die;
  5144. }
  5145. $fileinfo = array('contextid' => $context->id, // ID of context
  5146. 'component' => 'mod_iassign', // usually = table name
  5147. 'filearea' => 'activity', // usually = table name
  5148. 'itemid' => 0, // usually = ID of row in table
  5149. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5150. 'userid' => $USER->id,
  5151. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5152. 'license' => 'allrightsreserved', // allrightsreserved
  5153. 'timecreated' => $file->get_timecreated(),
  5154. 'filename' => $file->get_filename()); // any filename
  5155. $file->delete();
  5156. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5157. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5158. }
  5159. $output = "<script type='text/javascript'>
  5160. //<![CDATA[
  5161. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5162. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5163. //]]>
  5164. </script>";
  5165. print $output;
  5166. die();
  5167. }
  5168. /// Function for create an tag for iAssign filter
  5169. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5170. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5171. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5172. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5173. // @param int $fileid Id of file
  5174. // @return string Return an string with an tag of iassign filter
  5175. function tag_ilm ($fileid) {
  5176. global $DB;
  5177. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5178. $width = '600';
  5179. $height = '400';
  5180. $file = $fs->get_file_by_id($fileid);
  5181. $filetype = explode(".", $file->get_filename());
  5182. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5183. foreach ($iassign_ilm as $value) {
  5184. $extensions = explode(",", $value->extension);
  5185. if (in_array($filetype[1], $extensions)) {
  5186. $width = $value->width;
  5187. $height = $value->height;
  5188. }
  5189. }
  5190. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5191. }
  5192. /// Function for delete iAssign file in Moodle data (exercise)
  5193. function delete_file_ilm () {
  5194. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5195. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5196. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5197. $file = $fs->get_file_by_id($fileid);
  5198. if ($file)
  5199. $file->delete();
  5200. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5201. die();
  5202. }
  5203. /// Function for delete selected iAssign file in Moodle data (exercise)
  5204. function delete_selected_ilm () {
  5205. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5206. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5207. $context = context_course::instance($this->id);
  5208. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5209. $dirid = $this->get_dir_ilm('dirid');
  5210. foreach ($files_id as $file_id) {
  5211. $file = $fs->get_file_by_id($file_id);
  5212. if ($file) {
  5213. if (!$file->is_directory())
  5214. $file->delete();
  5215. else {
  5216. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5217. foreach ($files_delete as $value)
  5218. $value->delete();
  5219. $file->delete();
  5220. }
  5221. }
  5222. }
  5223. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5224. die();
  5225. }
  5226. /// Function for duplicate iAssign file from "online" edition
  5227. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5228. function duplicate_file_ilm () {
  5229. global $USER, $COURSE;
  5230. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5231. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5232. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5233. $filename = optional_param('filename', NULL, PARAM_RAW);
  5234. $file = $fs->get_file_by_id($fileid);
  5235. $context = context_course::instance($this->id);
  5236. $fileinfo = array(
  5237. 'contextid' => $context->id, // ID of context
  5238. 'component' => 'mod_iassign', // usually = table name
  5239. 'filearea' => 'activity', // usually = table name
  5240. 'itemid' => 0, // usually = ID of row in table
  5241. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5242. 'userid' => $USER->id,
  5243. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5244. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5245. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5246. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5247. die();
  5248. }
  5249. /// Function for rename iAssign file
  5250. function rename_file_ilm () {
  5251. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5252. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5253. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5254. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5255. $file = $fs->get_file_by_id($fileid);
  5256. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5257. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5258. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5259. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5260. die();
  5261. }
  5262. /// Function for get iassign file for iassign form
  5263. function add_ilm () {
  5264. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5265. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5266. $output = "
  5267. <script type='text/javascript'>
  5268. //<![CDATA[
  5269. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5270. iassign_file_link.innerHTML = '$filename';
  5271. window.opener.document.forms['mform1'].file.value='$fileid';
  5272. window.opener.document.forms['mform1'].filename.value='$filename';
  5273. window.close();
  5274. //]]>
  5275. </script>";
  5276. print $output;
  5277. die();
  5278. }
  5279. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5280. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5281. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5282. function preview_ilm ($courseid, $iassign_ilm) {
  5283. global $OUTPUT, $CFG, $USER;
  5284. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5285. $title = get_string('modulename', 'iassign'); // iAssign
  5286. print $OUTPUT->header();
  5287. print $OUTPUT->box_start();
  5288. $javascript = "
  5289. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5290. <script type='text/javascript'>
  5291. //<![CDATA[
  5292. function submit_close () {
  5293. window.opener.location.reload();
  5294. window.close();
  5295. }
  5296. //]]>
  5297. </script>\n";
  5298. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5299. // to the complete "applet" tag
  5300. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5301. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5302. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5303. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5304. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5305. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5306. if ($ilm_name != "ivprog") {
  5307. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5308. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5309. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5310. } else {
  5311. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5312. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5313. $timecreated = time();
  5314. $token = md5($timecreated);
  5315. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5316. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5317. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5318. $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)
  5319. }
  5320. $html = "
  5321. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5322. <table border='1'>
  5323. <tr><td>
  5324. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5325. <!-- iLM calls : end -->
  5326. </td></tr>
  5327. </table>
  5328. <table>
  5329. <tr>
  5330. <td align='center'>
  5331. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5332. </td></tr>
  5333. </table>
  5334. </form>\n";
  5335. print $javascript . $html;
  5336. print $OUTPUT->box_end();
  5337. //NAO echo format_string($html); // Moodle 3.X
  5338. die();
  5339. } // function preview_ilm($courseid, $iassign_ilm)
  5340. //r_ function preview_ilm ($iassign_ilm)
  5341. //r_ /// Function for preview iassign file from iassign filter.
  5342. //r_ function preview_ilm() {
  5343. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5344. //r_ $tag_filter = $this->tag_ilm($fileid);
  5345. //r_ $javascript = "<script type='text/javascript'>
  5346. //r_ //<![CDATA[
  5347. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5348. //r_ //]]>
  5349. //r_ </script>";
  5350. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5351. //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>
  5352. //r_ </table></form></body></html>";
  5353. //r_ echo $javascript . format_text($html);
  5354. //r_ die;
  5355. //r_ }
  5356. /// Function for export an package (zip) of iassign files
  5357. function export_files_ilm () {
  5358. global $CFG;
  5359. $context = context_course::instance($this->id);
  5360. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5361. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5362. $zip = new zip_archive();
  5363. $zip->open($zip_filename);
  5364. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5365. foreach ($files_id as $file_id) {
  5366. $file = $fs->get_file_by_id($file_id);
  5367. if (!$file->is_directory())
  5368. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5369. else {
  5370. $zip->add_directory($file->get_filepath());
  5371. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5372. foreach ($files_zip as $value) {
  5373. if (!$value->is_directory())
  5374. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5375. else
  5376. $zip->add_directory($value->get_filepath());
  5377. }
  5378. }
  5379. }
  5380. $zip->close();
  5381. header("Pragma: public");
  5382. header("Expires: 0");
  5383. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5384. header("Cache-Control: private", false);
  5385. header("Content-Type: application/zip");
  5386. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5387. header("Content-Transfer-Encoding: binary");
  5388. header("Content-Length: " . @filesize($zip_filename));
  5389. set_time_limit(0);
  5390. @readfile("$zip_filename") || die("File not found.");
  5391. unlink($zip_filename);
  5392. exit;
  5393. }
  5394. /// Function of execute a command in button editor tinymce
  5395. // @param int $fileid Id of file
  5396. function tinymce_ilm ($fileid) {
  5397. $tag_filter = $this->tag_ilm($fileid);
  5398. $output = "<script type='text/javascript'>
  5399. //<![CDATA[
  5400. var tag_filter = '$tag_filter';
  5401. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5402. // all right, insert it
  5403. } else {
  5404. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5405. }
  5406. // window.close();
  5407. //]]>
  5408. </script>\n";
  5409. print $output;
  5410. die();
  5411. }
  5412. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5413. /// Function to add content to the Editor Window
  5414. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5415. // @param int $fileid Id of file
  5416. function editor_ilm ($fileid, $editor) {
  5417. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5418. $output1 = "<script type='text/javascript'>
  5419. //<![CDATA[
  5420. var tag_filter = '$tag_filter';\n";
  5421. if ($editor == 'atto') {
  5422. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5423. } elseif ($editor == 'tinyMCE') {
  5424. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5425. } else
  5426. $output2 = "";
  5427. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5428. window.close();
  5429. //]]>
  5430. </script>\n";
  5431. //D var_dump($output);
  5432. print $output1 . $output2 . $output3;
  5433. die();
  5434. }
  5435. /// Function to add content to the Atto Editor Window
  5436. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5437. // @param int $fileid Id of file
  5438. function atto_ilm ($fileid) {
  5439. global $CFG, $DB;
  5440. $tag_filter = $this->tag_ilm($fileid);
  5441. $output = "<script type='text/javascript'>
  5442. //<![CDATA[
  5443. var tag_filter = '$tag_filter';
  5444. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5445. // all right, insert iLM tag to this editor
  5446. } else {
  5447. // error trying to insert
  5448. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5449. }
  5450. //window.close();
  5451. //]]>
  5452. </script>\n";
  5453. print $output;
  5454. die();
  5455. }
  5456. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5457. // @param string $key Key for return information
  5458. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5459. function get_dir_ilm ($key) {
  5460. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5461. $context = context_course::instance($this->id);
  5462. $dirid = optional_param('dirid', 0, PARAM_INT);
  5463. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5464. if ($dirid == 0) {
  5465. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5466. $dirid = $dir->get_id();
  5467. }
  5468. else {
  5469. $dir = $fs->get_file_by_id($dirid);
  5470. $dir_base = $dir->get_filepath();
  5471. }
  5472. $dir_parent = $dir->get_parent_directory();
  5473. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5474. return $data[$key];
  5475. }
  5476. /// Function for create an new dir
  5477. function new_dir_ilm () {
  5478. global $USER;
  5479. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5480. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5481. $dir_base = $this->get_dir_ilm('dir_base');
  5482. $context = context_course::instance($this->id);
  5483. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5484. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5485. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5486. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5487. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5488. }
  5489. /// Function for delete an dir
  5490. function delete_dir_ilm () { //
  5491. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5492. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5493. $context = context_course::instance($this->id);
  5494. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5495. $dir_parent = $this->get_dir_ilm('dir_parent');
  5496. if ($dir) {
  5497. if ($dir->is_directory()) {
  5498. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5499. foreach ($files_delete as $value)
  5500. $value->delete();
  5501. $dir->delete();
  5502. }
  5503. }
  5504. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5505. die();
  5506. }
  5507. /// Function for rename an dir
  5508. function rename_dir_ilm () {
  5509. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5510. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5511. $context = context_course::instance($this->id);
  5512. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5513. $dir_parent = $this->get_dir_ilm('dir_parent');
  5514. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5515. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5516. if ($dir->is_directory()) {
  5517. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5518. foreach ($files_rename_path as $value)
  5519. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5520. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5521. }
  5522. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5523. die();
  5524. }
  5525. /// Function for move an dir and your content for other dir
  5526. function selected_move_ilm () {
  5527. global $PAGE, $OUTPUT, $CFG;
  5528. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5529. $context = context_course::instance($this->id);
  5530. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5531. $dirid = $this->get_dir_ilm('dirid');
  5532. $dir_base = $this->get_dir_ilm('dir_base');
  5533. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5534. $code_javascript_ilm = "
  5535. <script type='text/javascript'>
  5536. //<![CDATA[
  5537. function getRadiobutton () {
  5538. var radioButtons = document.getElementsByTagName('input');
  5539. var param = '';
  5540. for (var counter=0; counter < radioButtons.length; counter++) {
  5541. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  5542. param = radioButtons[counter].value;
  5543. }
  5544. return param;
  5545. }
  5546. function move_selected_ilm () {
  5547. var msgAnswer;
  5548. if (getRadiobutton() != '') {
  5549. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  5550. if (msgAnswer)
  5551. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  5552. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  5553. }
  5554. else
  5555. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  5556. }
  5557. function cancel_selected_ilm () {
  5558. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5559. }
  5560. //]]>
  5561. </script>\n";
  5562. $title = get_string('move_files', 'iassign');
  5563. $PAGE->set_title($title);
  5564. $PAGE->set_pagelayout('base');
  5565. print $OUTPUT->header();
  5566. print $OUTPUT->heading($title);
  5567. $dir_paths = array();
  5568. print $OUTPUT->box_start();
  5569. print "<center>";
  5570. foreach ($files_id as $file_id) {
  5571. $file = $fs->get_file_by_id($file_id);
  5572. if ($file) {
  5573. if (!$file->is_directory())
  5574. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  5575. else {
  5576. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5577. array_push($dir_paths, $file->get_filepath());
  5578. }
  5579. }
  5580. }
  5581. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  5582. if ($dir_base != '/') {
  5583. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  5584. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  5585. }
  5586. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  5587. foreach ($files_tree as $file) {
  5588. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  5589. $is_parent = false;
  5590. foreach ($dir_paths as $dir) {
  5591. $path = explode("/", $dir);
  5592. array_pop($path);
  5593. $path[count($path) - 1] = '';
  5594. $path = implode("/", $path);
  5595. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  5596. $is_parent |= ($file->get_filepath() != $path ? false : true);
  5597. }
  5598. if ($is_parent == false) {
  5599. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  5600. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  5601. }
  5602. }
  5603. }
  5604. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  5605. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  5606. print "</center>";
  5607. print $OUTPUT->box_end();
  5608. print $OUTPUT->footer();
  5609. print $code_javascript_ilm;
  5610. die;
  5611. }
  5612. /// Function for move files for an dir
  5613. function move_files_ilm () {
  5614. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5615. $context = context_course::instance($this->id);
  5616. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5617. $dirid = $this->get_dir_ilm('dirid');
  5618. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  5619. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5620. foreach ($files_id as $file_id) {
  5621. $file = $fs->get_file_by_id($file_id);
  5622. if ($file) {
  5623. if ($file->is_directory()) {
  5624. $pathname = explode("/", $file->get_filepath());
  5625. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5626. foreach ($files_move_path as $value) {
  5627. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  5628. $value->rename($path_move, $value->get_filename());
  5629. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  5630. }
  5631. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  5632. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  5633. $file->rename($path_move, $file->get_filename());
  5634. } else {
  5635. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  5636. $file->rename($dir_move->get_filepath(), $file->get_filename());
  5637. }
  5638. }
  5639. }
  5640. //die;
  5641. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  5642. die();
  5643. } // function move_files_ilm()
  5644. /// Function for recover files in use on all activities of a course
  5645. function recover_files_ilm () {
  5646. global $DB, $USER;
  5647. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5648. $courseid = optional_param('id', NULL, PARAM_INT);
  5649. $dirid = $this->get_dir_ilm('dirid');
  5650. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5651. $contextfile = context_course::instance($this->id);
  5652. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  5653. foreach ($iassigns as $iassign) {
  5654. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  5655. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  5656. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  5657. $context = context_module::instance($cm->id);
  5658. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  5659. if ($files) {
  5660. foreach ($files as $value) {
  5661. $extension = explode(".", $value->get_filename());
  5662. if (!$value->is_directory()) {
  5663. $fileinfo = array('contextid' => $contextfile->id,
  5664. 'component' => 'mod_iassign',
  5665. 'filearea' => 'activity',
  5666. 'itemid' => 0,
  5667. 'filepath' => $this->get_dir_ilm('dir_base'),
  5668. 'userid' => $USER->id,
  5669. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5670. 'license' => 'allrightsreserved',
  5671. 'timecreated' => time(),
  5672. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  5673. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  5674. }
  5675. }
  5676. } // if ($files)
  5677. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  5678. } // foreach ($iassigns as $iassign)
  5679. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5680. die();
  5681. } // function recover_files_ilm()
  5682. /// Auxiliary function the get all files in a given context
  5683. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5684. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  5685. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  5686. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  5687. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  5688. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  5689. // (NAO s_iassign_statement.file = s_files.id)
  5690. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5691. $dir_base = $this->get_dir_ilm('dir_base');
  5692. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5693. $countf = 0;
  5694. $array_files_id = array(); // all files from this context
  5695. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  5696. //$filename = $item_fc->get_filename();
  5697. //$filepath = $item_fc->get_filepath();
  5698. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  5699. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  5700. // $array_files_aux[] = $item_fc;
  5701. $itemid = $item_fc->get_id();
  5702. if (!in_array($itemid, $array_files_id)) {
  5703. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  5704. if ($fileuserid == $userid)
  5705. $filesfrommine[] = $item_fc;
  5706. else
  5707. $filesfromothers[] = $item_fc;
  5708. $array_files_id[] = $itemid;
  5709. $countf++;
  5710. }
  5711. }
  5712. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  5713. return $countf;
  5714. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  5715. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  5716. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5717. function get_all_ilm_files_by_fileid ($fileid) {
  5718. global $DB, $USER;
  5719. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  5720. //TODO Criar coluna 'authorid'
  5721. $str_query = "SELECT * FROM {iassign_statement} " .
  5722. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  5723. $array_iassign_ilm = $DB->get_records_sql($str_query);
  5724. return $array_iassign_ilm;
  5725. }
  5726. //NN
  5727. //NN
  5728. // Build string with JavaScript code with function to edit/remove/double iLM files
  5729. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  5730. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  5731. global $CFG;
  5732. $error_files_exists = get_string('error_file_exists', 'iassign');
  5733. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5734. $code_javascript_ilm = "
  5735. <script type='text/javascript'>
  5736. //<![CDATA[
  5737. function preview_ilm (fileid, ilmid) { //JavaScript function
  5738. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5739. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5740. }
  5741. function update_ilm (ilmid, fileid) { //JavaScript function
  5742. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5743. }
  5744. function delete_ilm (ilmid, fileid) { //JavaScript function
  5745. var msgAnswer;
  5746. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5747. if (msgAnswer) {
  5748. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5749. }
  5750. }
  5751. function delete_selected_ilm () { //JavaScript function
  5752. var msgAnswer;
  5753. var param = getCheckbox();
  5754. if (param.join() != '') {
  5755. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5756. if (msgAnswer)
  5757. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5758. }
  5759. else
  5760. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5761. }
  5762. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  5763. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5764. }
  5765. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  5766. var filenamecopy;
  5767. var i;
  5768. var files = new Array(" . $files_array . ");
  5769. do {
  5770. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5771. } while (filenamecopy == '');
  5772. if (filenamecopy == null)
  5773. return false;\n
  5774. else {
  5775. for (i=0;i<files.length;i++) {
  5776. if (files[i]==filenamecopy) {
  5777. alert('" . $error_files_exists . "');
  5778. return false;\n
  5779. }
  5780. }\n" .
  5781. // @see: function 'duplicate_file_ilm()' above
  5782. "
  5783. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5784. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5785. } // else
  5786. }
  5787. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  5788. var filenamecopy;
  5789. var i;
  5790. var files = new Array($files_array);
  5791. do {
  5792. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5793. } while (filenamecopy == '');
  5794. if (filenamecopy == null)
  5795. return false;
  5796. else {
  5797. for (i=0;i<files.length;i++) {
  5798. if (files[i]==filenamecopy) {
  5799. alert('" . $error_files_exists . "');
  5800. return false;
  5801. }
  5802. }
  5803. 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;
  5804. }
  5805. }
  5806. function export_files_ilm () { //JavaScript function
  5807. var param = getCheckbox();
  5808. if (param.join() != '')
  5809. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  5810. else
  5811. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  5812. }
  5813. function select_all_ilm () { //JavaScript function
  5814. var checkBoxes = document.getElementsByTagName('input');
  5815. var selectAll = document.getElementById('select_all');
  5816. for (var counter=0; counter < checkBoxes.length; counter++) {
  5817. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  5818. checkBoxes[counter].checked = selectAll.checked;
  5819. }
  5820. }
  5821. function getCheckbox () { //JavaScript function
  5822. var checkBoxes = document.getElementsByTagName('input');
  5823. var param = new Array();
  5824. for (var counter=0; counter < checkBoxes.length; counter++) {
  5825. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  5826. param.push(checkBoxes[counter].value);
  5827. }
  5828. return param;
  5829. }
  5830. function new_dir_ilm () { //JavaScript function
  5831. var dirname = '';
  5832. var i;
  5833. var dirs = new Array(" . $dirs_array . ");
  5834. do {
  5835. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  5836. } while (dirname == '');
  5837. if (dirname == null)
  5838. return false;\n
  5839. else {
  5840. for (i=0;i<dirs.length;i++) {
  5841. if (dirs[i]==dirname) {
  5842. alert('" . $error_dir_exists . "');
  5843. return false;\n
  5844. }
  5845. }
  5846. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  5847. }
  5848. }
  5849. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  5850. var msgAnswer;
  5851. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  5852. if (msgAnswer) {
  5853. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  5854. }
  5855. }
  5856. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  5857. var dirnamecopy;
  5858. var i;
  5859. var dirs = new Array($dirs_array);
  5860. do {
  5861. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  5862. } while (dirnamecopy == '');
  5863. if (dirnamecopy == null)
  5864. return false;\n
  5865. else {
  5866. for (i=0;i<dirs.length;i++) {
  5867. if (dirs[i]==dirnamecopy) {
  5868. alert('" . $error_dir_exists . "');
  5869. return false;\n
  5870. }
  5871. }
  5872. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  5873. }
  5874. }
  5875. function move_selected_ilm (ilmid) { //JavaScript function
  5876. var param = getCheckbox();
  5877. if (param.join() != '')
  5878. 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();
  5879. else
  5880. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  5881. }
  5882. function recover_files_ilm () { //JavaScript function
  5883. var msgAnswer;
  5884. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  5885. if (msgAnswer) {
  5886. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  5887. }
  5888. }
  5889. window.onload = function() { //JavaScript function
  5890. var xPosition = 0;
  5891. var yPosition = 0;
  5892. element=document.getElementById('new_file');
  5893. while(element) {
  5894. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  5895. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  5896. element = element.offsetParent;
  5897. }
  5898. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  5899. document.getElementById('new_file').style.right = '' + 0 + 'px';
  5900. location.hash = '#new_file';
  5901. };
  5902. //]]>
  5903. </script>\n"; // end of $code_javascript_ilm
  5904. return $code_javascript_ilm;
  5905. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  5906. /// List iassign files from course directory
  5907. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  5908. function view_files_ilm ($iassign_ilm_class, $extension) {
  5909. global $CFG, $DB, $USER, $OUTPUT;
  5910. $fs = get_file_storage();
  5911. $context = context_course::instance($this->id);
  5912. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5913. $dirid = $this->get_dir_ilm('dirid');
  5914. $dir_base = $this->get_dir_ilm('dir_base');
  5915. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  5916. $files_array = '';
  5917. foreach ($files_course as $value) {
  5918. if (!$value->is_directory())
  5919. $files_array .= "'" . $value->get_filename() . "',";
  5920. }
  5921. $files_array .= "''";
  5922. $error_files_exists = get_string('error_file_exists', 'iassign');
  5923. $dirs_array = '';
  5924. foreach ($files_course as $value) {
  5925. if ($value->is_directory()) {
  5926. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  5927. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  5928. }
  5929. }
  5930. $dirs_array .= "''";
  5931. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  5932. // TODO Rever o preview pois só deixar ver uma vez.
  5933. $code_javascript_ilm = "
  5934. <script type='text/javascript'>
  5935. //<![CDATA[
  5936. function preview_ilm (fileid, ilmid) {
  5937. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  5938. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  5939. }
  5940. function update_ilm (ilmid, fileid) {
  5941. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5942. }
  5943. function delete_ilm (ilmid, fileid) {
  5944. var msgAnswer;
  5945. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  5946. if (msgAnswer) {
  5947. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  5948. }
  5949. }
  5950. function delete_selected_ilm () {
  5951. var msgAnswer;
  5952. var param = getCheckbox();
  5953. if (param.join() != '') {
  5954. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  5955. if (msgAnswer)
  5956. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  5957. }
  5958. else
  5959. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  5960. }
  5961. function add_ilm_iassign (ilmid, filename, fileid) {
  5962. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  5963. }
  5964. function duplicate_ilm (ilmid, filename, fileid) {
  5965. var filenamecopy;
  5966. var i;
  5967. var files = new Array($files_array);
  5968. do {
  5969. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  5970. } while (filenamecopy == '');
  5971. if (filenamecopy == null)
  5972. return false;\n
  5973. else {
  5974. for (i=0;i<files.length;i++) {
  5975. if (files[i]==filenamecopy) {
  5976. alert('$error_files_exists');
  5977. return false;\n
  5978. }
  5979. }\n" .
  5980. // @see: function 'duplicate_file_ilm()' above
  5981. "
  5982. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  5983. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  5984. } // else
  5985. }
  5986. function rename_ilm (ilmid, filename, fileid) {
  5987. var filenamecopy;
  5988. var i;
  5989. var files = new Array($files_array);
  5990. do {
  5991. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  5992. } while (filenamecopy == '');
  5993. if (filenamecopy == null)
  5994. return false;
  5995. else {
  5996. for (i=0;i<files.length;i++) {
  5997. if (files[i]==filenamecopy) {
  5998. alert('$error_files_exists');
  5999. return false;
  6000. }
  6001. }
  6002. 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;
  6003. }
  6004. }
  6005. function export_files_ilm () {
  6006. var param = getCheckbox();
  6007. if (param.join() != '')
  6008. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6009. else
  6010. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6011. }
  6012. function select_all_ilm () {
  6013. var checkBoxes = document.getElementsByTagName('input');
  6014. var selectAll = document.getElementById('select_all');
  6015. for (var counter=0; counter < checkBoxes.length; counter++) {
  6016. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6017. checkBoxes[counter].checked = selectAll.checked;
  6018. }
  6019. }
  6020. function getCheckbox () {
  6021. var checkBoxes = document.getElementsByTagName('input');
  6022. var param = new Array();
  6023. for (var counter=0; counter < checkBoxes.length; counter++) {
  6024. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6025. param.push(checkBoxes[counter].value);
  6026. }
  6027. return param;
  6028. }
  6029. function new_dir_ilm () {
  6030. var dirname = '';
  6031. var i;
  6032. var dirs = new Array($dirs_array);
  6033. do {
  6034. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6035. } while (dirname == '');
  6036. if (dirname == null)
  6037. return false;\n
  6038. else {
  6039. for (i=0;i<dirs.length;i++) {
  6040. if (dirs[i]==dirname) {
  6041. alert('$error_dir_exists');
  6042. return false;\n
  6043. }
  6044. }
  6045. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6046. }
  6047. }
  6048. function delete_dir_ilm (ilmid, dirid) {
  6049. var msgAnswer;
  6050. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6051. if (msgAnswer) {
  6052. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6053. }
  6054. }
  6055. function rename_dir_ilm (ilmid, dirname, dirid) {
  6056. var dirnamecopy;
  6057. var i;
  6058. var dirs = new Array($dirs_array);
  6059. do {
  6060. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6061. } while (dirnamecopy == '');
  6062. if (dirnamecopy == null)
  6063. return false;\n
  6064. else {
  6065. for (i=0;i<dirs.length;i++) {
  6066. if (dirs[i]==dirnamecopy) {
  6067. alert('$error_dir_exists');
  6068. return false;\n
  6069. }
  6070. }
  6071. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6072. }
  6073. }
  6074. function move_selected_ilm (ilmid) {
  6075. var param = getCheckbox();
  6076. if (param.join() != '')
  6077. 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();
  6078. else
  6079. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6080. }
  6081. function recover_files_ilm () {
  6082. var msgAnswer;
  6083. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6084. if (msgAnswer) {
  6085. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6086. }
  6087. }
  6088. window.onload = function() {
  6089. var xPosition = 0;
  6090. var yPosition = 0;
  6091. element=document.getElementById('new_file');
  6092. while(element) {
  6093. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6094. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6095. element = element.offsetParent;
  6096. }
  6097. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6098. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6099. location.hash = '#new_file';
  6100. };
  6101. //]]>
  6102. </script>\n";
  6103. $output = "";
  6104. $select_all = "";
  6105. $count_files = 0;
  6106. $extensions_allow = array();
  6107. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6108. foreach ($iassign_ilm as $item_iassign_ilm)
  6109. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6110. foreach ($files_course as $value) {
  6111. $filename = $value->get_filename();
  6112. $filepath = $value->get_filepath();
  6113. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6114. $pathname = $pathname[count($pathname) - 1];
  6115. $fileid = $value->get_id();
  6116. $tmp = explode(".", $filename);
  6117. if (count($tmp)>1) // avoid error if the file has no extension
  6118. $filetype = $tmp[1];
  6119. else // probably error...
  6120. $filetype = '';
  6121. $author = $value->get_author();
  6122. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6123. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6124. $extensions = explode(",", $extension);
  6125. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6126. $count_files ++;
  6127. // buscar fileid nas tabelas do iassign
  6128. $list_filein_use = "";
  6129. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6130. if ($iassign_statement_activity_list) {
  6131. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6132. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6133. }
  6134. }
  6135. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6136. if (!$iassign_ilm) {
  6137. $iassign_ilm = new stdClass();
  6138. $iassign_ilm->id = $ilmid;
  6139. }
  6140. // Do not use $var inside "..." - problem with some "unusual" operational system
  6141. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6142. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6143. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6144. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6145. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6146. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6147. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6148. $check_select = "";
  6149. $link_rename = "";
  6150. $link_delete = "";
  6151. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6152. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6153. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6154. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6155. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6156. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6157. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6158. if ($value->get_userid() == $USER->id) {
  6159. if ($iassign_statement_activity_list) {
  6160. $check_select = "";
  6161. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6162. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6163. $link_rename = "";
  6164. } else {
  6165. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6166. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6167. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6168. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6169. }
  6170. }
  6171. if (!in_array($filetype, $extensions_allow)) {
  6172. $link_edit = "";
  6173. $link_add_ilm_iassign = "";
  6174. $link_add_ilm_tinymce = "";
  6175. $link_add_ilm_atto = "";
  6176. $link_filter = "";
  6177. }
  6178. if ($value->is_directory()) {
  6179. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6180. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6181. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6182. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6183. <td><center>$author</center></td>
  6184. <td><center>$timecreated</center></td>
  6185. <td><center>$timemodified</center></td></tr>\n";
  6186. }
  6187. else if ($this->from == 'iassign') {
  6188. $new_id = "";
  6189. $new_class = "";
  6190. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6191. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6192. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6193. }
  6194. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6195. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6196. <td><center>$author</center></td>
  6197. <td><center>$timecreated</center></td>
  6198. <td><center>$timemodified</center></td></tr>\n";
  6199. }
  6200. else if ($this->from == 'block') {
  6201. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6202. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6203. <td><center>$author</center></td>
  6204. <td><center>$timecreated</center></td>
  6205. <td><center>$timemodified</center></td></tr>\n";
  6206. }
  6207. else if ($this->from == 'tinymce') {
  6208. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6209. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6210. <td><center>$author</center></td>
  6211. <td><center>$timecreated</center></td>
  6212. <td><center>$timemodified</center></td></tr>\n";
  6213. }
  6214. else if ($this->from == 'atto') {
  6215. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6216. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6217. <td><center>$author</center></td>
  6218. <td><center>$timecreated</center></td>
  6219. <td><center>$timemodified</center></td></tr>\n";
  6220. }
  6221. }
  6222. }
  6223. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6224. $dir_base = "";
  6225. $header = "";
  6226. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6227. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6228. foreach ($basename as $value) {
  6229. $dir_base .= $value . "/";
  6230. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6231. if ($dir_id) {
  6232. if ($value == "") {
  6233. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6234. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6235. } else {
  6236. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6237. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6238. }
  6239. }
  6240. } // foreach ($basename as $value)
  6241. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6242. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6243. $html .= "
  6244. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6245. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6246. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6247. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6248. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6249. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6250. </table>\n";
  6251. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6252. $html .= "<table width='100%'><tr>\n";
  6253. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6254. if ($count_files != 0) {
  6255. $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";
  6256. $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";
  6257. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6258. }
  6259. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6260. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6261. $html .= "</form>\n";
  6262. print $code_javascript_ilm;
  6263. print $html;
  6264. } // function view_files_ilm($extension)
  6265. } // class ilm_manager
  6266. /// Class to insert of icons
  6267. class iassign_icons {
  6268. static function insert ($icon) {
  6269. global $CFG;
  6270. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6271. return $string;
  6272. }
  6273. }
  6274. /// Class with util functions for plugin manage
  6275. class iassign_utils {
  6276. /// Function to return the filename extension
  6277. // @param string The $filename as an string
  6278. // @return string Return an string (last group after '.')
  6279. static function filename_extension ($filename) {
  6280. if ($filename == null || $filename == '') {
  6281. return null;
  6282. }
  6283. $itens = explode('.', $filename);
  6284. $num = count($itens);
  6285. if ($num < 2) {
  6286. return null;
  6287. }
  6288. return $itens[$num - 1];
  6289. }
  6290. /// Use the PHP class/package ZipArchive to create a Zip file
  6291. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6292. // 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
  6293. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6294. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6295. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6296. $zip = new zip_archive(); //2
  6297. $res = $zip->open($full_path_zip_filename);
  6298. $total_vet = count($vet_student_filename);
  6299. for ($ii=0; $ii<$total_vet; $ii++) {
  6300. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6301. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6302. }
  6303. $ret = $zip->close();
  6304. iassign_utils::download_file($full_path_zip_filename);
  6305. $filenameZip = $zip->filename;
  6306. return array($ret, $zip);
  6307. }
  6308. static function download_file ($zip_filename) {
  6309. header("Pragma: public");
  6310. header("Expires: 0");
  6311. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6312. header("Cache-Control: private", false);
  6313. header("Content-Type: application/zip");
  6314. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6315. header("Content-Transfer-Encoding: binary");
  6316. header("Content-Length: " . @filesize($zip_filename));
  6317. set_time_limit(0);
  6318. @readfile("$zip_filename") || die("File not found.");
  6319. unlink($zip_filename);
  6320. }
  6321. /// Function for format filename remove special caracters
  6322. // @param string $text String for clean
  6323. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6324. // @return string Return an string in clean format
  6325. static function format_filename ($text) {
  6326. if ($text != '.') {
  6327. //D $text = htmlspecialchars(urldecode($text));
  6328. //D echo "locallib.php: format_filename: $text<br/>";
  6329. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6330. $text = json_decode($text)->{current_language()};
  6331. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6332. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6333. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6334. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6335. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6336. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6337. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6338. // E.g. text = "exerc_midpoint.course.geo"
  6339. // 0123456789012345678901234
  6340. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6341. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6342. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6343. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6344. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6345. //$ext = strrpos($text, ".");
  6346. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6347. //$text = str_replace($array1, $array2, $text);
  6348. }
  6349. return $text;
  6350. }
  6351. /// Function to filter characters to the file name to iLM content
  6352. // @param string $text String for clean
  6353. // @param string $ext String ot the extension of the iLM
  6354. // @return string Return an string in clean format
  6355. static function filter_filename_extension ($filename, $ext) {
  6356. if ($filename != '.') {
  6357. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6358. $arrTo = array("_","","","","","","","","","","","","");
  6359. $filename = str_replace($arrFrom, $arrTo, $filename);
  6360. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6361. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6362. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6363. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6364. $index_lastposition = strlen($filenameF);
  6365. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6366. $text = str_replace(".", "_", $text); // erase all other "."
  6367. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6368. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6369. }
  6370. else
  6371. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6372. return $filenameF;
  6373. }
  6374. /// Function for format pathname remove special caracters
  6375. // @param string $text String for clean
  6376. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6377. // @return string Return an string in clean format
  6378. static function format_pathname ($text, $is_lowercase = true) {
  6379. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6380. $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", "-", "_", "", "", "");
  6381. $text = str_replace($array1, $array2, $text);
  6382. if ($is_lowercase)
  6383. $text = strtolower($text);
  6384. return $text;
  6385. }
  6386. /// Function for format file name from iLM original name
  6387. // @param string $text String to build the file neam
  6388. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6389. // @return string Return an string in clean format
  6390. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6391. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6392. $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", "-", "_", "", "", "");
  6393. $index_firstposition_blank = strpos($ilm_name, " ");
  6394. if ($index_firstposition_blank) { // truncate the name!
  6395. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6396. }
  6397. $index_firstposition_dots = strpos($ilm_name, ":");
  6398. if ($index_firstposition_dots) { // truncate the name!
  6399. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6400. }
  6401. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6402. if ($is_lowercase)
  6403. $namefiltered = strtolower($namefiltered);
  6404. return $namefiltered;
  6405. }
  6406. /// Function for insert version in the filename
  6407. // @param string $filename Name of file
  6408. // @return string Return the filename with version
  6409. static function version_filename ($filename) {
  6410. $array_filename = explode('.', $filename);
  6411. if (count($array_filename) > 1)
  6412. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6413. else
  6414. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6415. return $filename;
  6416. }
  6417. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6418. static function remove_code_message ($string) {
  6419. $array = explode("&lt;ia_uc&gt;", $string);
  6420. return $array[0];
  6421. }
  6422. }
  6423. // class iassign_utils
  6424. /// Class with language functions for plugin manage
  6425. class iassign_language {
  6426. /// Function for return text in language or get default language (en)
  6427. // @param string $lang Code of language
  6428. // @param string $description JSON text content all languages
  6429. // @return string Return an string in the language selected
  6430. static function get_description_lang ($lang, $descriptions) {
  6431. $description_lang = "";
  6432. $description = json_decode($descriptions);
  6433. if ($description == null) {
  6434. $description_lang = $descriptions;
  6435. }
  6436. else {
  6437. if (isset($description->{$lang}))
  6438. $description_lang = $description->{$lang};
  6439. else
  6440. if (isset($description->en)) //MOOC2014
  6441. $description_lang = $description->en;
  6442. else //MOOC2014
  6443. $description_lang = "en"; //MOOC2014
  6444. }
  6445. return $description_lang;
  6446. }
  6447. /// Function for return all language supported by iLM
  6448. // @param string $descriptions JSON text content all languages
  6449. // @return string Return as string with all languages
  6450. static function get_all_lang ($descriptions) {
  6451. $langs = "";
  6452. $description = json_decode($descriptions);
  6453. if ($description) {
  6454. foreach ($description as $key => $value) {
  6455. $langs .= $key . " ; ";
  6456. }
  6457. $langs = substr($langs, 0, strlen($langs) - 3);
  6458. }
  6459. return $langs;
  6460. }
  6461. /// Function for convert json in xml //MOOC2014
  6462. // @param string $json JSON text
  6463. // @return string Return as string with xml tags
  6464. static function json_to_xml ($json) {
  6465. $xml = "";
  6466. $json = json_decode($json);
  6467. foreach ($json as $key => $value) {
  6468. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6469. }
  6470. return $xml;
  6471. }
  6472. }
  6473. // class iassign_language
  6474. /// Class with log functions for plugin manage.
  6475. class iassign_log {
  6476. /// Function for insert log event
  6477. // @param string $action Code action of event
  6478. // @param string $information Text for describe action of event
  6479. // @param int $cmid Id of context module
  6480. // @param int $ilmid Id of iLM
  6481. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6482. global $COURSE, $CFG, $USER, $DB;
  6483. $newentry = new stdClass();
  6484. $newentry->time = time();
  6485. $newentry->userid = $USER->id;
  6486. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6487. $newentry->course = $COURSE->id;
  6488. $newentry->cmid = $cmid;
  6489. $newentry->ilmid = $ilmid;
  6490. $newentry->action = $action;
  6491. $newentry->info = $information;
  6492. $newentry->language = current_language();
  6493. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6494. if (ini_get("browscap") && function_exists('get_browse')) {
  6495. $browser = get_browse(null, true);
  6496. $newentry->javascript = $browser['javascript'];
  6497. $newentry->java = $browser['javaapplets'];
  6498. }
  6499. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6500. print_error('error_add_log', 'iassign');
  6501. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6502. } // class iassign_log