locallib.php 320 KB

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