locallib.php 301 KB

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