locallib.php 382 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248
  1. <?php
  2. /**
  3. * This class provides all the functionality for an ia (interactive activities).
  4. *
  5. * Release Notes:
  6. * - v 4.9.4 2020/05/28
  7. * + Detail fixed in old line 6789/7240, avoid error with file without extension ($filetype = $tmp[1];)
  8. *
  9. * - v 4.9.3 2020/01/16
  10. * + Several fixes to allow to move activities in a block and improvements in repository and to appear comment submission button
  11. *
  12. * - v 4.9.2 2019/03/13
  13. * + Several fixes to allow iLM under HTML stack
  14. *
  15. * - v 4.9.1 2017/11/02
  16. * + Fixed a bug with iGeom script - the view was not loading the CEO with activity (resulting in an error "Erro ao gravar na base de dados")
  17. * + function view_iassign_current(): it were inserted 2 'if(substr($ilm_name,0,5)=="igeom") if($iassign_statement_activity_item->special_param1==1) $lTA=true;' to call '$ilm->view_iLM(...lTA)'
  18. *
  19. * - v 4.9 2017/03/13
  20. * + Great number of changes to allow the use o iVProgH5 (e.g. function changed: from 'applet_ilm' to 'build_ilm_tags')
  21. *
  22. * - v 4.8 2016/05/12
  23. * + Function add_to_log() is deprecated it was then rewritten to the new events API
  24. * + Resolved: the field "description" table "iassign_ilm" was being filled with the codes in HTML when importing magnet package and
  25. * due to this the language field was not being displayed because in place of the quotes was recorded in the & quot field.
  26. * ("$description_str = htmlentities(str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML()));"
  27. * replaced by
  28. * "description_str = str_replace(array('<description>','</description>'), array('',''), $application_xml->description->asXML());")
  29. * - v 4.7 2016/02/17
  30. * + Moodle 3.X: now iAssign is working fine under version 3.X (iassign/version.php: '$module->' changed to '$plugin->'; iassign/locallib.php: 'format_text(...)' replaced 'filter_text(...)')
  31. * + Improved: now is possible to see the iGeom menus in preview (from iAssign Repository) - it depends on the version 1.3 of iAssign filter!
  32. * + Improved: new names for 'form.input.MA_POST_Archive' and 'form.input.MA_POST_Value', now: 'iLM_PARAM_ArchiveContent' and 'iLM_PARAM_ActivityEvaluation'
  33. * + BUG fixed: now it is fine the "online" edition of activities (in iAssign Repository) - inserted 'iLM_PARAM_Authoring' (iLM 2) and 'MA_POST_ArchiveTeacher' (iLM 1)
  34. * + BUG fixed: it is possible to change the name of any file in iAssign Repository - problems was in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  35. * + BUG fixed: it is possible to duplicate any file in iAssign Repository - problems also in 'optional_param(...)', 'PARAM_TEXT' replaced 'PARAM_ALPHANUMEXT'
  36. * + BUG fixed: now is possible to edit an iAssign activity with no new object been created (in iGeom: turn an example in exercise)
  37. *
  38. * --------------- (code bellow was used at our MOOC 2014)
  39. * - v 4.6 2014/02/25
  40. * + Fix bugs in filter function for open applets.
  41. * - v 4.5 2014/02/24
  42. * + Fix bugs in params.
  43. * + Insert new param type.
  44. * - v 4.4 2014/01/24
  45. * + Allow select type of params.
  46. * + Insert the use of applet params specific for activities.
  47. * - v 4.3 2014/01/23
  48. * + Insert function for move activities for other iLM (ilm_settings::confirm_move_iassign, ilm_settings::move_iassign).
  49. * - v 4.2 2016/02/13
  50. * + Fixed API usage to work fine under Moodle 3.X: ilm_editor_new()
  51. * --------------- (above code used at our MOOC 2014)
  52. *
  53. * - v 4.1 2013/12/13
  54. * + Insert log in iAssign actions.
  55. * + Allow use the language in iLM description (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm, iassign_language::get_description_lang, iassign_language::get_all_lang).
  56. * + Insert class for Log actions in system.
  57. * - v 4.0 2013/10/31
  58. * + Insert support of export iLM in zip packages (ilm_settings::export_ilm).
  59. * + Insert support of import iLM from zip packages (ilm_settings::import_ilm).
  60. * + Fix bugs in message alert in iassign title and remove message alert of the description by cache error.
  61. * - v 3.9 2013/10/25
  62. * + Insert support of upgrade iLM.
  63. * + Insert support for more than one extension in iLM.
  64. * + Fix bugs in verion control.
  65. * - v 3.8 2013/09/19
  66. * + Get data of general fields in iassign statement table (iassign::add_edit_iassign).
  67. * - v 3.7 2013/09/12
  68. * + Change tag APPLET in all functions of module (ilm::view_iLM, ilm_manager::ilm_editor_new, ilm_manager::ilm_editor_update).
  69. * + Insert tool for manage aditional params for iLM (ilm_settings::add_edit_copy_param, ilm_settings::visible_param, ilm_settings::add_param, ilm_settings::edit_param, ilm_settings::copy_param, ilm_settings::delete_param).
  70. * - v 3.6 2013/09/05
  71. * + Insert function ilm_settings::applet_ilm for create APPLET html tag.
  72. * + Insert function ilm_settings::applet_filetime for get modified date of iLM file.
  73. * + Change tag APPLET in function ilm_settings::view_ilm.
  74. * - v 3.5 2013/08/26
  75. * + Fix bug in download package iassign without answers (iassign::report).
  76. * - v 3.4 2013/08/23
  77. * + Fix bug in export package iassign.
  78. * - v 3.3 2013/08/22
  79. * + Insert functions for export users answer in iassign (iassign::export_file_answer, iassign::export_package_answer, iassign::view_iassign_current, iassign::report).
  80. * + Insert function for rename iassign file (ilm_manager::rename_file_ilm, ilm_manager::view_files_ilm).
  81. * - v 3.2 2013/08/21
  82. * + Change title link with message for get file for donwload file (ilm_manager::view_files_ilm).
  83. * + Change functions for import files for ilm_manager.php.
  84. * + Create static utils class for functions system utils (iassign_utils::format_filename, iassign_utils::version_filename).
  85. * - v 3.1 2013/08/15
  86. * + Change return file selected (ilm_manager::add_ilm).
  87. * + Insert functions for import files, export files and remove selected files (ilm_manager::view_files_ilm, ilm_manager::import_files_ilm, ilm_manager::export_files_ilm, ilm_manager::delete_selected_ilm).
  88. * - v 3.0 2013/08/02
  89. * + Insert link for view informations of iLMs in teacher view, same screen of admin view but wiht some features hide (ilm_settings::list_ilm, ilm_settings::view_ilm, iassign::view_iassigns).
  90. * - v 2.9 2013/08/01
  91. * + Fix bugs in functions ilm_settings::new_file_ilm, ilm_settings::copy_new_version_ilm, ilm_settings::add_edit_copy_ilm.
  92. * - v 2.8 2013/07/25
  93. * + Insert the activity name in header of view (activity::view_dates).
  94. * + Set function default iLM in view iLMs versions (ilm_settings::default_ilm and ilm_settings::confirm_default_ilm).
  95. * - v 2.7 2013/07/24
  96. * + Create link previous and next for student view in one activity (activity::view_dates).
  97. * + Fix bugs for view error in iLM not on DB in function iassign::view_iassign_current.
  98. * - v 2.6 2013/07/23
  99. * + Fix bugs for view files in function ilm_manager::view_files_ilm.
  100. * + Fix bugs for comment on teacher view in function iassign::view_iassign_current.
  101. * - v 2.5 2013/07/12
  102. * + Change iLM settings for accept versions (ilm_settings::new_file_ilm, ilm_settings::new_ilm, ilm_settings::edit_ilm, ilm_settings::copy_new_version_ilm).
  103. * + Insert new informations in iLMs table: created date, modified date, author, version, modified date of JAR (ilm_settings::view_ilm).
  104. * + Added support for PHP 7.0 Constructors and fallback for previous Moodle Versions (<3.1) - Márcio
  105. *
  106. * @author Patricia Alves Rodrigues
  107. * @author Leônidas O. Brandão
  108. * @contributor Igor Moreira Félix (2018-)
  109. * @contributor Márcio de Lima Passos (2014)
  110. * @version v 4.9.2 2019/03/13
  111. * @version v 4.8 2016/05/12
  112. * @package mod_iassign_lib
  113. * @since 2010/09/27
  114. * @copyright iMath (http://www.matematica.br) and LInE (http://line.ime.usp.br) - Computer Science Dep. of IME-USP (Brazil)
  115. *
  116. * <b>License</b>
  117. * - http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  118. */
  119. //TODO Review: eliminate iLM JAR under MoodleData? It is necessary to HTML5 packages (like iVProgH5), anyway
  120. //TODO Whenever under HTTPS, verify if MoodleData is working, if it is not, please use iLM JAR under WWW setting $CONF_WWW = 1
  121. //TODO (under HTTPS could fail 'pluginfile', like 'https://saw.atp.usp.br/pluginfile.php/1/mod_iassign/ilm/182563135/iassign/ilm/igeom/5920/iGeom.jar"'
  122. $CONF_WWW = 1; //TODO get iLM (JAR) from WWW, avoiding MoodleData
  123. /**
  124. * Standard base class for all iAssign
  125. */
  126. class iassign {
  127. var $cm;
  128. var $course;
  129. var $iassign;
  130. var $striassign;
  131. var $striassigns;
  132. var $context;
  133. var $activity;
  134. var $iassign_up;
  135. var $iassign_down;
  136. var $action;
  137. var $iassign_submission_current;
  138. var $userid_iassign;
  139. var $bottonPost;
  140. var $write_solution;
  141. var $view_iassign;
  142. // 3.1 update PHP 7.0 compatibility for all moodle versions
  143. //D public function iassign($iassign, $cm, $course) { self::__construct($iassign, $cm, $course); }
  144. /// Constructor for the base iassign class
  145. // @calledby ./mod/iassign/view.php : $iassigninstance = new iassign($iassign, $cm, $course)
  146. // @calledby ./mod/iassign/grade.php : $iassigninstance = new iassign($iassign, $cm, $course);
  147. // @calledby ./mod/iassign/renderer.php : return $this->render(new iassign_files($context, $itemid, $filearea));
  148. function __construct ($iassign, $cm, $course) {
  149. global $COURSE, $CFG, $USER, $DB;
  150. $botton = optional_param('botton', NULL, PARAM_TEXT);
  151. $this->userid_iassign = optional_param('userid_iassign', 0, PARAM_INT);
  152. if (!is_null($botton))
  153. $USER->iassignEdit = $botton;
  154. // The Moodle function 'optional_param(...)' allow to filter GET parameters over a click that launches, e.g., './mod/iassign/view.php&userid_iassign=6'
  155. // If "$var1 = optional_param('userid_iassign', 'NOT', PARAM_TEXT);", $var1 will be set to 6 (if 'userid_iassign' is not present, $var1 will be set to 'NOT'
  156. $this->iassign_up = optional_param('iassign_up', 0, PARAM_INT); // if parameter 'iassign_up' does not exists or it is not integer => use 0 as "default"
  157. $this->iassign_down = optional_param('iassign_down', 0, PARAM_INT);
  158. $this->iassign_submission_current = optional_param('iassign_submission_current', 0, PARAM_INT);
  159. $this->write_solution = optional_param('write_solution', 0, PARAM_INT);
  160. $this->action = optional_param('action', NULL, PARAM_TEXT);
  161. $this->cm = $cm;
  162. $this->context = context_module::instance($this->cm->id);
  163. if (!has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id))
  164. $this->userid_iassign = $USER->id;
  165. if ($course) {
  166. $this->course = $course;
  167. }
  168. else if ($this->cm->course == $COURSE->id) {
  169. $this->course = $COURSE;
  170. }
  171. else if (!$this->course = $DB->get_record('course', array('id' => $this->cm->course))) {
  172. print_error('invalidid', 'iassign');
  173. }
  174. $this->coursecontext = context_course::instance($this->course->id);
  175. if ($iassign) {
  176. $this->iassign = $iassign;
  177. }
  178. else if (!$this->iassign = $DB->get_record('iassign', array('id' => $this->cm->instance))) {
  179. print_error('invalidid', 'iassign');
  180. }
  181. $USER->context = context_module::instance($this->cm->id);
  182. $USER->cm = $this->cm->id;
  183. $this->iassign->cmidnumber = $this->cm->idnumber; // compatibility with modedit ia obj
  184. $this->iassign->courseid = $this->course->id; // compatibility with modedit ia obj
  185. $this->context = context_module::instance($this->cm->id);
  186. $this->striassign = get_string('modulename', 'iassign');
  187. $this->striassigns = get_string('modulenameplural', 'iassign');
  188. $this->return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $this->cm->id;
  189. $this->bottonPost = 0;
  190. $this->view_iassign = optional_param('action', false, PARAM_BOOL);
  191. $this->activity = new activity(optional_param('iassign_current', NULL, PARAM_TEXT));
  192. $this->view();
  193. } // function __construct($iassign, $cm, $course)
  194. /// Show iAssign by using the security filter (temporary data on '*_iassign_security')
  195. // This method provides the page to view each iLM with any interactive activity
  196. // @calledby view.php : $iassigninstance->view($id); that instantiate 'iassign' (constructor above)
  197. function view () { // This is an standard function for each iAssign instance (to not use parameters, it is ignored)
  198. global $USER, $DB, $OUTPUT;
  199. // $iassign_statementid = $this->iassign->iassign_statementid;
  200. if ($this->activity!=null && $this->activity->get_activity()!=null && isset($this->activity->get_activity()->id))
  201. $iassign_statementid = $this->activity->get_activity()->id;
  202. else
  203. $iassign_statementid = "";
  204. // '$this' has : iassign Object = cm ; course ; iassign ; striassign ; striassigns ; context ; activity ; iassign_up ; iassign_down ; action ; ... ; coursecontext ; return
  205. // If this user has no capability to View 'iassign': stop here
  206. require_capability('mod/iassign:view', $this->context);
  207. // Trigger module view event
  208. $event = \mod_iassign\event\course_module_viewed::create(array(
  209. 'objectid' => $this->iassign->id,
  210. 'context' => $this->context
  211. ));
  212. $event->add_record_snapshot('course', $this->course);
  213. $event->trigger();
  214. if ($this->action) { // when student do/redo activity or teacher see student solution
  215. $this->action(); // calls '$this->view_iLM();'
  216. }
  217. else {
  218. print $OUTPUT->header();
  219. $this->view_iassigns(); // show the iLM with the content
  220. print $OUTPUT->footer();
  221. }
  222. // Security: delete all records with an error loading iLM - 'iassign_security : id iassign_statementid userid file timecreated view'
  223. //D $DB->delete_records("iassign_security", array("userid" => $USER->id, "view" => 1));
  224. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  225. //D foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  226. $DB->delete_records("iassign_security", array("userid" => $USER->id, "iassign_statementid" => $iassign_statementid));
  227. //D $iassign_iLM_security = $DB->get_record("iassign_security", array("iassign_statementid" => $iassign_statementid));
  228. //D if ($iassign_iLM_security) foreach ($iassign_iLM_security as $item) { echo $iassign_iLM_security->id . " ; " . $iassign_iLM_security->iassign_statementid . " ; " . $iassign_iLM_security->userid . " ; " . $iassign_iLM_security->timecreated . " ; " . $iassign_iLM_security->view . " ; " . $iassign_iLM_security->file . "<br/>\n" }
  229. //D else echo "Apagou!<br/>";
  230. die();
  231. } // function view()
  232. /// Execute the action from Moodle (move, make visible, register the exercise (teacher) or its answer (learner)...)
  233. function action () {
  234. global $USER;
  235. // action:
  236. // up - move up activity (mover atividade para cima)
  237. // down - move down activity (mover atividade para baixo)
  238. // visible - view/hide activity (exibir/ocultar atividade)
  239. // delete - delete activity (excluir atividade)
  240. // deleteyes - confirms exclusion of activity (confirma exclusão de atividade)
  241. // deleteno - does not erase activity (não apaga atividade)
  242. // add - add activity (adicionar atividade)
  243. // edit - edit activity (modificar atividade)
  244. $action_iassign = array(
  245. 'newcomment' => '$this->add_comment();',
  246. 'view' => '$this->view_iassign_current();',
  247. 'get_answer' => '$this->get_answer();',
  248. 'repeat' => '$this->view_iassign_current();',
  249. 'overwrite' => '$this->get_answer();',
  250. 'stats_student' => '$this->stats_students();',
  251. 'download_answer' => '$this->export_file_answer();',
  252. 'download_all_answer' => '$this->export_package_answer();');
  253. $action_iassign_limit = array(
  254. 'view' => '$this->view_iassign_current();',
  255. //'newcomment' => '$this->get_answer();',
  256. 'viewsubmission' => '$this->view_iassign_current();',
  257. 'edit_status' => '$this->edit_status();',
  258. 'edit_grade' => '$this->edit_grade();',
  259. 'export_csv' => '$this->export_csv();',
  260. 'report' => '$this->report();',
  261. 'print' => '$this->report();',
  262. 'stats' => '$this->stats();',
  263. 'printstats' => '$this->stats();');
  264. $restricted = array('firstdown' => '$this->activity->move_iassign("firstdown", $this->iassign_down, $this->return);',
  265. 'up' => '$this->activity->move_iassign("up", $this->iassign_up, $this->return);',
  266. 'down' => '$this->activity->move_iassign("down", $this->iassign_down, $this->return);',
  267. 'visible' => '$this->activity->visible_iassign($this->return);',
  268. 'delete' => '$this->activity->delete($this->return);',
  269. 'deleteno' => '$this->return_home_course("confirm_not_delete_iassign");',
  270. 'deleteyes' => '$this->activity->deleteyes($this->return, $this);',
  271. 'add' => '$this->add_edit_iassign();',
  272. 'edit' => '$this->add_edit_iassign();',
  273. 'get_answer' => '$this->get_answer();',
  274. 'duplicate_activity' => '$this->duplicate_activity();',
  275. 'move_activity' => '$this->move_activity();',
  276. 'auto_evaluate' => '$this->auto_evaluate();',
  277. 'all_submissions' => '$this->all_submissions();',
  278. 'delete_submissions' => '$this->delete_submissions();',
  279. 'download_submissions' => '$this->download_submissions();',
  280. 'open_individual_submission' => '$this->open_individual_submission();',
  281. 'get_individual_submission' => '$this->get_individual_submission();',
  282. 'get_student_submission' => '$this->get_student_submission();',
  283. 'get_teacher_exercise' => '$this->get_teacher_exercise();',
  284. 'post_auto_eval_result' => '$this->post_auto_eval_result();'
  285. );
  286. $action_iassign_restricted = array_merge($restricted, $action_iassign_limit, $action_iassign);
  287. // On depends the user's capability: precedence to edit power ('editiassign'); after to analyse ('evaluateiassign'); otherwise only view (any other).
  288. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) { //xxxxxxxxxxxxxxxxxxxxxxxxxxx
  289. // When teacher is seeing student solution. By 'viewsubmission' goes to the function 'view_iassign_current()'
  290. eval($action_iassign_restricted[$this->action]); // Now load 'view_iassign_current()' with 'viewsubmission' or 'new_iassign($param)' by '$this->add_edit_iassign()'
  291. }
  292. elseif (has_capability('mod/iassign:evaluateiassign', $this->context, $USER->id)) {
  293. eval($action_iassign_limit[$this->action]);
  294. }
  295. else { // Student reaches this point
  296. // When student do/redo activity: do => action = "view"; redo => action = "repeat"
  297. // Arrive here with: "get_answer"; "view"
  298. if (isset($action_iassign[$this->action])) // avoid error if non capable user try direct acess
  299. eval($action_iassign[$this->action]); // Now load 'view_iassign_current()' with 'view'
  300. }
  301. } // function action()
  302. /// This method prints the student submission to a specific exercise
  303. function get_student_submission () {
  304. global $DB;
  305. $student = optional_param('iassign_student', NULL, PARAM_TEXT);
  306. $exercise = optional_param('iassign_exercise', NULL, PARAM_TEXT);
  307. if (!$student || !$exercise) exit;
  308. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $exercise, "userid" => $student));
  309. if ($iassign_submission)
  310. print($iassign_submission->answer);
  311. die();
  312. }
  313. /// This method prints the teacher exercise
  314. function get_teacher_exercise () {
  315. global $DB, $COURSE;
  316. $ilmid = optional_param('iassign_exercise', NULL, PARAM_INT);
  317. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $ilmid));
  318. $fs = get_file_storage(); // Get reference to all files in Moodle data
  319. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  320. foreach ($files as $file) {
  321. if ($file->get_filename() != ".") {
  322. print($file->get_content());
  323. }
  324. }
  325. die();
  326. }
  327. /// This method receives the data from auto_eval event
  328. /// @see auto_evaluate()
  329. function post_auto_eval_result () {
  330. global $COURSE, $CFG, $USER, $DB;
  331. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  332. exit;
  333. //ercise="+exercises[actual_exercise]+"&student="+students[actual_student]+"&grade="+(grade * actual_value),
  334. $exercise = optional_param('iassign_exercise', -1, PARAM_INT);
  335. $student = optional_param('student', -1, PARAM_INT);
  336. $grade = optional_param('grade', 0, PARAM_FLOAT);
  337. // 1: Recuperar a nota atual:
  338. $actual = $DB->get_record('iassign_submission', array('iassign_statementid' => $exercise, 'userid' => $student));
  339. // 2: Atualizar a tabela:
  340. $update_entry = new stdClass();
  341. $update_entry->id = $actual->id;
  342. $update_entry->previous_grade = $actual->grade;
  343. $update_entry->grade = $grade;
  344. // Update the iassign_submission
  345. $DB->update_record("iassign_submission", $update_entry);
  346. }
  347. /// Function to help download all_submissions files
  348. function download_submissions_help ($list) {
  349. global $DB, $CFG, $OUTPUT;
  350. // Get list of iLMs
  351. $ilm_list = $DB->get_records("iassign_ilm");
  352. // Get list of enrolled students:
  353. $params = array('shortname' => 'student');
  354. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  355. $context = context_course::instance($this->course->id);
  356. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  357. $students_list = $DB->get_records_sql(
  358. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  359. $json_obj = new stdclass();
  360. $json_obj->submissions = [];
  361. $csvfields = [];
  362. $csvfields[] = 'submissionid';
  363. $csvfields[] = 'file';
  364. $csvfields[] = 'filesize';
  365. $csvfields[] = 'timestamp';
  366. $csvfields[] = 'humandate';
  367. $csvfields[] = 'grade';
  368. $csvfields[] = 'userid';
  369. $csvfields[] = 'exerciseid';
  370. $json_obj->submissions[] = $csvfields;
  371. $exercise_dir = [];
  372. $exercises_list = [];
  373. foreach ($list as $item) {
  374. if (!in_array($item->iassign_statementid, $exercise_dir)) {
  375. $temp = $DB->get_record("iassign_statement", array("id" => $item->iassign_statementid));
  376. $exercises_list[] = $temp;
  377. $exercise_dir[] = $temp->id;
  378. }
  379. }
  380. $student_dir = [];
  381. $students_list = [];
  382. foreach ($list as $item) {
  383. if (!in_array($item->userid, $student_dir)) {
  384. $temp = $DB->get_record("user", array("id" => $item->userid));
  385. $students_list[] = $temp;
  386. $student_dir[] = $temp->id;
  387. }
  388. }
  389. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR;
  390. $zip_filename = $diretorio . 'package_iassign_'.time().'.zip';
  391. $zip = new zip_archive(); // create ZIP
  392. $zip->open($zip_filename);
  393. foreach($exercises_list as $exercise) {
  394. $dir_ex = iassign_utils::format_filename($exercise->name);
  395. $zip->add_directory(
  396. $dir_ex
  397. );
  398. $extension_ilm = '';
  399. foreach ($ilm_list as $ilm) {
  400. if ($exercise->iassign_ilmid == $ilm->id) {
  401. $extension_ilm = $ilm->extension;
  402. break;
  403. }
  404. }
  405. foreach ($students_list as $student) {
  406. $individual_dir =
  407. $dir_ex . DIRECTORY_SEPARATOR .
  408. iassign_utils::format_filename($student->firstname . ' ' . $student->lastname);
  409. $zip->add_directory(
  410. $individual_dir
  411. );
  412. $i = 1;
  413. foreach($list as $item) {
  414. if ($item->userid == $student->id
  415. && $item->iassign_statementid == $exercise->id) {
  416. $date = new DateTime();
  417. $date->setTimestamp($item->timecreated);
  418. $new_file = $individual_dir . DIRECTORY_SEPARATOR . iassign_utils::format_filename('submission_' . ($i++) . '_' . date_format($date, 'Y-m-d_H-i-s') . '.' . $extension_ilm);
  419. $zip->add_file_from_string($new_file, $item->answer);
  420. $temp_json = [];
  421. $temp_json[] = intval($item->id);
  422. $temp_json[] = $new_file;
  423. $temp_json[] = strlen($new_file);
  424. $temp_json[] = intval($item->timecreated);
  425. $temp_json[] = date_format($date, 'Y-m-d H-i-s');
  426. $temp_json[] = doubleval($item->grade);
  427. $temp_json[] = intval($item->userid);
  428. $temp_json[] = intval($exercise->id);
  429. $json_obj->submissions[] = $temp_json;
  430. }
  431. }
  432. }
  433. }
  434. $csv_str = "";
  435. foreach($json_obj->submissions as $sub) {
  436. $csv_str .= $this->csvstr($sub) . "\n";
  437. }
  438. $zip->add_file_from_string('index.csv', $csv_str);
  439. $zip->close();
  440. iassign_utils::download_file($zip_filename);
  441. exit;
  442. }
  443. function csvstr(array $fields) : string {
  444. $f = fopen('php://memory', 'r+');
  445. if (fputcsv($f, $fields) === false) {
  446. return false;
  447. }
  448. rewind($f);
  449. $csv_line = stream_get_contents($f);
  450. return rtrim($csv_line);
  451. }
  452. /// Download submissions from table iassign_allsubmissions
  453. function download_submissions () {
  454. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  455. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  456. exit;
  457. $type = optional_param('type', NULL, PARAM_TEXT);
  458. $item = optional_param('item', NULL, PARAM_TEXT);
  459. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  460. $iassign_id = optional_param('iassign', NULL, PARAM_TEXT);
  461. $sub_list = [];
  462. if ($type == 'individual') {
  463. $sub_list[] = $DB->get_record(
  464. 'iassign_allsubmissions', array('id' => $item));
  465. } elseif ($type == 'student') {
  466. $sub_list = $DB->get_records(
  467. 'iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  468. } elseif ($type == 'exercise') {
  469. $sub_list = $DB->get_records(
  470. 'iassign_allsubmissions', array('iassign_statementid' => $item));
  471. } elseif ($type == 'block') {
  472. $exercises_in_block = $DB->get_records(
  473. 'iassign_statement', array('iassignid' => $iassign_id));
  474. foreach ($exercises_in_block as $exercise) {
  475. $temp = $DB->get_records(
  476. 'iassign_allsubmissions', array('iassign_statementid' => $exercise->id));
  477. $sub_list = array_merge($sub_list, $temp);
  478. }
  479. }
  480. $this->download_submissions_help($sub_list);
  481. }
  482. /// Delete submissions in table iassign_allsubmissions
  483. function delete_submissions () {
  484. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  485. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  486. exit;
  487. $type = optional_param('type', NULL, PARAM_TEXT);
  488. $item = optional_param('item', NULL, PARAM_TEXT);
  489. $exercise = optional_param('exercise', NULL, PARAM_TEXT);
  490. if ($type == 'individual') {
  491. $DB->delete_records('iassign_allsubmissions', array('id' => $item));
  492. } elseif ($type == 'student') {
  493. $DB->delete_records('iassign_allsubmissions', array('userid' => $item, 'iassign_statementid' => $exercise));
  494. } elseif ($type == 'exercise') {
  495. $DB->delete_records('iassign_allsubmissions', array('iassign_statementid' => $item));
  496. }
  497. }
  498. function get_individual_submission () {
  499. global $DB, $USER;
  500. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  501. exit;
  502. $submissionid = optional_param('submissionid', NULL, PARAM_TEXT);
  503. $submission = $DB->get_record("iassign_allsubmissions", array("id" => $submissionid));
  504. print $submission->answer;
  505. }
  506. /// Open individual submission
  507. function open_individual_submission () {
  508. global $DB, $USER, $CFG;
  509. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  510. exit;
  511. $submissionid = optional_param('item', NULL, PARAM_TEXT);
  512. $id = $this->cm->id;
  513. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  514. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=get_individual_submission&" . $param_aux . "&submissionid=" . $submissionid;
  515. $atual_submission = $DB->get_record('iassign_allsubmissions', array('id' => $submissionid));
  516. //print_r($atual_submission);
  517. $all_submissions = $DB->get_records('iassign_allsubmissions',
  518. array('iassign_statementid' => $atual_submission->iassign_statementid,
  519. 'userid' => $atual_submission->userid));
  520. $previous = null;
  521. $next = null;
  522. $i = 0;
  523. $found = false;
  524. foreach($all_submissions as $individual) {
  525. if (!$found && $individual->id != $submissionid) {
  526. $previous = $individual;
  527. }
  528. if ($found) {
  529. $next = $individual;
  530. break;
  531. }
  532. if ($individual->id === $submissionid) {
  533. $found = true;
  534. }
  535. $i ++;
  536. }
  537. print '<center style="padding-top: 2rem;">';
  538. if ($previous) {
  539. $url_prev = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $previous->id;
  540. print '<a href="'.$url_prev.'" style="color: blue; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  541. } else {
  542. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;"><span>&#9664;</span> '.get_string('all_submissions_manager_previous', 'iassign').'</a> ';
  543. }
  544. print ' (' . $i . '/' . count($all_submissions) . ')';
  545. if ($next) {
  546. $url_next = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=open_individual_submission&" . $param_aux . "&item=" . $next->id;
  547. print '<a href="'.$url_next.'" style="color: blue; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  548. } else {
  549. print '<a href="#" style="color: gray; text-decoration: none;margin: 1rem;">'.get_string('all_submissions_manager_next', 'iassign').' <span>&#9654;</span></a>';
  550. }
  551. print ilm_settings::build_ilm_tags(1, ['type' => "view", 'Proposition' => $url]);
  552. print '</center>';
  553. }
  554. /// Manage all submissions in exercises to table iassign_allsubmissions
  555. function all_submissions () {
  556. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  557. if (!has_capability('mod/iassign:runautoevaluate', $this->context, $USER->id))
  558. exit;
  559. print $OUTPUT->header();
  560. $id = $this->cm->id;
  561. $param_aux = "id=" . $id . "&userid_iassign=" . $USER->id;
  562. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  563. print '
  564. <div class="modal" id="modalConfirm" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  565. <div class="modal-dialog modal-dialog-centered" role="document">
  566. <div class="modal-content">
  567. <div class="modal-header">
  568. <h5 class="modal-title" id="exampleModalLongTitle">'.get_string('delete', 'iassign').'</h5>
  569. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  570. <span aria-hidden="true">&times;</span>
  571. </button>
  572. </div>
  573. <div class="modal-body">'
  574. . get_string('all_submissions_manager_confirm', 'iassign')
  575. . '</div>
  576. <div class="modal-footer">
  577. <button type="button" onclick="confirm_delete()" class="btn btn-primary">'.get_string('confirm', 'iassign').'</button>
  578. <button type="button" class="btn btn-secondary" data-dismiss="modal">'.get_string('cancel', 'iassign').'</button>
  579. </div>
  580. </div>
  581. </div>
  582. </div>';
  583. print '
  584. <script>
  585. var sub_type;
  586. var sub_item;
  587. var sub_el;
  588. var sub_exercise;
  589. function delete_submission (type, item, el, exercise = 0) {
  590. sub_type = type;
  591. sub_item = item;
  592. sub_exercise = exercise;
  593. sub_el = el.closest("tr");
  594. if (!sub_el) sub_el = el.closest("a");
  595. $("#modalConfirm").modal();
  596. }
  597. function confirm_delete () {
  598. var url = "'.$enderecoPOST.'&action=delete_submissions";
  599. var xhttp = new XMLHttpRequest();
  600. xhttp.open("GET", url + "&type=" + sub_type + "&item=" + sub_item + "&exercise=" + sub_exercise, true);
  601. xhttp.send();
  602. $("#modalConfirm").modal("hide");
  603. if ($(sub_el).attr("href"))
  604. $($(sub_el).attr("href")).remove();
  605. if (sub_el) sub_el.remove();
  606. }
  607. function download_submission(type, item, exercise = 0, iassign = 0) {
  608. var url = "'.$enderecoPOST.'&action=download_submissions";
  609. url += "&type=" + type + "&item=" + item + "&exercise=" + exercise + "&iassign=" + iassign;
  610. document.location = url;
  611. }
  612. function open_submission(item) {
  613. var url = "'.$enderecoPOST.'&action=open_individual_submission&item=" + item;
  614. var poupup = window.open(
  615. url,
  616. "popup",
  617. "width=900,height=900");
  618. }
  619. </script>';
  620. // Get list of exercises in the instance:
  621. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  622. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  623. print '<h2 class="m-b-2">' . get_string('all_submissions_manager', 'iassign') . '';
  624. print '<i onclick="download_submission(\'block\', 0, 0, '.$iassignid.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.5rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> </h2>';
  625. // Get list of enrolled students:
  626. $params = array('shortname' => 'student');
  627. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  628. $context = context_course::instance($this->course->id);
  629. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  630. $students_list = $DB->get_records_sql(
  631. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " . " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " . " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  632. print '<div class="list-group list-group-root">';
  633. foreach ($exercises_list as $exercise) {
  634. $submissions_list = $DB->get_records("iassign_allsubmissions", array("iassign_statementid" => $exercise->id));
  635. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  636. print '
  637. <a href="#item-'.$exercise->id.'" class="list-group-item list-group-item-action h4" style="margin-top: 1rem;" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\' > <i class="fa fa-caret-right"></i> '
  638. . $exercise->name
  639. . ' - ' . $iassign_ilm->name
  640. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'exercise\', '
  641. . $exercise->id .', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  642. . '<i onclick="event.stopPropagation(); download_submission(\'exercise\', '
  643. . $exercise->id .')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-left: 1rem; margin-top: .2rem;" aria-hidden="true"></i> '
  644. . '<span class="badge badge-primary badge-pill" style="float: right;">' . count($submissions_list) . '</span>'
  645. . '</a>';
  646. print '<div class="list-group collapse" style="padding: 0 1.5rem;" id="item-'.$exercise->id.'">';
  647. foreach ($students_list as $student) {
  648. $total = 0;
  649. $student_submissions = [];
  650. foreach ($submissions_list as $submission) {
  651. if ($submission->userid == $student->userid) {
  652. $student_submissions[] = $submission;
  653. $total ++;
  654. }
  655. }
  656. print '<a href="#item-'.$exercise->id.'-'.$student->userid.'" class="list-group-item list-group-item-action" data-toggle="collapse" onclick=\'$(".fa-caret-right, .fa-caret-down", this).toggleClass("fa-caret-right").toggleClass("fa-caret-down");\'>
  657. <i class="fa fa-caret-right"></i> ' . $student->firstname . ' ' . $student->lastname
  658. . '<i class="fa fa-times" onclick="event.stopPropagation(); delete_submission(\'student\', '
  659. . $student->userid .', this, '.$exercise->id.')" style="color:#C62828; cursor: pointer; font-size: 1.5rem; float: right; margin-left: .5rem;" aria-hidden="true"></i>'
  660. . '<i onclick="event.stopPropagation(); download_submission(\'student\', '.$student->userid.', '.$exercise->id.')" class="fa fa-download" style="float: right; color: #1fa67a; font-size: 1.3rem; cursor: pointer; margin-left: 1rem; margin-top: .1rem;" aria-hidden="true"></i> '
  661. . '<span class="badge badge-primary badge-pill" style="float: right;">' . $total . '</span>'
  662. . ' </a>';
  663. print '<div class="list-group collapse" style="padding-left: 5rem;padding-right: 5rem;" id="item-'.$exercise->id.'-'.$student->userid.'">';
  664. print '<table class="table table-striped table-hover"><thead>
  665. <tr>
  666. <th scope="col">#</th>
  667. <th scope="col">'.get_string('all_submissions_manager_date', 'iassign').'</th>
  668. <th scope="col">'.get_string('grade_student', 'iassign').'</th>
  669. <th scope="col">'.get_string('config_param_actions', 'iassign').'</th>
  670. </tr>
  671. </thead><tbody>';
  672. $i = 1;
  673. foreach ($student_submissions as $individual) {
  674. $date = new DateTime();
  675. $date->setTimestamp($individual->timecreated);
  676. print '<tr>';
  677. print '<td>'.$i++.'</td>';
  678. print '<td>'.date_format($date, 'd/m/Y H:i:s').'</td>';
  679. print '<td>'.$individual->grade.'</td>';
  680. print '<td>
  681. <i onclick="open_submission('.$individual->id.')" class="fa fa-external-link" style="color:#1177d1; cursor: pointer; font-size: 1.2rem; margin-right: .5rem;" aria-hidden="true"></i>
  682. <i onclick="download_submission(\'individual\', '.$individual->id.')" class="fa fa-download" style="color: #1fa67a; font-size: 1.2rem; cursor: pointer; margin-right: .5rem;" aria-hidden="true"></i>
  683. <i class="fa fa-times" onclick="delete_submission(\'individual\', '.$individual->id.', this)" style="color:#C62828; cursor: pointer; font-size: 1.5rem; " aria-hidden="true"></i></td>';
  684. print '</tr>';
  685. }
  686. print '</tbody></table>';
  687. //print '<a href="#" class="list-group-item list-group-item-action">Item 1.1.1</a>';
  688. print '</div>';
  689. }
  690. print '</div>';
  691. }
  692. print '</div>';
  693. print $OUTPUT->footer();
  694. }
  695. /// This method runs activities auto evaluation in teacher area
  696. function auto_evaluate () {
  697. global $COURSE, $CFG, $USER, $DB, $OUTPUT, $PAGE;
  698. if (!has_capability('mod/iassign:runautoevaluate', $USER->context, $USER->id))
  699. exit;
  700. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  701. $PAGE->navbar->add(get_string('auto_evaluate_title', 'iassign'), $actual_link);
  702. // Get list of exercises in the instance:
  703. $iassignid = optional_param('iassignid', NULL, PARAM_TEXT);
  704. $exercises_list = $DB->get_records("iassign_statement", array("iassignid" => $iassignid));
  705. // Get list of enrolled students:
  706. $params = array('shortname' => 'student');
  707. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  708. $context = context_course::instance($this->course->id);
  709. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  710. $students_list = $DB->get_records_sql(
  711. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  712. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  713. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  714. print $OUTPUT->header();
  715. print '<div><div>' . get_string('auto_evaluate_select', 'iassign') . '</div>';
  716. print '<ul style="list-style-type: none; margin: 1em;">';
  717. foreach ($exercises_list as $exercise) {
  718. $matches = [];
  719. preg_match('/[0-9]*\.?[0-9]*/', $exercise->name, $matches, PREG_OFFSET_CAPTURE);
  720. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  721. if ($iassign_ilm && $iassign_ilm->reevaluate == 1) {
  722. if ($matches[0][0]) {
  723. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="'.$matches[0][0].'" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">' . $exercise->name . '</label></li>';
  724. } else {
  725. print '<li id="li-item-'.$exercise->id.'"><input data-iditem="('.$exercise->id.')" data-exercise="'.$exercise->id.'" class="form-check-input" type="checkbox" id="ex_'.$exercise->id.'"><label id="label_ex_'.$exercise->id.'" for="ex_'.$exercise->id.'">(' . $exercise->id . ') - ' . $exercise->name . '</label></li>';
  726. }
  727. } else {
  728. if ($matches[0][0]) {
  729. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>' . $exercise->name . '</li>';
  730. } else {
  731. print '<li id="li-item-'.$exercise->id.'"> <i onmouseenter="$(\'#li-item-'.$exercise->id.'\').find(\'i\').tooltip(\'show\');" class="fa fa-times without-reevaluator" style="font-size: 1.1em;color: red;margin-bottom: .7em;margin-left: -1.3em;margin-right: .58em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_missing', 'iassign').'"></i>(' . $exercise->id . ') - ' . $exercise->name . '</li>';
  732. }
  733. }
  734. }
  735. print '</ul>
  736. <center>
  737. <button class="btn btn-primary" onclick="start_evaluation()" id="button_start">'.get_string('auto_evaluate_start', 'iassign').'</button>
  738. <button class="btn btn-danger" disabled="disabled" onclick="stop_evaluation()" id="button_stop">'.get_string('auto_evaluate_stop', 'iassign').'</button>
  739. <div id="evaluate_message" style="color: red"></div>
  740. <div id="evaluate_alerts"></div>
  741. <div>
  742. <div id="progress_bar" class="progress" style="width: 40em; height: 30px; margin-top: 1em; display: none; text-align: left;">
  743. <div class="progress-bar progress-bar-striped progress-bar-animated" role="progressbar" style="width: 1%; height: 100%;" aria-valuenow="0" aria-valuemin="1" aria-valuemax="100">1%</div>
  744. </div>
  745. </center>'; // close "
  746. print ' </div>' + "\n";
  747. print ' <script>';
  748. print '// #submissions = ' . count($exercises_list) . "\n"; //Debug
  749. print ' var submissions = [';
  750. // Get list of student id have submit for each exercise:
  751. foreach ($exercises_list as $exercise) {
  752. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  753. print '
  754. {
  755. "exerciseid": "' . $exercise->id . '",
  756. "grade": ' . $exercise->grade . ',
  757. "ilm": "' . $CFG->wwwroot . '/mod/iassign/' . $iassign_ilm->file_jar . $iassign_ilm->file_class . '",
  758. "submited": ['; // "
  759. $params = array('iassign_statementid' => $exercise->id);
  760. $submited = $DB->get_records_sql( // Get userid and his grade
  761. "SELECT s.userid, s.grade FROM {iassign_submission} s " .
  762. " WHERE s.iassign_statementid = :iassign_statementid", $params);
  763. foreach ($submited as $ss) {
  764. print($ss->userid . ',');
  765. }
  766. print '],';
  767. print '"allgrades": [';
  768. foreach ($submited as $ss) {
  769. print( $ss->grade . ',');
  770. }
  771. print ']
  772. },'; // close "
  773. } // foreach ($exercises_list as $exercise)
  774. print " ];\n";
  775. print '
  776. var total_submissions = 0;
  777. var selected_exercises;
  778. var count_steps;
  779. var value_by_step;
  780. var stoped = false;
  781. var time_interval = 5000;
  782. var var_interval;
  783. function add_hover_th (id_th, id_li) {
  784. $("#" + id_th).hover(function() {
  785. $("#" + id_li).css("background-color", "#d9d8d8");
  786. $(this).css("background-color", "#d9d8d8");
  787. }, function() {
  788. $("#" + id_li).css("background-color", "");
  789. $(this).css("background-color", "");
  790. });
  791. }
  792. function start_evaluation () {
  793. stoped = false;
  794. $("#progress_bar").css("display", "none");
  795. $("#evaluate_message").text("");
  796. $("#evaluate_alerts").text("");
  797. $(".added-col").remove();
  798. $(".progress-bar").addClass("progress-bar-animated progress-bar-striped").text("0%").css("width", "1%");
  799. selected_exercises = [];
  800. var c = 0;
  801. for (var i = 0; i < exercises.length; i++) {
  802. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  803. selected_exercises[c++] = exercises[i];
  804. }
  805. }
  806. if (selected_exercises.length == 0) {
  807. $("#evaluate_message").text("'.get_string('auto_evaluate_select_msg', 'iassign').'");
  808. return;
  809. } else {
  810. $("input:checkbox").attr("disabled", true);
  811. for (var i = 0; i < selected_exercises.length; i++) {
  812. var desc = $("#ex_" + selected_exercises[i]).data("iditem");
  813. $("#cols-exercises").append( $("<th />", { class : "added-col text-center", text : desc, id : "th-item-"+selected_exercises[i] }));
  814. $("#table-results tbody tr").each(function(e) {
  815. var id_t = "std_" + $(this).data("student") + "_ex_" + selected_exercises[i];
  816. $(this).append( $("<td />", {class : "added-col text-center", id : id_t, text : "", data : {"student": $(this).data("student"), "exercise": selected_exercises[i]} }));
  817. });
  818. add_hover_th("th-item-"+selected_exercises[i], "li-item-"+selected_exercises[i]);
  819. }
  820. $("#button_start").prop("disabled", true);
  821. $("#button_stop").prop("disabled", false);
  822. $("#progress_bar").css("display", "block");
  823. }
  824. total_submissions = selected_exercises.length * students.length;
  825. count_steps = 0;
  826. value_by_step = 100/total_submissions;
  827. actual_exercise = 0;
  828. actual_student = 0;
  829. actual_submission = 0;
  830. get_original_propositions();
  831. var_interval = setInterval(verifyBreak, time_interval);
  832. } // function start_evaluation()
  833. var actual_exercise;
  834. var actual_student;
  835. var actual_submission;
  836. var actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM
  837. function run_individual_evaluation () {
  838. if (stoped) return;
  839. // Verify if student really sent his answer
  840. var found = false;
  841. for (var j = 0; j < submissions.length; j++) {
  842. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  843. for (var k = 0; k < submissions[j].submited.length; k++) {
  844. if (students[actual_student] == submissions[j].submited[k]) {
  845. found = true;
  846. break;
  847. }
  848. }
  849. break;
  850. }
  851. }
  852. if (found == false) {
  853. postResultAutoEval();
  854. } else {
  855. // If it was sent, search it...
  856. var final_url = "";
  857. var student_answer = "' . $CFG->wwwroot . "/mod/iassign/view.php?action=get_student_submission&id=" . $this->cm->id . '" + "&iassign_student=" + students[actual_student] + "&iassign_exercise=" + selected_exercises[actual_exercise];
  858. for (var j = 0; j < submissions.length; j++) {
  859. if (submissions[j].exerciseid == selected_exercises[actual_exercise]) {
  860. final_url = submissions[j].ilm;
  861. break;
  862. }
  863. }
  864. final_url += "?iLM_PARAM_AssignmentURL=true&iLM_PARAM_Assignment=" + encodeURIComponent(student_answer) + "&iLM_PARAM_TeacherAutoEval=true";
  865. actual_answer_url = student_answer; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  866. window.frames["ifrm"].location=final_url;
  867. }
  868. } // function run_individual_evaluation()
  869. var break_student = -1;
  870. var break_exercise = -1;
  871. function verifyBreak () {
  872. if (actual_student == break_student && actual_exercise == break_exercise) {
  873. postResultAutoEval(-6);
  874. break_student = -1;
  875. break_exercise = -1;
  876. return;
  877. } else {
  878. break_student = actual_student;
  879. break_exercise = actual_exercise;
  880. }
  881. }
  882. // This function is called by the iLM to get the student s answer (to compare with re-evaluation)
  883. function getStudentAnswerURL () {
  884. return actual_answer_url; // to provide the current student answer (to "iassing_integration_functios.js" of iLM)
  885. }
  886. // This function is called by the iLM!!!
  887. function getAutoEvalOriginalData () {
  888. return original_propositions[actual_exercise];
  889. }
  890. function updateProgressBar () {
  891. if (stoped) return;
  892. var temp = (count_steps * value_by_step)|0;
  893. count_steps ++;
  894. temp = temp > 100 ? 100 : temp;
  895. $(".progress-bar").css("width", temp + "%").text(temp + "%");
  896. if (temp >= 100) {
  897. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  898. $("#button_start").prop("disabled", false);
  899. $("#button_stop").prop("disabled", true);
  900. $("input:checkbox").attr("disabled", false);
  901. clearInterval(var_interval);
  902. }
  903. }
  904. // Process the re-evaluated "grade" - DEVELOPER: here, do NOT use apostrophe!
  905. // The iLM method "getiLMContent()" must, after re-evaluate getting "new_grade", call this with "postResultAutoEval(new_grade)"
  906. function postResultAutoEval (grade = null) {
  907. var id_t = "std_" + students[actual_student] + "_ex_" + selected_exercises[actual_exercise];
  908. if (grade == null) {
  909. $("#"+id_t).html(\'<i class="fa fa-circle-o text-muted" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('not_post', 'iassign').'"></i>\');
  910. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  911. } else {
  912. // Verify if the re-evaluation grade is the of that one registered:
  913. var actual_value = 0;
  914. var actual_student_grade = 0;
  915. for (var k = 0; k < submissions.length; k++) {
  916. if (submissions[k].exerciseid == selected_exercises[actual_exercise]) {
  917. actual_value = submissions[k].grade;
  918. for (var h = 0; h < submissions[k].submited.length; h++) {
  919. if (submissions[k].submited[h] == students[actual_student]) {
  920. actual_student_grade = submissions[k].allgrades[h];
  921. break;
  922. }
  923. }
  924. break;
  925. }
  926. }
  927. // @FeedbackConvention
  928. if (grade < 0) {
  929. switch (grade) {
  930. case -1:
  931. // Test-cases are empty:
  932. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_empty_cases', 'iassign').'"></i></i>\');
  933. var mm = actual_exercise;
  934. $("#"+id_t).find(".details-button").click(function(e) {
  935. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_empty_cases', 'iassign').'</td></tr></table>\');
  936. });
  937. break;
  938. case -2:
  939. // Test-cases were manually altered by the student (fraud!):
  940. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_diff_cases', 'iassign').'"></i></i>\');
  941. var mm = actual_exercise;
  942. $("#"+id_t).find(".details-button").click(function(e) {
  943. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+"</td></tr><tr><td style=\'width: 30%;\' colspan=\'2\'><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_diff_cases', 'iassign').'</td></tr></table>");
  944. });
  945. $.ajax({
  946. dataType: "html",
  947. url: "'.$CFG->wwwroot.'/mod/iassign/view.php?action=post_auto_eval_result&id='.$this->cm->id.'&iassign_exercise="+selected_exercises[actual_exercise]+"&student="+students[actual_student]+"&grade=0",
  948. success: function(d) {}
  949. });
  950. break;
  951. case -5:
  952. // Execution failed:
  953. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-times-circle-o fa-6" aria-hidden="true" style="color: #ef5151; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_msg_t_fail', 'iassign').'"></i></i>\');
  954. var mm = actual_exercise;
  955. $("#"+id_t).find(".details-button").click(function(e) {
  956. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;" colspan="2"><b>'.get_string('auto_result', 'iassign').'</b><br>'.get_string('auto_evaluate_msg_fail', 'iassign').'</td></tr></table>\');
  957. });
  958. break;
  959. case -6: // iLM not answering was detected in "verifyBreak()"
  960. // The iLM are not answering:
  961. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-clock-o fa-6" aria-hidden="true" style="color: orange; font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_title_time', 'iassign').'"></i></i>\');
  962. $("#"+id_t).find(".details-button").click(function(e) {
  963. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">' . get_string('auto_evaluate_msg_time', 'iassign') . '</td></tr></table>\');
  964. });
  965. break;
  966. }
  967. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  968. } else {
  969. console.log((grade), (actual_student_grade));
  970. if ((grade) == (actual_student_grade)) {
  971. $("#"+id_t).html(\'<i class="fa fa-check-circle-o text-success" aria-hidden="true" style="font-size: 2em;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_ok', 'iassign').'"></i>\');
  972. } else { // Notas diferem:
  973. $("#"+id_t).html(\'<i data-toggle="modal" class="details-button" data-target="#exampleModalCenter"><i class="fa fa-exclamation-circle text-warning" aria-hidden="true" style="font-size: 2em; cursor: pointer;" data-toggle="tooltip" data-original-title="'.get_string('auto_evaluate_different_grades', 'iassign').'"></i></i>\');
  974. var mm = actual_exercise;
  975. $("#"+id_t).find(".details-button").click(function(e) {
  976. $(".modal-body").html(\'<table class="table"><tr><td style="width: 30%;">'.get_string('exercise', 'iassign').':</td><td>\'+$("#label_ex_"+selected_exercises[mm]).text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('student', 'iassign').'</td><td>\'+$(this).closest("tr").find(".student-name").text()+\'</td></tr><tr><td style="width: 30%;">'.get_string('auto_evaluate_grade_registered', 'iassign').'</td><td>\'+(actual_student_grade*grade)+\'</td></tr><tr><td style="width: 30%;"><b>'.get_string('auto_evaluate_grade_new', 'iassign').'</b></td><td>\'+(grade * actual_value)+\'</td></tr><tr><td colspan="2">'.get_string('auto_evaluate_msg_grade_update', 'iassign').'</tr></table>\');
  977. });
  978. // Send to the endpoint the post_auto_eval_result to verify:
  979. $.ajax({
  980. dataType: "html",
  981. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=post_auto_eval_result&id=' . $this->cm->id . '&iassign_exercise=" + selected_exercises[actual_exercise] + "&student=" + students[actual_student] + "&grade=" + (grade),
  982. success: function(d) {}
  983. });
  984. }
  985. $("#"+id_t).find(\'[data-toggle="tooltip"]\').tooltip();
  986. }
  987. }
  988. updateProgressBar();
  989. // Does it must continue in the same exercise or stop?
  990. if (actual_student < students.length) {
  991. actual_student ++;
  992. run_individual_evaluation();
  993. } else {
  994. actual_student = 0;
  995. // Does it go to next exercise or is it finished?
  996. if (actual_exercise < selected_exercises.length) {
  997. actual_exercise++;
  998. run_individual_evaluation();
  999. } else {
  1000. $("#evaluate_alerts").text("' . get_string('auto_evaluate_finished', 'iassign') . '");
  1001. }
  1002. }
  1003. }
  1004. var original_propositions;
  1005. function get_original_propositions () {
  1006. original_propositions = [];
  1007. var count = 0;
  1008. for (var i = 0; i < exercises.length; i++) {
  1009. if ($("#ex_"+exercises[i]).is(":checked") == true) {
  1010. $.ajax({
  1011. dataType: "html",
  1012. url: "' . $CFG->wwwroot . '/mod/iassign/view.php?action=get_teacher_exercise&id=' . $this->cm->id . '&iassign_exercise="+exercises[i],
  1013. success: function(d) { // variable "d" has the iLM content
  1014. original_propositions[count] = d; // exercise original content
  1015. count ++;
  1016. if (count == selected_exercises.length) {
  1017. run_individual_evaluation();
  1018. }
  1019. }
  1020. });
  1021. }
  1022. }
  1023. }
  1024. function stop_evaluation () {
  1025. stoped = true;
  1026. $("#button_start").prop("disabled", false);
  1027. $("#button_stop").prop("disabled", true);
  1028. $(".progress-bar").removeClass("progress-bar-animated progress-bar-striped");
  1029. $("input:checkbox").attr("disabled", false);
  1030. $("#evaluate_alerts").text("'.get_string('auto_evaluate_stopped', 'iassign').'");
  1031. clearInterval(var_interval);
  1032. }
  1033. var exercises = [ '; // '
  1034. foreach ($exercises_list as $exercise) {
  1035. print $exercise->id . ',';
  1036. }
  1037. print ' ];';
  1038. print ' var students = [ ';
  1039. foreach ($students_list as $student) {
  1040. print $student->userid . ',';
  1041. }
  1042. print '];';
  1043. print ' var ilms = [';
  1044. foreach ($exercises_list as $exercise) {
  1045. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $exercise->iassign_ilmid));
  1046. print "'" . $CFG->wwwroot . "/mod/iassign/" . $iassign_ilm->file_jar . "/" . $iassign_ilm->file_class . "',";
  1047. }
  1048. print ']';
  1049. print '</script>';
  1050. print '
  1051. <div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  1052. <div class="modal-dialog modal-dialog-centered" role="document">
  1053. <div class="modal-content">
  1054. <div class="modal-header">
  1055. <h5 class="modal-title" id="exampleModalLongTitle">' . get_string('auto_evaluate_details', 'iassign') . '</h5>
  1056. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  1057. <span aria-hidden="true">&times;</span>
  1058. </button>
  1059. </div>
  1060. <div class="modal-body">
  1061. ...
  1062. </div>
  1063. <div class="modal-footer">
  1064. <button type="button" class="btn btn-secondary" data-dismiss="modal">' . get_string('close', 'iassign') . '</button>
  1065. </div>
  1066. </div>
  1067. </div>
  1068. </div>'; //
  1069. print '<iframe name="ifrm" style="position: absolute; top: -1000px;"></iframe>';
  1070. print '<table id="table-results" class="table table-hover m-t-1">
  1071. <thead>
  1072. <tr id="cols-exercises">
  1073. <th scope="col" style="width: 30rem;">'.get_string('students', 'iassign').'</th>
  1074. </tr>
  1075. </thead>
  1076. <tbody>'; // "
  1077. foreach ($students_list as $student) {
  1078. $user = $DB->get_record('user', array('id' => $student->userid));
  1079. $avatar = new user_picture($user);
  1080. $avatar->courseid = $COURSE->id;
  1081. $avatar->link = true;
  1082. print
  1083. '<tr data-student="'.$student->userid.'">
  1084. <td>' . $OUTPUT->render($avatar) . ' <span class="student-name">' . $user->firstname . ' ' . $user->lastname . '</span></td>
  1085. </tr>'; // "
  1086. }
  1087. print '</tbody>
  1088. </table>'; // "
  1089. print $OUTPUT->footer();
  1090. } // function auto_evaluate()
  1091. /// This method moves an iAssign activity
  1092. function move_activity () {
  1093. global $USER, $CFG, $DB, $COURSE;
  1094. $iassign_id = optional_param('iassign_current', NULL, PARAM_TEXT);
  1095. $iassign_destiny = optional_param('iassign_destiny', NULL, PARAM_TEXT);
  1096. $update_entry_new_iassign = new stdClass();
  1097. $update_entry_new_iassign->id = $iassign_id;
  1098. $update_entry_new_iassign->iassignid = $iassign_destiny;
  1099. // Update the iassign_statement
  1100. $DB->update_record("iassign_statement", $update_entry_new_iassign);
  1101. // Update file context
  1102. $c_i = context_module::instance($this->cm->id);
  1103. $ret = get_coursemodule_from_id("iassign", $c_i->instanceid);
  1104. $course_module_info = $DB->get_record("course_modules", array("course" => $COURSE->id, "module" => $ret->module, "instance" => $iassign_destiny));
  1105. $path_module = context_course::instance($COURSE->id);
  1106. $context_file = $DB->get_record_sql('SELECT * FROM {context} WHERE instanceid="' . $course_module_info->id . '" AND path like "'.$path_module->path.'%"');
  1107. if ($context_file) {
  1108. $id_context = $context_file->id;
  1109. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_id));
  1110. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1111. $files = $fs->get_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  1112. foreach ($files as $value) {
  1113. if ($value->get_filename() != ".") {
  1114. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1115. $newfile = $fs->create_file_from_storedfile(array('contextid' => $id_context, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => $iassign_id), $value);
  1116. $updateentry = new stdClass();
  1117. $updateentry->id = $iassign_id;
  1118. $updateentry->file = $newfile->get_itemid();
  1119. $DB->update_record("iassign_statement", $updateentry);
  1120. $fs->delete_area_files(context_module::instance($this->cm->id)->id, 'mod_iassign', 'exercise', $value->get_itemid());
  1121. break;
  1122. }
  1123. }
  1124. }
  1125. $this->return_home_course('moved_activity');
  1126. exit;
  1127. }
  1128. /// This method duplicates an iAssign activity
  1129. function duplicate_activity () {
  1130. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1131. $id = $this->cm->id;
  1132. $iassignid = optional_param('iassign_current', NULL, PARAM_TEXT);
  1133. $context = context_module::instance($this->cm->id);
  1134. $contextuser = context_user::instance($USER->id);
  1135. // Get the the iAssign acitivity to be duplicated
  1136. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassignid));
  1137. // Remove the current id of activity
  1138. $iassign_statement->id=0;
  1139. // Get the information about current author, and add this information in author_modified field
  1140. $author = $DB->get_record("user", array('id' => $USER->id));
  1141. $iassign_statement->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1142. $iassign_statement->author_modified = $iassign_statement->author_modified_name;
  1143. // Store the activity in the table
  1144. if ($id_ = $DB->insert_record("iassign_statement", $iassign_statement)) {
  1145. // Duplicate activity file
  1146. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1147. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement->file);
  1148. foreach ($files as $value) {
  1149. if ($value->get_filename() != ".") {
  1150. $last_id = $DB->get_record_sql('SELECT itemid FROM {files} WHERE component="mod_iassign" ORDER BY itemid DESC LIMIT 1')->itemid;
  1151. $newfile = $fs->create_file_from_storedfile(array('contextid' => $context->id, 'component' => 'mod_iassign', 'filearea' => 'exercise', 'itemid' => ($last_id + 1)), $value);
  1152. $updateentry = new stdClass();
  1153. $updateentry->id = $id_;
  1154. $updateentry->file = $newfile->get_itemid();
  1155. // Update the duplicated iLM iAssign with new file id
  1156. $DB->update_record("iassign_statement", $updateentry);
  1157. }
  1158. }
  1159. }
  1160. // log event --------------------------------------------------------------------------------------
  1161. iassign_log::add_log('duplicate_iassign_exercise', 'name: ' . $author->firstname, $id_, $this->cm->id);
  1162. $this->return_home_course('duplicated_activity');
  1163. exit;
  1164. }
  1165. // / This method gets the content from comment and register it
  1166. function add_comment () {
  1167. global $USER, $DB;
  1168. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1169. $comment = false;
  1170. if ($submission_comment)
  1171. $comment = $this->write_comment_submission();
  1172. $id_submission = optional_param('iassign_submission_current', NULL, PARAM_TEXT);
  1173. if (!$id_submission) {
  1174. $iassign_submission =
  1175. $DB->get_record("iassign_submission",
  1176. array(
  1177. "iassign_statementid" => $this->activity->get_activity()->id,
  1178. "userid" => $USER->id
  1179. )
  1180. );
  1181. if ($iassign_submission) {
  1182. $id_submission = $iassign_submission->id;
  1183. }
  1184. }
  1185. echo $this->search_comment_submission($id_submission);
  1186. }
  1187. /// This method gets the content from the iLM and register it
  1188. // It could be the "exercise template" (teacher) or an answer (student)
  1189. function get_answer () {
  1190. global $USER, $CFG, $DB, $OUTPUT;
  1191. $id = $this->cm->id;
  1192. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  1193. $submission_ajax = optional_param('iLM_ajax', NULL, PARAM_TEXT);
  1194. if ($submission_ajax == 1) ob_start();
  1195. $comment = false;
  1196. if ($submission_comment)
  1197. $comment = $this->write_comment_submission();
  1198. // receives data of iLM using the current activity
  1199. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1200. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1201. // receives data of submission of current activity
  1202. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1203. // receives post and get
  1204. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1205. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1206. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1207. $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)
  1208. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1209. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1210. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1211. $msg = '';
  1212. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1213. $newentry = new stdClass();
  1214. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1215. $newentry->userid = $this->userid_iassign;
  1216. $newentry->timecreated = time();
  1217. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1218. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1219. $DB->insert_record("iassign_allsubmissions", $newentry);
  1220. }
  1221. // Feedback
  1222. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1223. $str_action = "view"; // repeat
  1224. if (strtolower($iassign_ilm->name) == "igeom") {
  1225. }
  1226. $title = get_string('evaluate_iassign', 'iassign');
  1227. print $OUTPUT->header();
  1228. print $OUTPUT->box_start();
  1229. // Action = { view ; repeat ; viewsubmission }
  1230. // * '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")
  1231. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1232. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1233. $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;
  1234. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1235. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1236. print '<table width=100% >';
  1237. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1238. //TODO alterar aqui???
  1239. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1240. // empty_answer_post = No solution was posted.
  1241. if ($comment)
  1242. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1243. else
  1244. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1245. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1246. } else {
  1247. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1248. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1249. // Correct answer!!
  1250. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1251. $this->write_solution = 1; //
  1252. $status = 3;
  1253. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1254. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1255. // log record
  1256. $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;
  1257. // Trigger module viewed event.
  1258. $event = \mod_iassign\event\submission_created::create(array(
  1259. 'objectid' => $this->iassign->id,
  1260. 'context' => $this->context,
  1261. 'other' => $info
  1262. ));
  1263. $event->add_record_snapshot('course', $this->course);
  1264. $event->trigger();
  1265. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1266. // Wrong answer...: get_answer_incorrect
  1267. $status = 2;
  1268. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1269. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1270. // log record
  1271. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1272. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1273. // Trigger module viewed event.
  1274. $event = \mod_iassign\event\submission_created::create(array(
  1275. 'objectid' => $this->iassign->id,
  1276. 'context' => $this->context,
  1277. 'other' => $info
  1278. ));
  1279. $event->add_record_snapshot('course', $this->course);
  1280. $event->trigger();
  1281. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1282. // Presents to the learner the result of the automatic evaluate?
  1283. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1284. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1285. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1286. print '<tr>';
  1287. // log record
  1288. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1289. // Trigger module viewed event.
  1290. $event = \mod_iassign\event\submission_created::create(array(
  1291. 'objectid' => $this->iassign->id,
  1292. 'context' => $this->context,
  1293. 'other' => $info
  1294. ));
  1295. $event->add_record_snapshot('course', $this->course);
  1296. $event->trigger();
  1297. } else { // yes!!!
  1298. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1299. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1300. print '<tr>';
  1301. print $msg;
  1302. }
  1303. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1304. $status = 1;
  1305. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1306. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1307. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1308. print '<tr>';
  1309. // log record
  1310. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1311. $event = \mod_iassign\event\submission_created::create(array(
  1312. 'objectid' => $this->iassign->id,
  1313. 'context' => $this->context,
  1314. 'other' => $info
  1315. ));
  1316. $event->add_record_snapshot('course', $this->course);
  1317. $event->trigger();
  1318. } // if ($iassign_ilm->evaluate == 1)
  1319. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1320. print '</tr></table>';
  1321. print $OUTPUT->box_end();
  1322. // add or update evaluate
  1323. if ($this->write_solution == 1) {
  1324. $timenow = time();
  1325. // new record
  1326. if (!$iassign_submission) {
  1327. $newentry = new stdClass();
  1328. $newentry->userid = $this->userid_iassign;
  1329. // $newentry->userid = $USER->id;
  1330. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1331. $newentry->timecreated = $timenow;
  1332. $newentry->timemodified = $timenow;
  1333. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1334. $newentry->grade = round($grade_student, 2);
  1335. $newentry->status = $status;
  1336. $newentry->experiment = 1;
  1337. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1338. print_error('error_insert', 'iassign');
  1339. } else {
  1340. // Trigger module viewed event.
  1341. $event = \mod_iassign\event\submission_created::create(array(
  1342. 'objectid' => $this->iassign->id,
  1343. 'context' => $this->context
  1344. ));
  1345. $event->add_record_snapshot('course', $this->course);
  1346. $event->trigger();
  1347. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1348. }
  1349. } elseif ($iassign_submission->status != 3) {
  1350. $newentry = new stdClass();
  1351. $newentry->id = $iassign_submission->id;
  1352. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1353. $newentry->userid = $iassign_submission->userid;
  1354. $newentry->timecreated = $iassign_submission->timecreated;
  1355. $newentry->timemodified = $timenow;
  1356. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1357. $newentry->grade = round($grade_student, 2);
  1358. $newentry->status = $status;
  1359. $newentry->experiment = $iassign_submission->experiment + 1;
  1360. if (!$DB->update_record("iassign_submission", $newentry)) {
  1361. print_error('error_update', 'iassign');
  1362. //D depurar...
  1363. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1364. //D $fp = fopen("teste1.txt","w");
  1365. //D fwrite($fp,$stringAux);
  1366. } else {
  1367. // Trigger module viewed event.
  1368. $event = \mod_iassign\event\submission_updated::create(array(
  1369. 'objectid' => $this->iassign->id,
  1370. 'context' => $this->context
  1371. ));
  1372. $event->add_record_snapshot('course', $this->course);
  1373. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1374. }
  1375. } else {
  1376. if ($return_get_answer == 1) {
  1377. $newentry = new stdClass();
  1378. $newentry->id = $iassign_submission->id;
  1379. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1380. $newentry->userid = $iassign_submission->userid;
  1381. $newentry->timecreated = $iassign_submission->timecreated;
  1382. $newentry->timemodified = $timenow;
  1383. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1384. $newentry->grade = round($grade_student, 2);
  1385. $newentry->status = $status;
  1386. $newentry->experiment = $iassign_submission->experiment + 1;
  1387. if (!$DB->update_record("iassign_submission", $newentry))
  1388. print_error('error_update', 'iassign');
  1389. else {
  1390. $event = \mod_iassign\event\submission_updated::create(array(
  1391. 'objectid' => $this->iassign->id,
  1392. 'context' => $this->context
  1393. ));
  1394. $event->add_record_snapshot('course', $this->course);
  1395. $event->trigger();
  1396. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1397. print $OUTPUT->box_start();
  1398. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1399. print $OUTPUT->box_end();
  1400. }
  1401. } elseif ($return_get_answer == 2) {
  1402. print $OUTPUT->box_start();
  1403. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1404. print $OUTPUT->box_end();
  1405. } else {
  1406. print $OUTPUT->box_start();
  1407. print "
  1408. <script type='text/javascript'>
  1409. //<![CDATA[
  1410. function overwrite () {
  1411. document.formEnvio.return_get_answer.value = 1;
  1412. document.formEnvio.submit();
  1413. }
  1414. function nooverwrite () {
  1415. document.formEnvio.return_get_answer.value = 2;
  1416. document.formEnvio.submit();
  1417. }
  1418. //]]>
  1419. </script>";
  1420. $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;
  1421. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1422. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1423. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1424. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1425. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1426. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1427. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1428. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1429. <input type='hidden' name='return_get_answer'/> ";
  1430. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1431. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1432. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1433. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1434. print " </form>";
  1435. print $OUTPUT->box_end();
  1436. }
  1437. }
  1438. } // if ($this->write_solution == 1)
  1439. print $OUTPUT->footer();
  1440. if ($submission_ajax == 1) {
  1441. ob_end_clean();
  1442. print 'OK';
  1443. }
  1444. die();
  1445. } // function get_answer()
  1446. /// Export in file the answer of student.
  1447. function export_file_answer () {
  1448. global $DB;
  1449. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1450. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1451. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1452. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1453. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1454. $extensions = explode(",", $iassign_ilm->extension);
  1455. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1456. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1457. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1458. header("Pragma: public");
  1459. header("Expires: 0");
  1460. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1461. header("Cache-Control: private", false);
  1462. header("Content-Type: document/unknown");
  1463. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1464. set_time_limit(0);
  1465. print($iassign_submission->answer);
  1466. exit;
  1467. } // function export_file_answer()
  1468. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1469. // @calledby $this->export_package_answer()
  1470. //TODO Precisa terminar! //TODO_HTML
  1471. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1472. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1473. <head>
  1474. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1475. $str_html .= " </head>
  1476. <body>\n";
  1477. $tam = sizeof($array_iassign_name);
  1478. for ($ii=0; $ii<$tam; $ii++) {
  1479. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1480. }
  1481. $str_html .= "
  1482. </body>\n</html>";
  1483. return $str_html;
  1484. }
  1485. /// Export an package (zip) with all answer of students
  1486. // @calledby $this->action()
  1487. function export_package_answer () {
  1488. global $DB, $CFG, $OUTPUT;
  1489. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1490. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1491. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1492. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1493. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1494. $userid = optional_param('userid', NULL, PARAM_INT);
  1495. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1496. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1497. //TODO_HTML echo "username=$username<br/>"; exit;
  1498. $current_date = date('Y_m_d_H');
  1499. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1500. // If temporary directory under Moodle data does not exists => create it
  1501. if (!is_dir($diretorio)) {
  1502. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1503. // created directory with permissions to be seen by everyone
  1504. }
  1505. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1506. if (!is_writable($diretorio)) { // send a highlighted message!
  1507. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1508. exit; // just in case
  1509. }
  1510. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1511. $zip = new zip_archive(); // create ZIP
  1512. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1513. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1514. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1515. $vet_student_filename = array();
  1516. $vet_student_content = array();
  1517. foreach ($iassign_statements as $iassign_statement) {
  1518. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1519. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1520. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1521. $extensions = explode(",", $iassign_ilm->extension);
  1522. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1523. if ($iassign_submission) {
  1524. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1525. $student_content = $iassign_submission->answer;
  1526. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1527. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1528. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1529. if ($resp) {
  1530. $vet_student_filename[] = $student_filename;
  1531. $vet_student_content[] = $student_content;
  1532. }
  1533. else { // send a highlighted message!
  1534. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1535. exit; // just in case
  1536. }
  1537. }
  1538. }
  1539. $zip->close(); // close the ZIP file
  1540. if (count($vet_student_filename)>0) {
  1541. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1542. $result_tf = $vet_result[0];
  1543. $filenameZip = $vet_result[1]->filename;
  1544. }
  1545. iassign_utils::download_file($zip_filename); // download the ZIP file
  1546. exit;
  1547. } // function export_package_answer()
  1548. /// Editing status of interactive activities
  1549. function edit_status () {
  1550. global $USER, $DB, $OUTPUT;
  1551. $newentry = new stdClass();
  1552. $newentry->id = $this->iassign_submission_current;
  1553. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1554. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1555. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1556. $newentry->status = $iassign_submission->status;
  1557. $newentry->teacher = $USER->id;
  1558. if (!$DB->update_record('iassign_submission', $newentry))
  1559. print_error('error_update', 'iassign');
  1560. else {
  1561. // Trigger module viewed event.
  1562. $event = \mod_iassign\event\submission_updated::create(array(
  1563. 'objectid' => $this->iassign->id,
  1564. 'context' => $this->context
  1565. ));
  1566. $event->add_record_snapshot('course', $this->course);
  1567. $event->trigger();
  1568. $this->action = 'viewsubmission';
  1569. $this->view_iassign_current();
  1570. } // if (!$DB->update_record('iassign_submission', $newentry))
  1571. } // function edit_status()
  1572. /// Editing grade of interactive activities
  1573. function edit_grade () {
  1574. global $USER, $DB, $OUTPUT;
  1575. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1576. if ($newgrade && $newgrade >= 0) {
  1577. $newentry = new stdClass();
  1578. $newentry->id = $this->iassign_submission_current;
  1579. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1580. $newentry->teacher = $USER->id;
  1581. if (!$DB->update_record('iassign_submission', $newentry))
  1582. print_error('error_update', 'iassign');
  1583. else {
  1584. // Trigger module viewed event.
  1585. $event = \mod_iassign\event\submission_updated::create(array(
  1586. 'objectid' => $this->iassign->id,
  1587. 'context' => $this->context
  1588. ));
  1589. $event->add_record_snapshot('course', $this->course);
  1590. $event->trigger();
  1591. }
  1592. } // if ($newgrade >= 0)
  1593. $this->action = 'viewsubmission';
  1594. $this->view_iassign_current();
  1595. }
  1596. /// Add or Edit interactive activities
  1597. // @calledby $this->action()
  1598. function add_edit_iassign () {
  1599. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1600. require_once('iassign_form.php');
  1601. $id = $this->cm->id;
  1602. $iassignid = $this->iassign->id;
  1603. $param = new stdClass();
  1604. $param->action = $this->action; // oculto
  1605. $param->id = $id; // oculto
  1606. $COURSE->cm = $id;
  1607. $COURSE->iassignid = $iassignid;
  1608. $COURSE->iassign_file_id = NULL;
  1609. $context = context_module::instance($this->cm->id);
  1610. $contextuser = context_user::instance($USER->id);
  1611. $component = 'mod_iassign';
  1612. $filearea = 'exercise';
  1613. if (!empty($this->iassign_current))
  1614. $COURSE->iassign_id = $this->iassign_current;
  1615. else
  1616. $COURSE->iassign_id = 0;
  1617. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1618. if ($this->action == 'add') {
  1619. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1620. $params = array('iassignid' => $iassignid);
  1621. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1622. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1623. $total_of_activities = count($iassign_statement);
  1624. $param->iassignid = $iassignid;
  1625. $param->name = "";
  1626. $param->oldname = "";
  1627. $param->type_iassign = 3;
  1628. $param->proposition = "";
  1629. $author = $DB->get_record("user", array("id" => $USER->id));
  1630. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1631. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1632. $param->author = $param->author_name;
  1633. $param->author_modified = $param->author_modified_name;
  1634. $COURSE->iassign_list = array();
  1635. $param->iassign_list = array();
  1636. if ($iassign_statement) {
  1637. foreach ($iassign_statement as $iassign) {
  1638. $iassignid = $iassign->id;
  1639. $param->iassign_list[$iassignid] = 0;
  1640. $COURSE->iassign_list[$iassignid] = new stdClass();
  1641. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1642. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1643. $COURSE->iassign_list[$iassignid]->enable = 1;
  1644. } // foreach ($iassign_statement as $iassign)
  1645. }
  1646. $param->iassign_ilmid = 0;
  1647. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1648. $param->file = 0;
  1649. $param->fileold = 0;
  1650. $param->filename = "";
  1651. $param->grade = $iassign_data->grade;
  1652. $param->timemodified = time();
  1653. $param->timecreated = time();
  1654. $param->timeavailable = $iassign_data->timeavailable;
  1655. $param->timedue = $iassign_data->timedue;
  1656. $param->preventlate = $iassign_data->preventlate;
  1657. $param->test = $iassign_data->test;
  1658. $param->special_param1 = 0;
  1659. $param->visible = 1;
  1660. $param->max_experiment = $iassign_data->max_experiment;
  1661. $param->dependency = 0;
  1662. $param->automatic_evaluate = 1;
  1663. $param->show_answer = 1;
  1664. } // if ($this->action == 'add')
  1665. elseif ($this->action == 'edit') {
  1666. $COURSE->iassign_list = array();
  1667. $this_activity = $this->activity->get_activity();
  1668. if ($this_activity != null) {
  1669. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1670. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1671. $param->iassign_id = $iassign_statement_current->id; // oculto
  1672. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1673. $param->name = $iassign_statement_current->name;
  1674. $param->oldname = $iassign_statement_current->name;
  1675. $param->type_iassign = $iassign_statement_current->type_iassign;
  1676. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1677. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1678. //2019 $param->proposition = $iassign_statement_current->proposition;
  1679. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1680. $param->author_name = $iassign_statement_current->author_name; // oculto
  1681. $param->author = $iassign_statement_current->author_name;
  1682. $author = $DB->get_record("user", array('id' => $USER->id));
  1683. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1684. $param->author_modified = $param->author_modified_name;
  1685. $dependency = explode(';', $iassign_statement_current->dependency);
  1686. $param->iassign_list = array();
  1687. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1688. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1689. $array_dependency = array();
  1690. $subdependency = "";
  1691. $sub_subdependency = "";
  1692. // dependent on this exercise
  1693. if ($iassign_statement_dependency) {
  1694. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1695. // to whom this exercise depends
  1696. foreach ($inter as $tmp)
  1697. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1698. $list_dependency = $subdependency . $sub_subdependency;
  1699. $array_dependency = explode(";", $list_dependency);
  1700. }
  1701. // Get all activity with the same iLM - iassignid
  1702. $str_query = "SELECT id, name FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' ORDER BY s.position ASC";
  1703. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1704. $total_of_activities = count($all_others_iassign_statement) + 1;
  1705. $inter = array();
  1706. if ($all_others_iassign_statement) {
  1707. foreach ($all_others_iassign_statement as $iassign)
  1708. if (in_array($iassign->id, $dependency))
  1709. $inter[] = $iassign->id;
  1710. }
  1711. if ($all_others_iassign_statement) {
  1712. foreach ($all_others_iassign_statement as $iassign) {
  1713. $iassignid = $iassign->id;
  1714. $COURSE->iassign_list[$iassignid] = new stdClass();
  1715. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1716. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1717. if (in_array($iassignid, $dependency))
  1718. $param->iassign_list[$iassignid] = 1;
  1719. else
  1720. $param->iassign_list[$iassignid] = 0;
  1721. if (in_array($iassignid, $array_dependency))
  1722. $COURSE->iassign_list[$iassignid]->enable = 0;
  1723. else
  1724. $COURSE->iassign_list[$iassignid]->enable = 1;
  1725. } // foreach ($all_others_iassign_statement as $iassign)
  1726. }
  1727. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1728. $param->fileold = 0;
  1729. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1730. $param->filename = '';
  1731. $param->grade = $iassign_statement_current->grade;
  1732. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1733. $param->timeavailable = $iassign_statement_current->timeavailable;
  1734. $param->timedue = $iassign_statement_current->timedue;
  1735. $param->preventlate = $iassign_statement_current->preventlate;
  1736. $param->test = $iassign_statement_current->test;
  1737. $param->special_param1 = $iassign_statement_current->special_param1;
  1738. $param->position = $iassign_statement_current->position; // oculto
  1739. $param->visible = $iassign_statement_current->visible;
  1740. $param->max_experiment = $iassign_statement_current->max_experiment;
  1741. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1742. $param->show_answer = $iassign_statement_current->show_answer;
  1743. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1744. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1745. if ($files) {
  1746. foreach ($files as $file) {
  1747. if ($file->get_filename() != '.') {
  1748. $param->filename = $file->get_filename();
  1749. $param->file = $file->get_id();
  1750. $param->fileold = $file->get_id();
  1751. $COURSE->iassign_file_id = $file->get_id();
  1752. }
  1753. }
  1754. }
  1755. //TODO //MOOC2014 -- inicio
  1756. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1757. //D if ($iassign_ilm_configs) {
  1758. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1759. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1760. //D } //MOOC2014 -- fim
  1761. } // if ($this_activity != null)
  1762. } // elseif ($this->action == 'edit')
  1763. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1764. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1765. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1766. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1767. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1768. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1769. $param->position = $total_of_activities;
  1770. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1771. $mform->set_data($param);
  1772. if ($mform->is_cancelled()) {
  1773. $this->return_home_course('iassign_cancel');
  1774. exit;
  1775. }
  1776. else { // if ($mform->is_cancelled())
  1777. $result = $mform->get_data();
  1778. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1779. if ($result) {
  1780. $result->context = $context;
  1781. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1782. $result->grade = 0;
  1783. if ($result->type_iassign == 1) {
  1784. $result->automatic_evaluate = 0;
  1785. $result->show_answer = 0;
  1786. }
  1787. elseif ($result->automatic_evaluate == 0)
  1788. $result->show_answer = 0;
  1789. // $_POST['iassign_list']
  1790. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1791. if ($result->iassign_list) {
  1792. foreach ($result->iassign_list as $key => $value)
  1793. $result->dependency .= $key . ';';
  1794. }
  1795. else
  1796. $result->dependency = 0;
  1797. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1798. //TODO Then get it directly from the form data $_POST!
  1799. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1800. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1801. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1802. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1803. if ($this->action == 'add') {
  1804. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1805. if ($iassign_statement_name) {
  1806. $this->return_home_course('error_iassign_name');
  1807. die();
  1808. }
  1809. // Really insert the new iActivity in table '*_iassign_statement'
  1810. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1811. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1812. // Trigger module viewed event.
  1813. $event = \mod_iassign\event\iassign_created::create(array(
  1814. 'objectid' => $iassignid,
  1815. 'context' => $context
  1816. ));
  1817. $event->add_record_snapshot('course', $this->course);
  1818. $event->trigger();
  1819. $this->return_home_course('iassign_add');
  1820. } // if ($this->action == 'add')
  1821. elseif ($this->action == 'edit') {
  1822. $iassignid = $this->activity->update_iassign($result);
  1823. $this->activity->update_calendar($iassignid, $result->oldname);
  1824. // Trigger module viewed event.
  1825. $event = \mod_iassign\event\iassign_updated::create(array(
  1826. 'objectid' => $iassignid,
  1827. 'context' => $context
  1828. ));
  1829. $event->add_record_snapshot('course', $this->course);
  1830. $event->trigger();
  1831. $this->return_home_course('iassign_update');
  1832. } // elseif ($this->action == 'edit')
  1833. die();
  1834. } // if ($result)
  1835. } // else if ($mform->is_cancelled())
  1836. print $OUTPUT->header();
  1837. $mform->display();
  1838. print $OUTPUT->footer();
  1839. die();
  1840. } // function add_edit_iassign()
  1841. /// Search for dependencies
  1842. function search_dependency ($search_iassing_id, $iassign_statement) {
  1843. global $DB, $OUTPUT;
  1844. $dependency = "";
  1845. if ($iassign_statement)
  1846. foreach ($iassign_statement as $iassign) {
  1847. $inter_dependency = explode(';', $iassign->dependency);
  1848. if (in_array($search_iassing_id, $inter_dependency)) {
  1849. $dependency .= $iassign->id . ";";
  1850. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1851. } // if (in_array($search_iassing_id, $inter_dependency))
  1852. } // foreach ($iassign_statement as $iassign)
  1853. return $dependency;
  1854. }
  1855. /// Search for "sub"dependency
  1856. function search_sub_dependency ($search_iassing_id) {
  1857. global $DB, $OUTPUT;
  1858. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1859. $dependency = "";
  1860. if ($iassign_statement) {
  1861. $inter_dependency = explode(';', $iassign_statement->dependency);
  1862. foreach ($inter_dependency as $tmp) {
  1863. if ($tmp != 0)
  1864. $dependency .= $tmp . ";";
  1865. $dependency .= $this->search_sub_dependency($tmp);
  1866. } // foreach ($inter_dependency as $tmp)
  1867. } // if ($iassign_statement)
  1868. return $dependency;
  1869. }
  1870. // Warning message
  1871. static function warning_message_iassign ($strcode) {
  1872. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1873. }
  1874. /// Update grade of iAssign
  1875. // Called always any iAssign activity is created
  1876. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1877. static function update_grade_iassign ($iassignid) {
  1878. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1879. require_once($CFG->libdir . '/gradelib.php');
  1880. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1881. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1882. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1883. // Each iAssign item is associated with one item on the "gradebook"
  1884. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1885. //$sum_grade = 0;
  1886. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1887. //foreach($grade as $tmp) {
  1888. // $sum_grade += $tmp->grade;
  1889. // }
  1890. //1 Solution 1
  1891. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1892. //1 $sum_grade = 0; //1
  1893. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1894. //2 Solution 2
  1895. $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
  1896. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1897. if (key($array_sum_grade))
  1898. $sum_grade = key($array_sum_grade); //2
  1899. else
  1900. $sum_grade = 0; //2
  1901. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1902. $grades = NULL;
  1903. $params = array('itemname' => $grade_iassign->name);
  1904. $params['iteminstance'] = $iassignid;
  1905. $params['gradetype'] = GRADE_TYPE_VALUE;
  1906. //2016 if ($sum_grade != 0) {
  1907. $params['grademax'] = $sum_grade;
  1908. $params['rawgrademax'] = $sum_grade;
  1909. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1910. $params['grademin'] = 0;
  1911. // @calls /lib/gradelib.php: call to grade_item->insert()
  1912. //TODO: is there any error here in Moodle version 3.0?
  1913. //TODO: Incorrect property 'grademax' found when inserting grade object
  1914. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1915. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1916. }
  1917. /// Update grade of student
  1918. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1919. global $CFG, $DB, $OUTPUT;
  1920. require_once($CFG->libdir . '/gradelib.php');
  1921. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1922. // Review all the student submission for this iAssign activity
  1923. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1924. $total_grade = 0;
  1925. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1926. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1927. if ($iassign_submission)
  1928. $total_grade += $iassign_submission->grade;
  1929. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1930. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1931. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1932. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1933. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1934. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1935. $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
  1936. if (key($array_sum_grade))
  1937. $sum_grade = key($array_sum_grade); //2
  1938. else
  1939. $sum_grade = 0; //2
  1940. $grades['userid'] = $userid;
  1941. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1942. $params = array('itemname' => $grade_iassign->name);
  1943. $params['iteminstance'] = $iassignid;
  1944. $params['gradetype'] = GRADE_TYPE_VALUE;
  1945. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1946. $params['grademax'] = $sum_grade;
  1947. $params['rawgrademax'] = $sum_grade;
  1948. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1949. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1950. }
  1951. /// Display caption of icons
  1952. function view_legend_icons () {
  1953. global $USER, $CFG, $DB, $OUTPUT;
  1954. $id = $this->cm->id;
  1955. if ($this->action == 'print')
  1956. print '<table border=1 width=100%><tr>';
  1957. else
  1958. print '<table width=100%><tr>';
  1959. print '<td >';
  1960. if ($this->action != 'print')
  1961. print $OUTPUT->help_icon('legend', 'iassign');
  1962. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1963. // $imagetext = '');
  1964. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1965. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1966. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1967. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1968. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1969. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1970. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1971. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1972. print '</td>' . "\n";
  1973. if ($this->action != 'print') {
  1974. $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>";
  1975. $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>";
  1976. $link_export = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=export_csv&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('export_ilm') . '&nbsp;' . get_string('export_csv', 'iassign') . "</a>";
  1977. $link_auto_evaluate = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=auto_evaluate&iassignid=" . $this->iassign->id . "'>" . iassign_icons::insert('correct') . '&nbsp;' . get_string('auto_evaluate_reprocess', 'iassign') . "</a>";
  1978. $link_all_submissions_manager = "<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=all_submissions&iassignid=" . $this->iassign->id . "'><i class='fa fa-files-o' aria-hidden='true' style='color: red'></i>&nbsp;" . get_string('all_submissions_manager', 'iassign') . "</a>";
  1979. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1980. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1981. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1982. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1983. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1984. } // if ($this->action != 'print')
  1985. print '</tr></table>' . "\n";
  1986. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1987. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1988. $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>";
  1989. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1990. print '</tr></table>' . "\n";
  1991. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1992. else
  1993. print '</td></tr></table>' . "\n";
  1994. } // function view_legend_icons()
  1995. /// Display activity current
  1996. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1997. function view_iassign_current () {
  1998. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1999. $id = $this->cm->id;
  2000. $iassignid = $this->iassign->id;
  2001. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2002. $iassign = $DB->get_record("iassign", array("id" => $iassignid)); // from table '*_iassign': id course name intro introformat activity_group grade timeavailable timedue preventlate test max_experiment
  2003. // Get data of current activity : table '*_iassign_statement' = id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid file grade timemodified timecreated ...
  2004. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  2005. if (!$iassign_statement_activity_item) {
  2006. print $OUTPUT->header();
  2007. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2008. print $OUTPUT->footer();
  2009. exit;
  2010. }
  2011. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2012. $ilm_name = '';
  2013. if ($ilm->ilm)
  2014. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2015. // 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
  2016. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2017. // log record
  2018. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2019. //Trigger module viewed event.
  2020. $event = \mod_iassign\event\submission_viewed::create(array(
  2021. 'objectid' => $iassign->id,
  2022. 'context' => $this->context,
  2023. 'other' => $info
  2024. ));
  2025. $event->add_record_snapshot('course', $this->course);
  2026. $event->trigger();
  2027. // Search of iLM data used in the current activity
  2028. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2029. // Add actual activity to navbar:
  2030. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2031. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2032. print $OUTPUT->header();
  2033. if ($this->action == 'viewsubmission') {
  2034. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2035. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2036. else
  2037. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2038. } else {
  2039. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2040. }
  2041. if ($iassign_submission)
  2042. $this->update_comment($iassign_submission->id);
  2043. $file = $iassign_statement_activity_item->file;
  2044. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2045. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2046. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2047. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2048. $this->bottonPost = 0; // hide submit button
  2049. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2050. $this->view_iassign = false; // disable visualization of activity
  2051. $repeat = "";
  2052. $last_iassign = "";
  2053. $student_answer = "";
  2054. $comment = "";
  2055. // *** Teacher access (view learner's submission)
  2056. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2057. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2058. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2059. // ---> access teacher for test
  2060. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2061. $this->bottonPost = 1;
  2062. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2063. $this->activity->view_dates();
  2064. $USER->iassignEdit = $this->bottonPost;
  2065. $this->activity->show_info_iassign();
  2066. if ($iassign_submission) {
  2067. //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;
  2068. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2069. } else {
  2070. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2071. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2072. }
  2073. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2074. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2075. // Prepare tags to present the iLM
  2076. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2077. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2078. // *** (end) Teacher access (view the activity)
  2079. // *** Teacher access (view learner's submission to the activity)
  2080. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2081. // It is teacher or 'nonediting teacher' that can evaluate
  2082. // ----> area teacher evaluate
  2083. $row = optional_param('row', 0, PARAM_INT);
  2084. $column = optional_param('column', 0, PARAM_INT);
  2085. $link_next = iassign_icons::insert('right_disable');
  2086. $link_previous = iassign_icons::insert('left_disable');
  2087. $link_up = iassign_icons::insert('up_disable');
  2088. $link_down = iassign_icons::insert('down_disable');
  2089. // next_activity
  2090. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2091. $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);
  2092. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2093. }
  2094. // previous_activity
  2095. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2096. $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);
  2097. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2098. }
  2099. // previous_student
  2100. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2101. $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);
  2102. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2103. }
  2104. // next_student
  2105. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2106. $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);
  2107. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2108. }
  2109. if ($iassign_submission) {
  2110. $student_answer = $iassign_submission->answer;
  2111. }
  2112. $last_iassign = get_string('last_iassign', 'iassign');
  2113. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2114. // Messages related to due date (and user role)
  2115. $this->activity->view_dates();
  2116. print $OUTPUT->box_start();
  2117. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2118. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2119. print $OUTPUT->user_picture($user_data);
  2120. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2121. print '</td>' . "\n";
  2122. print '<td width=20% align=right>' . "\n";
  2123. print '<table width=50 cellpadding="0">';
  2124. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2125. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2126. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2127. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2128. print '</table>' . "\n";
  2129. print '</td></tr></table>' . "\n";
  2130. print $OUTPUT->box_end();
  2131. print $OUTPUT->box_start();
  2132. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2133. print '<td width=60% valign="top">' . "\n";
  2134. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2135. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2136. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2137. $resp = get_string('yes');
  2138. else
  2139. $resp = get_string('no');
  2140. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2141. if ($iassign_statement_activity_item->show_answer == 1)
  2142. $resp = get_string('yes');
  2143. else
  2144. $resp = get_string('no');
  2145. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2146. print '</td>';
  2147. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2148. print '<td width=40% valign="top" align="left">';
  2149. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2150. // check status of solution sent by the student
  2151. if ($iassign_submission) {
  2152. switch ($iassign_submission->status) {
  2153. case 3 :
  2154. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2155. break;
  2156. case 2 :
  2157. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2158. break;
  2159. case 1 :
  2160. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2161. break;
  2162. default :
  2163. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2164. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2165. } // switch ($iassign_submission->status)
  2166. }
  2167. else { // if ($iassign_submission)
  2168. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2169. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2170. }
  2171. // update_status
  2172. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2173. $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);
  2174. print " <script type='text/javascript'>
  2175. //<![CDATA[
  2176. function overwriteStatus (newstatus) {
  2177. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2178. document.formEditStatus.return_status.value=newstatus;
  2179. document.formEditStatus.submit();
  2180. }
  2181. else
  2182. document.formEditStatus.return_status.value=-1;
  2183. }
  2184. //]]>
  2185. </script>";
  2186. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2187. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2188. 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";
  2189. print " <input type='hidden' name='return_status'>\n";
  2190. print "</form>\n";
  2191. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2192. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2193. $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);
  2194. print "
  2195. <script type='text/javascript'>
  2196. //<![CDATA[
  2197. function overwriteGrade (newgrade,maxgrade) {
  2198. if (newgrade<0 || newgrade>maxgrade) {
  2199. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2200. document.formEditGrade.return_grade.value=-1;
  2201. document.formEditGrade.submit();
  2202. }
  2203. else {
  2204. document.formEditGrade.return_grade.value=newgrade;
  2205. document.formEditGrade.submit();
  2206. }
  2207. }
  2208. //]]>
  2209. </script>";
  2210. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2211. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2212. print " <input type='text' name='grade' size='6'>";
  2213. print " <input type='hidden' name='return_grade'> ";
  2214. 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";
  2215. print "</form>";
  2216. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2217. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2218. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2219. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2220. if ($teacher)
  2221. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2222. } // if ($iassign_submission->experiment > 0)
  2223. print '</td>';
  2224. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2225. print '</tr></table>';
  2226. print $OUTPUT->box_end();
  2227. $USER->iassignEdit = $this->bottonPost;
  2228. if ($iassign_submission && $allow_resubmission) {
  2229. // Put the iLM to
  2230. print $OUTPUT->box_start();
  2231. print '<p><strong>' . $last_iassign . '</strong></p>';
  2232. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2233. $enderecoPOST = "";
  2234. // Prepare tags to present the iLM
  2235. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2236. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2237. print $OUTPUT->box_end();
  2238. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2239. // ATTENTION: exception used by iGeom (exercise with "script")
  2240. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2241. if (substr($ilm_name, 0, 5)=="igeom") {
  2242. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2243. $loadTeacherActivity = true;
  2244. }
  2245. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2246. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2247. // Prepare tags to present the iLM
  2248. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2249. }
  2250. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2251. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2252. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2253. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2254. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2255. // *** (end) Teacher access (view learner's submission to the activity)
  2256. // *** Student access (view the activity)
  2257. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2258. // It could be the learner (he could send or resend the activity)
  2259. // ---> access student
  2260. $time_now = time();
  2261. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2262. // activity of type example - not submit button for submission
  2263. $this->view_iassign = true;
  2264. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2265. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2266. // activity of type test - iLM automatic evaluator - submit button for submission
  2267. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2268. $this->bottonPost = 1;
  2269. $this->view_iassign = true;
  2270. } else
  2271. $this->view_iassign = false;
  2272. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2273. // activity of type exercise (learner can send his answer, if yet open...)
  2274. $this->view_iassign = true;
  2275. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2276. $this->view_iassign = false;
  2277. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2278. $this->bottonPost = 1; // allow the submit button
  2279. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2280. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2281. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2282. if (!$iassign_submission) {
  2283. $str_iassign_submission_id = '';
  2284. $str_iassign_submission_answer = '';
  2285. }
  2286. else {
  2287. $str_iassign_submission_id = $iassign_submission->id;
  2288. $str_iassign_submission_answer = $iassign_submission->answer;
  2289. }
  2290. if ($this->action != 'repeat') {
  2291. $repeat = "<a href='view.php?action=repeat&id="
  2292. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2293. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2294. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2295. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2296. }
  2297. $this->bottonPost = 1;
  2298. $this->write_solution = 1; // can register his submission
  2299. $student_answer = $str_iassign_submission_answer;
  2300. }
  2301. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2302. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2303. $last_iassign = get_string('last_iassign', 'iassign');
  2304. if ($iassign_submission) {
  2305. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2306. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2307. $student_answer = $iassign_submission->answer;
  2308. } else {
  2309. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2310. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2311. }
  2312. }
  2313. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2314. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2315. $this->bottonPost = 1;
  2316. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2317. } else {
  2318. $last_iassign = get_string('last_iassign', 'iassign');
  2319. if ($iassign_submission) {
  2320. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2321. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2322. $student_answer = $iassign_submission->answer;
  2323. } else {
  2324. // Symbol of "redo activity"
  2325. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2326. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2327. }
  2328. }
  2329. } // elseif ($iassign_statement_activity_item->test == 1)
  2330. elseif ($iassign_statement_activity_item->test == 0)
  2331. $this->view_iassign = false;
  2332. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2333. if ($iassign_submission)
  2334. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2335. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2336. else
  2337. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2338. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2339. $this->activity->view_dates();
  2340. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2341. print $OUTPUT->box_start();
  2342. print '<table width=100% border=0 valign="top">' . "\n";
  2343. print '<tr><td width=60% valign="top">' . "\n";
  2344. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2345. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2346. $flag_dependency = true;
  2347. if ($iassign_statement_activity_item->type_iassign == 3) {
  2348. if ($iassign_statement_activity_item->dependency == 0) {
  2349. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2350. } else {
  2351. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2352. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2353. foreach ($dependencys as $dependency) {
  2354. if ($dependency) {
  2355. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2356. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2357. if ($dependencysubmissions) {
  2358. if ($dependencysubmissions->status == 3)
  2359. $icon = iassign_icons::insert('correct');
  2360. elseif ($dependencysubmissions->status == 2) {
  2361. $icon = iassign_icons::insert('incorrect');
  2362. $flag_dependency = false;
  2363. } elseif ($dependencysubmissions->status == 1) {
  2364. $icon = iassign_icons::insert('post');
  2365. $flag_dependency = false;
  2366. } elseif ($dependencysubmissions->status == 0) {
  2367. $icon = iassign_icons::insert('not_post');
  2368. $flag_dependency = false;
  2369. }
  2370. } else {
  2371. $icon = iassign_icons::insert('not_post');
  2372. $flag_dependency = false;
  2373. } // if ($dependencysubmissions)
  2374. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2375. } // if ($dependency)
  2376. } // foreach ($dependencys as $dependency)
  2377. } // if ($iassign_statement_activity_item->dependency == 0)
  2378. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2379. if ($flag_dependency == false) {
  2380. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2381. $this->view_iassign = false;
  2382. print '</tr></table>' . "\n";
  2383. }
  2384. else {
  2385. $this->view_iassign = true;
  2386. print '</td>' . "\n";
  2387. } // if ($flag_dependency == false)
  2388. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2389. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2390. // receiver=1 - message to teacher
  2391. // receiver=2 - message to student
  2392. if ($iassign_submission) {
  2393. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2394. if ($verify_message)
  2395. $comment = iassign_icons::insert('comment_unread');
  2396. }
  2397. print '<td width=40% valign="top" align="left">';
  2398. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2399. if ($iassign_statement_activity_item->show_answer == 1) {
  2400. // check status of solution sent by the student
  2401. if ($iassign_submission) {
  2402. switch ($iassign_submission->status) {
  2403. case 3 :
  2404. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2405. break;
  2406. case 2 :
  2407. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2408. break;
  2409. case 1 :
  2410. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2411. break;
  2412. default :
  2413. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2414. $repeat = "";
  2415. $last_iassign = "";
  2416. } // switch ($iassign_submission->status)
  2417. } else {
  2418. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2419. $repeat = "";
  2420. $last_iassign = "";
  2421. }
  2422. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2423. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2424. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2425. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2426. if ($iassign_statement_activity_item->max_experiment == 0)
  2427. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2428. else {
  2429. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2430. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2431. $repeat = "";
  2432. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2433. $this->bottonPost = 0;
  2434. $this->write_solution = 0;
  2435. }
  2436. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2437. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2438. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2439. if ($teacher)
  2440. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2441. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2442. } // if ($iassign_statement_activity_item->show_answer==1)
  2443. else {
  2444. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2445. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2446. $repeat = "";
  2447. $last_iassign = "";
  2448. } elseif ($iassign_submission->status == 1) {
  2449. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2450. }
  2451. }
  2452. print '</td>';
  2453. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2454. print '</tr></table>' . "\n";
  2455. // Presents the iLM
  2456. print '<table width=100% border=0 valign="top">' . "\n";
  2457. print '<td width=80% align="left">';
  2458. 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\".
  2459. print '<td width=20% align="rigth">';
  2460. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2461. print $repeat; // symbol of "redo activity"
  2462. print '</td></tr></table>' . "\n";
  2463. //2019 print $OUTPUT->box_end(); // closing Box 5 but sometimes it does reach this point - see it at the end of 'if ($this->view_iassign)'
  2464. $output = '';
  2465. if (!$iassign_ilm) {
  2466. $iassign_ilm = new stdClass();
  2467. $iassign_ilm->file_jar = "";
  2468. }
  2469. $output .= $OUTPUT->box_start();
  2470. $USER->iassignEdit = $this->bottonPost;
  2471. // ---
  2472. // Presents the iLM
  2473. // Prepare tags to present the iLM
  2474. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2475. $student_answer = ""; //?
  2476. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2477. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2478. $student_answer = "";
  2479. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2480. } else {
  2481. // When student is redoing his activity
  2482. // ATTENTION: exception used by iGeom (exercise with "script")
  2483. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2484. if (substr($ilm_name, 0, 5)=="igeom") {
  2485. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2486. $loadTeacherActivity = true;
  2487. }
  2488. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2489. }
  2490. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2491. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2492. //1 $history_comment = '';
  2493. //1 if ($iassign_submission) {
  2494. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2495. //1 }
  2496. //1 if (!empty($history_comment)) {
  2497. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2498. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2499. //1 $output .= $history_comment;
  2500. //1 $output .= "</table>\n";
  2501. //1 }
  2502. //1 $output .= "</form></center>\n";
  2503. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2504. //1 }
  2505. $output .= $OUTPUT->box_end();
  2506. print $output;
  2507. } // if ($this->view_iassign)
  2508. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2509. } // if ($this->view_iassign)
  2510. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2511. else
  2512. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2513. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2514. print '<table width=100% border=0 valign="top">' . "\n";
  2515. print '<tr><td width=60% valign="top">' . "\n";
  2516. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2517. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2518. print '</tr></table>' . "\n";
  2519. $student_answer = "";
  2520. $enderecoPOST = "";
  2521. // Prepare tags to present the iLM
  2522. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2523. print $output;
  2524. }
  2525. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2526. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2527. if ($only_one_send_button==0 && $iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2528. // Put a block with area to sent/answer comments
  2529. $output = '';
  2530. $history_comment = '';
  2531. $row = optional_param('row', 0, PARAM_INT);
  2532. $column = optional_param('column', 0, PARAM_INT);
  2533. if ($iassign_submission) {
  2534. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2535. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2536. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2537. }
  2538. else {
  2539. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2540. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2541. }
  2542. $output .= $OUTPUT->box_start();
  2543. //if (!empty($history_comment)) {
  2544. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2545. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2546. $output .= "</table>";
  2547. print " <script type='text/javascript'>
  2548. //<![CDATA[
  2549. function submit_comment(url) {
  2550. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2551. var formData = new FormData();
  2552. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2553. var request = new XMLHttpRequest();
  2554. request.open('POST', url);
  2555. document.getElementById('comments_history').innerHTML = '';
  2556. request.onload = function (e) {
  2557. if (request.readyState === 4) {
  2558. if (request.status === 200) {
  2559. document.getElementById('comments_history').innerHTML = request.responseText;
  2560. document.getElementById('check-message-success').style.visibility = 'visible';
  2561. setTimeout(function(){
  2562. document.getElementById('check-message-success').style.visibility = 'hidden';
  2563. }, 3000);
  2564. }
  2565. }
  2566. };
  2567. document.formEnvioComment.submission_comment.value = '';
  2568. request.send(formData);
  2569. }
  2570. //]]>
  2571. </script>";
  2572. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2573. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2574. $output .= "<p><button class='btn btn-primary' onclick=\"submit_comment('$enderecoPOSTcomment')\" type=button value='" . get_string('submit_comment', 'iassign') . "'>".get_string('submit_comment', 'iassign')."</button> <i id='check-message-success' class='fa fa-check' aria-hidden='true' style='position: absolute; color: green; font-size: 2.0rem; margin-left: 1rem; visibility: hidden;'></i> </p> \n";
  2575. $output .= "</form> </center>\n";
  2576. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2577. // }
  2578. $output .= $OUTPUT->box_end();
  2579. print $output;
  2580. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2581. // final block 'studant'
  2582. print $OUTPUT->footer();
  2583. die();
  2584. } // function view_iassign_current()
  2585. /// Export the data from performance report into CSV file format
  2586. function export_csv () {
  2587. global $USER, $CFG, $DB, $OUTPUT;
  2588. $str = "";
  2589. $fields = "student_id, student_name";
  2590. // Finding all iassign activities for the iassign:
  2591. $id = $this->cm->id;
  2592. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2593. $c = 1;
  2594. foreach ($iassign_list as $iassign) {
  2595. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2596. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2597. $c ++;
  2598. }
  2599. // Finding enrolled students:
  2600. $params = array('shortname' => 'student');
  2601. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2602. $context = context_course::instance($this->course->id);
  2603. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2604. $students = $DB->get_records_sql(
  2605. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2606. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2607. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2608. foreach ($students as $student) {
  2609. $str .= $student->userid . ',';
  2610. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2611. foreach ($iassign_list as $iassign) {
  2612. $str .= ',' . $iassign->id . ',';
  2613. $str .= '"' . $iassign->name . '",';
  2614. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2615. if ($student_submissions) {
  2616. $str .= $student_submissions->experiment . ',';
  2617. $str .= $student_submissions->grade . ',';
  2618. switch ($student_submissions->status) {
  2619. case 3:
  2620. $str .= '"correct",';
  2621. break;
  2622. case 2:
  2623. $str .= '"incorrect",';
  2624. break;
  2625. case 1:
  2626. $str .= '"post",';
  2627. break;
  2628. case 0:
  2629. $str .= '"not_post",';
  2630. break;
  2631. }
  2632. } else {
  2633. $str .= ',,"not_post",';
  2634. }
  2635. $str .= $iassign->iassign_ilmid . ',';
  2636. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2637. $str .= '"' . $ilm_activity->name . '"';
  2638. }
  2639. $str .= "\n";
  2640. }
  2641. $str = $fields . "\n" . $str;
  2642. header("Content-type: text/csv");
  2643. header("Content-disposition: attachment; filename=report.csv");
  2644. header("Pragma: no-cache");
  2645. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2646. header('Content-Length: ' . strlen($str));
  2647. header('Connection: close');
  2648. print $str;
  2649. flush();
  2650. } // function export_csv()
  2651. /// Display report of performance
  2652. function report () {
  2653. global $USER, $CFG, $DB, $OUTPUT;
  2654. $id = $this->cm->id;
  2655. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2656. if ($this->action != 'print') {
  2657. $title = get_string('report', 'iassign');
  2658. print $OUTPUT->header();
  2659. } // if ($this->action != 'print')
  2660. print $OUTPUT->box_start();
  2661. $this->view_legend_icons();
  2662. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2663. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2664. print $OUTPUT->box_end();
  2665. if ($this->action == 'print')
  2666. print '<table border=1 width="100%">' . "\n";
  2667. else
  2668. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2669. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2670. // $num = array();
  2671. $i = 1;
  2672. $num = array();
  2673. foreach ($iassign_list as $iassign) {
  2674. $test_exercise = "";
  2675. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2676. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2677. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2678. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2679. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2680. $num[$i] = new stdClass();
  2681. $num[$i]->name = $iassign->name;
  2682. $num[$i]->id = $i;
  2683. $num[$i]->iassignid = $iassign->id;
  2684. print ' <tr >' . "\n";
  2685. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2686. print "<td class=\"cell c0 actvity\">";
  2687. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2688. print ' </tr>' . "\n";
  2689. $i ++;
  2690. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2691. } // foreach ($iassign_list as $iassign)
  2692. print "</table>";
  2693. print "<p></p>";
  2694. if ($this->action == 'print')
  2695. print '<table border=1 width="100%">' . "\n";
  2696. else
  2697. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2698. $context = context_course::instance($this->course->id);
  2699. if ($i > 1) {
  2700. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2701. $params = array('shortname' => 'student');
  2702. $role = $DB->get_record_sql(
  2703. "SELECT s.id, s.shortname FROM {role} s " .
  2704. " WHERE s.shortname = :shortname", $params);
  2705. // $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");
  2706. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2707. $students = $DB->get_records_sql(
  2708. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2709. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2710. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2711. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2712. for ($j = 1; $j < $i; $j ++) {
  2713. $sum_iassign_correct[$j] = 0;
  2714. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2715. }
  2716. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2717. $sum_iassign = $j - 1;
  2718. print '</tr>' . "\n";
  2719. $total = 0;
  2720. $sum_student = 0;
  2721. $comment = iassign_icons::insert('comment_read');
  2722. $sum_comment = 0;
  2723. $sum_correct_iassign = array();
  2724. $sum_correct_student = array();
  2725. $USER->matrix_iassign = array();
  2726. if ($students) {
  2727. $w = 0;
  2728. foreach ($students as $tmp) {
  2729. $users_array[$w] = $tmp;
  2730. $w ++;
  2731. }
  2732. for ($x = 0; $x < $w; $x ++) {
  2733. print '<tr>' . "\n";
  2734. $sum_student ++;
  2735. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2736. print ' <td >' . $name . '</td>' . "\n";
  2737. $total_student = 0;
  2738. $tentativas = 0;
  2739. for ($j = 1; $j < $i; $j ++) {
  2740. $sum_comment = 0;
  2741. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2742. print ' <td valign="bottom" align="center">' . "\n";
  2743. if ($student_submissions) {
  2744. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2745. $tentativas = $student_submissions->experiment;
  2746. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2747. $params = array('iassign_submissionid' => $student_submissions->id);
  2748. $student_submissions_comment = $DB->get_record_sql(
  2749. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2750. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2751. if ($student_submissions_comment)
  2752. foreach ($student_submissions_comment as $tmp)
  2753. $sum_comment = $tmp;
  2754. // informations to previous activities
  2755. if ($j - 1 < 1 || $j == $i)
  2756. $iassign_previous = "-1";
  2757. else
  2758. $iassign_previous = $num[$j - 1]->iassignid;
  2759. if ($x - 1 < 0 || $x == $w)
  2760. $user_previous = "-1";
  2761. else
  2762. $user_previous = $users_array[$x - 1]->userid;
  2763. // next
  2764. if ($i - 1 > $j)
  2765. $iassign_next = $num[$j + 1]->iassignid;
  2766. else
  2767. $iassign_next = "-1";
  2768. if ($w - 1 > $x)
  2769. $user_next = $users_array[$x + 1]->userid;
  2770. else
  2771. $user_next = "-1";
  2772. $position = "&row= $x&column=$j";
  2773. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2774. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2775. $url .= $position;
  2776. // receiver=1 - message to teacher
  2777. // receiver=2 - message to student
  2778. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2779. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2780. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2781. $verify_message = $DB->get_record_sql(
  2782. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2783. "WHERE iassign_submissionid = :iassign_submissionid " .
  2784. " AND return_status= :return_status " .
  2785. " AND receiver= :receiver", $params);
  2786. if ($verify_message)
  2787. foreach ($verify_message as $tmp)
  2788. $sum_verify_message = $tmp;
  2789. if ($sum_verify_message > 0)
  2790. $comment = iassign_icons::insert('comment_unread');
  2791. else
  2792. $comment = iassign_icons::insert('comment_read');
  2793. if ($student_submissions->status == 3) {
  2794. $sum_iassign_correct[$j] ++;
  2795. $total_student ++;
  2796. $feedback = iassign_icons::insert('correct');
  2797. }
  2798. elseif ($student_submissions->status == 2) {
  2799. $feedback = iassign_icons::insert('incorrect');
  2800. }
  2801. elseif ($student_submissions->status == 1) {
  2802. $feedback = iassign_icons::insert('post');
  2803. }
  2804. elseif ($student_submissions->status == 0) {
  2805. $feedback = iassign_icons::insert('not_post');
  2806. }
  2807. if ($this->action != 'print') {
  2808. print '<table><tr>';
  2809. if ($tentativas > 0)
  2810. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2811. else
  2812. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2813. print '<td> &nbsp; </td>';
  2814. print '</tr>' . "\n";
  2815. if ($sum_comment > 0 && $sum_verify_message > 0)
  2816. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2817. else if ($sum_comment > 0)
  2818. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2819. print '</table>' . "\n";
  2820. }
  2821. if ($this->action == 'print')
  2822. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2823. } // if ($student_submissions)
  2824. else { // if ($student_submissions)
  2825. // informations to browse previous activities
  2826. if ($j - 1 < 1 || $j == $i)
  2827. $iassign_previous = "-1";
  2828. else
  2829. $iassign_previous = $num[$j - 1]->iassignid;
  2830. if ($x - 1 < 0 || $x == $w)
  2831. $user_previous = "-1";
  2832. else
  2833. $user_previous = $users_array[$x - 1]->userid;
  2834. // next
  2835. if ($i - 1 > $j)
  2836. $iassign_next = $num[$j + 1]->iassignid;
  2837. else
  2838. $iassign_next = "-1";
  2839. if ($w - 1 > $x)
  2840. $user_next = $users_array[$x + 1]->userid;
  2841. else
  2842. $user_next = "-1";
  2843. $position = "&row= $x&column=$j";
  2844. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2845. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2846. $url .= $position;
  2847. $feedback = iassign_icons::insert('not_post');
  2848. if ($this->action == 'print')
  2849. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2850. else {
  2851. print '<table><tr>';
  2852. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2853. print '<td> &nbsp; </td>';
  2854. print '</tr><tr>' . "\n";
  2855. print '<td> &nbsp;</td>';
  2856. if ($sum_comment > 0)
  2857. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2858. else
  2859. print '<td> &nbsp;</td>';
  2860. print '</tr></table>';
  2861. }
  2862. } // else if ($student_submissions)
  2863. $USER->matrix_iassign[$x][$j] = new stdClass();
  2864. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2865. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2866. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2867. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2868. if ($student_submissions)
  2869. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2870. else
  2871. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2872. print '</td>' . "\n";
  2873. } // for ($j=1; $j<$i; $j++)
  2874. $total = $total + $total_student;
  2875. $porcentagem = ($total_student / ($j - 1)) * 100;
  2876. if ($tentativas != 0 && $tentativas != null) {
  2877. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2878. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2879. }
  2880. else {
  2881. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2882. }
  2883. print '</tr>' . "\n";
  2884. $sum_correct_student[$sum_student] = new stdClass();
  2885. $sum_correct_student[$sum_student]->name = $name;
  2886. $sum_correct_student[$sum_student]->sum = $total_student;
  2887. } // for ($x = 0; $x < $w; $x ++)
  2888. for ($i = 1; $i < $j; $i ++) {
  2889. if (is_null($sum_iassign_correct[$i]))
  2890. $sum_iassign_correct[$i] = 0;
  2891. $sum_correct_iassign[$i] = new stdClass();
  2892. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2893. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2894. }
  2895. // print '</tr></table>' . "\n";
  2896. }
  2897. } // if ($i>1)
  2898. else {
  2899. print_string('no_activity', 'iassign');
  2900. }
  2901. print "</table>\n";
  2902. if ($this->action != 'print')
  2903. print $OUTPUT->footer();
  2904. die();
  2905. } // function report()
  2906. /// Display graphics of performance
  2907. function stats () {
  2908. global $USER, $CFG, $DB, $OUTPUT;
  2909. $id = $this->cm->id;
  2910. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2911. if ($this->action != 'printstats')
  2912. $title = get_string('graphic', 'iassign');
  2913. $num = array();
  2914. $sum_correct_iassign = array();
  2915. $sum_correct_student = array();
  2916. $sum_student = 0;
  2917. $i = 1;
  2918. foreach ($iassign_list as $iassign) {
  2919. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2920. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2921. $sum_iassign_correct[$i] = 0;
  2922. $num[$i] = new stdClass();
  2923. $num[$i]->name = $iassign->name;
  2924. $num[$i]->id = $i;
  2925. $num[$i]->iassignid = $iassign->id;
  2926. $i ++;
  2927. } // if ($iassign->type_iassign == 3)
  2928. } // foreach ($iassign_list as $iassign)
  2929. $sum_iassign = $i - 1;
  2930. $context = context_course::instance($this->course->id);
  2931. if ($i > 1) {
  2932. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2933. $params = array('shortname' => 'student');
  2934. $role = $DB->get_record_sql(
  2935. "SELECT s.id, s.shortname FROM {role} s " .
  2936. " WHERE s.shortname = :shortname", $params);
  2937. // $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");
  2938. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2939. $students = $DB->get_records_sql(
  2940. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2941. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2942. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2943. $total = 0;
  2944. $sum_student = 0;
  2945. $j = 0;
  2946. $sum_correct_iassign = array();
  2947. $sum_correct_student = array();
  2948. $sum_experiment = array();
  2949. if ($students) {
  2950. foreach ($students as $users) {
  2951. $sum_student ++;
  2952. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2953. // rows
  2954. $total_student = 0;
  2955. for ($j = 1; $j < $i; $j ++) {
  2956. $total_experiment = 0;
  2957. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2958. if ($student_submissions) {
  2959. if ($student_submissions->status == 3) {
  2960. $sum_iassign_correct[$j] ++;
  2961. $total_student ++;
  2962. } // if ($student_submissions->status == 3)
  2963. $total_experiment += $student_submissions->experiment;
  2964. }
  2965. $sum_experiment[$j] = $total_experiment;
  2966. } // for ($j=1; $j<$i; $j++)
  2967. $total = $total + $total_student;
  2968. $sum_correct_student[$sum_student] = new stdClass();
  2969. $sum_correct_student[$sum_student]->name = $name;
  2970. $sum_correct_student[$sum_student]->sum = $total_student;
  2971. } // foreach ($students as $users)
  2972. }
  2973. for ($i = 1; $i < $j; $i ++) {
  2974. if (is_null($sum_iassign_correct[$i]))
  2975. $sum_iassign_correct[$i] = 0;
  2976. $sum_correct_iassign[$i] = new stdClass();
  2977. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2978. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2979. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2980. } // for ($i = 1; $i < $j; $i++)
  2981. } // if ($i > 1)
  2982. if ($this->action != 'printstats') {
  2983. $title = get_string('graphic', 'iassign');
  2984. print $OUTPUT->header();
  2985. $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>";
  2986. $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>";
  2987. print '<table width=100%><tr>';
  2988. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2989. print '<td width=15% align="right">' . $link_report . '</td>';
  2990. print '</td></tr></table>' . "\n";
  2991. print "<br><br>";
  2992. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2993. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2994. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2995. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2996. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2997. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2998. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2999. print '</tr>' . "\n";
  3000. $sum_correct = 0;
  3001. if ($sum_correct_iassign) {
  3002. foreach ($sum_correct_iassign as $iassign) {
  3003. if (is_null($iassign->experiment))
  3004. $iassign->experiment = 0;
  3005. $bar = "";
  3006. $sum = $iassign->sum;
  3007. $percent = ($sum / $sum_student) * 100;
  3008. $text = number_format($percent, 1) . '%';
  3009. $sum_correct += $sum;
  3010. if ($sum > 0) {
  3011. for ($i = 1; $i < $percent * 2; $i ++)
  3012. $bar .= iassign_icons::insert('hbar_blue');
  3013. $bar .= iassign_icons::insert('hbar_blue_r');
  3014. } // if ($sum > 0)
  3015. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3016. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3017. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3018. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3019. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3020. print '</tr>' . "\n";
  3021. } // foreach ($sum_correct_iassign as $iassign)
  3022. }
  3023. print "</table>";
  3024. print "<br><br>";
  3025. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3026. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3027. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3028. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3029. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3030. print '</tr>' . "\n";
  3031. $sum_correct = 0;
  3032. foreach ($sum_correct_student as $student) {
  3033. $bar = "";
  3034. $sum = $student->sum;
  3035. $percent = ($sum / $sum_iassign) * 100;
  3036. $text = number_format($percent, 1) . '%';
  3037. $sum_correct += $sum;
  3038. if ($sum > 0) {
  3039. for ($i = 1; $i < $percent * 2; $i ++)
  3040. $bar .= iassign_icons::insert('hbar_blue');
  3041. $bar .= iassign_icons::insert('hbar_blue_r');
  3042. } // if ($sum > 0)
  3043. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3044. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3045. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3046. print '</tr>' . "\n";
  3047. } // foreach ($sum_correct_student as $student)
  3048. print "</table>\n";
  3049. print "<br><br>\n";
  3050. $var = 0;
  3051. $cv = 0;
  3052. $dv = 0;
  3053. $avg = 0;
  3054. if ($sum_correct_student) {
  3055. $avg = $sum_correct / $sum_student;
  3056. if ($avg > 0) {
  3057. foreach ($sum_correct_student as $student)
  3058. $var += pow($student->sum - $avg, 2);
  3059. $var = $var / $sum_student;
  3060. $dv = sqrt($var);
  3061. $cv = ($dv / $avg) * 100;
  3062. }
  3063. }
  3064. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3065. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3066. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3067. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3068. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3069. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3070. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3071. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3072. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3073. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3074. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3075. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3076. print "</table>\n";
  3077. print $OUTPUT->footer();
  3078. } else {
  3079. print "<STYLE TYPE='text/css'>
  3080. <!--
  3081. .boldtable {
  3082. font-family:sans-serif;
  3083. font-size:10pt;
  3084. }
  3085. -->
  3086. </STYLE>\n";
  3087. print '<table border=1 width=100%>' . "\n";
  3088. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3089. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3090. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3091. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3092. print '</tr>' . "\n";
  3093. $sum_correct = 0;
  3094. foreach ($sum_correct_iassign as $iassign) {
  3095. $bar = "";
  3096. $sum = $iassign->sum;
  3097. $percent = ($sum / $sum_student) * 100;
  3098. $text = number_format($percent, 1) . '%';
  3099. $sum_correct += $sum;
  3100. if ($sum > 0) {
  3101. for ($i = 1; $i < $percent * 2; $i ++)
  3102. $bar .= iassign_icons::insert('hbar_blue');
  3103. $bar .= iassign_icons::insert('hbar_blue_r');
  3104. } // if ($sum > 0)
  3105. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3106. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3107. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3108. print '</tr>' . "\n";
  3109. } // foreach ($sum_correct_iassign as $iassign)
  3110. print "</table>";
  3111. print "<br><br>";
  3112. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3113. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3114. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3115. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3116. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3117. print '</tr>' . "\n";
  3118. $sum_correct = 0;
  3119. foreach ($sum_correct_student as $student) {
  3120. $bar = "";
  3121. $sum = $student->sum;
  3122. $percent = ($sum / $sum_iassign) * 100;
  3123. $text = number_format($percent, 1) . '%';
  3124. $sum_correct += $sum;
  3125. if ($sum > 0) {
  3126. for ($i = 1; $i < $percent * 2; $i ++)
  3127. $bar .= iassign_icons::insert('hbar_blue');
  3128. $bar .= iassign_icons::insert('hbar_blue_r');
  3129. } // if ($sum > 0)
  3130. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3131. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3132. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3133. print '</tr>' . "\n";
  3134. } // foreach ($sum_correct_student as $student)
  3135. print "</table>\n";
  3136. print "<br/><br/>\n";
  3137. $var = 0;
  3138. $cv = 0;
  3139. $dv = 0;
  3140. $avg = 0;
  3141. if ($sum_correct_student) {
  3142. $avg = $sum_correct / $sum_student;
  3143. if ($avg > 0) {
  3144. foreach ($sum_correct_student as $student)
  3145. $var += pow($student->sum - $avg, 2);
  3146. $var = $var / $sum_student;
  3147. $dv = sqrt($var);
  3148. $cv = ($dv / $avg) * 100;
  3149. }
  3150. }
  3151. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3152. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3153. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3154. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3155. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3156. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3157. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3158. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3159. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3160. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3161. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3162. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3163. print "</table>\n";
  3164. } // if ($this->action != 'printstats')
  3165. die();
  3166. }
  3167. /// Display graphics of performance for students
  3168. function stats_students () {
  3169. global $USER, $CFG, $DB, $OUTPUT;
  3170. $id = $this->cm->id;
  3171. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3172. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3173. $title = get_string('results', 'iassign');
  3174. $sum_correct = 0;
  3175. $sum_incorrect = 0;
  3176. $sum_post = 0;
  3177. $sum_nopost = 0;
  3178. $sum_iassign = count($iassign_statement_list);
  3179. $bar_nopost = "";
  3180. $bar_correct = "";
  3181. $bar_incorrect = "";
  3182. $bar_post = "";
  3183. $text_nopost = "";
  3184. $text_correct = "";
  3185. $text_incorrect = "";
  3186. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3187. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3188. if ($iassign_submission) {
  3189. if ($iassign_submission->status == 3)
  3190. $sum_correct ++;
  3191. elseif ($iassign_submission->status == 2)
  3192. $sum_incorrect ++;
  3193. elseif ($iassign_submission->status == 1)
  3194. $sum_post ++;
  3195. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3196. $sum_nopost ++;
  3197. } // if ($iassign_submission)
  3198. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3199. if ($sum_iassign > 0) {
  3200. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3201. $text_correct = number_format($percent_correct, 1) . '%';
  3202. }
  3203. if ($sum_correct > 0) {
  3204. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3205. $bar_correct .= iassign_icons::insert('hbar_green');
  3206. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3207. } // if ($sum_correct > 0)
  3208. if ($sum_iassign > 0) {
  3209. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3210. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3211. }
  3212. if ($sum_incorrect > 0) {
  3213. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3214. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3215. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3216. } // if ($sum_incorrect > 0)
  3217. if ($sum_iassign > 0) {
  3218. $percent_post = ($sum_post / $sum_iassign) * 100;
  3219. $text_post = number_format($percent_post, 1) . '%';
  3220. }
  3221. if ($sum_post > 0) {
  3222. for ($i = 1; $i < $percent_post * 2; $i ++)
  3223. $bar_post .= iassign_icons::insert('hbar_blue');
  3224. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3225. } // if ($sum_post > 0)
  3226. if ($sum_iassign > 0) {
  3227. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3228. $text_nopost = number_format($percent_nopost, 1) . '%';
  3229. }
  3230. if ($sum_nopost > 0) {
  3231. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3232. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3233. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3234. } // if ($sum_nopost > 0)
  3235. print $OUTPUT->header();
  3236. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3237. print '<table width=100%><tr>';
  3238. print '<td align="right">' . $link_return . '</td>' . "\n";
  3239. print '</td></tr></table>' . "\n";
  3240. print "<br/><br/>\n";
  3241. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3242. print '<tr><th colspan=3 class="header c1">' . "\n";
  3243. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3244. // $imagetext = '');
  3245. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3246. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3247. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3248. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3249. print '</tr>' . "\n";
  3250. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3251. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3252. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3253. print '</tr>' . "\n";
  3254. if ($sum_post) {
  3255. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3256. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3257. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3258. print '</tr>' . "\n";
  3259. } // if ($sum_post)
  3260. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3261. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3262. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3263. print '</tr>' . "\n";
  3264. print "</table>";
  3265. print "<br><br>";
  3266. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3267. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3268. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3269. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3270. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3271. $sum_grade = 0;
  3272. $sum_grade_student = 0;
  3273. $avg = 0;
  3274. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3275. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3276. if (!$iassign_submission) {
  3277. $iassign_submission = new stdClass();
  3278. $iassign_submission->grade = 0;
  3279. }
  3280. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3281. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3282. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3283. print '</tr>' . "\n";
  3284. $sum_grade += $iassign_statement_activity_item->grade;
  3285. $sum_grade_student += $iassign_submission->grade;
  3286. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3287. if ($sum_grade > 0)
  3288. $avg = $sum_grade_student / $sum_grade * 100;
  3289. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3290. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3291. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3292. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3293. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3294. print "</table>";
  3295. print $OUTPUT->footer();
  3296. die();
  3297. } // function stats_students()
  3298. /// Display page of iAssign's activity
  3299. function view_iassigns () {
  3300. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3301. $id = $this->cm->id;
  3302. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3303. $notice = optional_param('notice', '', PARAM_TEXT);
  3304. if (strpos($notice, 'error'))
  3305. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3306. else if ($notice != '')
  3307. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3308. print $OUTPUT->box_start();
  3309. print '<table width=100% border=0><tr>' . "\n";
  3310. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3311. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3312. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3313. $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>";
  3314. $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>";
  3315. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3316. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3317. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3318. // Has capability to see "report": teacher or up
  3319. print '<td width=10% align="left">' . "\n";
  3320. print $link_help;
  3321. print '</td>' . "\n";
  3322. print '<td width=10% align="left">' . "\n";
  3323. print $link_report;
  3324. print '</td>' . "\n";
  3325. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3326. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3327. print '<td width=15% align="left">' . "\n";
  3328. print $link_add;
  3329. print "</td>\n";
  3330. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3331. //print '</tr></table>' . "\n";
  3332. print '<div style="float: right;">';
  3333. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3334. if ($iassign_list) {
  3335. print '<td align="right">' . "\n";
  3336. // $USER->iassignEdit == 0 view 'Turn editing off'
  3337. // $USER->iassignEdit == 1 view 'Turn editing on'
  3338. if (!isset($USER->iassignEdit))
  3339. $USER->iassignEdit = 0;
  3340. if ($USER->iassignEdit == 0) {
  3341. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3342. $botton = 1;
  3343. } // if ($USER->iassignEdit == 0)
  3344. elseif ($USER->iassignEdit == 1) {
  3345. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3346. $botton = 0;
  3347. } // elseif ($USER->iassignEdit == 1)
  3348. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3349. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3350. print " <input type=submit value='$bottonEdit_message'/>\n";
  3351. print "</form>\n";
  3352. print "</td>\n";
  3353. } // if ($iassign_list)
  3354. }
  3355. print '</tr></table>' . "\n";
  3356. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3357. // $this->view_legend_icons();
  3358. print $OUTPUT->box_end();
  3359. $iassign_array_exercise = array();
  3360. $i_exercise = 0;
  3361. $iassign_array_test = array();
  3362. $i_test = 0;
  3363. $iassign_array_example = array();
  3364. $i_example = 0;
  3365. $iassign_array_general = array();
  3366. $i_general = 0;
  3367. if ($iassign_list) {
  3368. if ($this->iassign->activity_group == 0) {
  3369. foreach ($iassign_list as $iassign) {
  3370. $iassign_array_general[$i_general] = $iassign;
  3371. $i_general ++;
  3372. }
  3373. } // if ($this->iassign->activity_group == 0)
  3374. else {
  3375. foreach ($iassign_list as $iassign) {
  3376. if ($iassign->type_iassign == 3) {
  3377. $iassign_array_exercise[$i_exercise] = $iassign;
  3378. $i_exercise ++;
  3379. } // if ($iassign->type_iassign == 3)
  3380. if ($iassign->type_iassign == 2) {
  3381. $iassign_array_test[$i_test] = $iassign;
  3382. $i_test ++;
  3383. } // if ($iassign->type_iassign == 2)
  3384. if ($iassign->type_iassign == 1) {
  3385. $iassign_array_example[$i_example] = $iassign;
  3386. $i_example ++;
  3387. } // if ($iassign->type_iassign == 1)
  3388. }
  3389. }
  3390. if ($iassign_array_exercise) {
  3391. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3392. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3393. }
  3394. if ($iassign_array_test) {
  3395. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3396. $this->show_iassign($title, $iassign_array_test, $i_test);
  3397. }
  3398. if ($iassign_array_example) {
  3399. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3400. $this->show_iassign($title, $iassign_array_example, $i_example);
  3401. }
  3402. if ($iassign_array_general) {
  3403. $title = "";
  3404. $this->show_iassign($title, $iassign_array_general, $i_general);
  3405. }
  3406. } else { // if ($iassign_list)
  3407. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3408. }
  3409. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3410. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3411. print $OUTPUT->box_start();
  3412. print '<table width=100% border=0><tr>' . "\n";
  3413. print '<td width=10% align="left">' . "\n";
  3414. print $link_report;
  3415. print '</td>' . "\n";
  3416. print '</tr></table>' . "\n";
  3417. print $OUTPUT->box_end();
  3418. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3419. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3420. print $OUTPUT->box_start();
  3421. print '<table width=100% border=0><tr>' . "\n";
  3422. print '<td align="left">' . "\n";
  3423. print $link_add;
  3424. print '</td>' . "\n";
  3425. print '</tr></table>' . "\n";
  3426. print $OUTPUT->box_end();
  3427. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3428. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3429. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3430. $this->view_legend_icons();
  3431. } // function view_iassigns()
  3432. /// Display all iAssigns
  3433. function show_iassign ($title, $iassign_array, $i) {
  3434. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3435. $id = $this->cm->id;
  3436. print $OUTPUT->box_start();
  3437. print " <script type='text/javascript'>
  3438. //<![CDATA[
  3439. function validate_move () {
  3440. var radios = document.getElementsByName('iassign_destiny');
  3441. var formValid = false;
  3442. //alert('aqui validate_move()');
  3443. var i = 0;
  3444. while (!formValid && i < radios.length) {
  3445. if (radios[i].checked) formValid = true;
  3446. i++;
  3447. }
  3448. if (!formValid) {
  3449. document.getElementById('move_dest').classList.add('alert-danger');
  3450. }
  3451. return formValid;
  3452. }
  3453. var modal;
  3454. function load_move(id_ias) {
  3455. document.form_move_activity.iassign_current.value = id_ias;
  3456. modal.style.display = 'block';
  3457. var radios = document.getElementsByName('iassign_destiny');
  3458. var i = 0;
  3459. while (i < radios.length) {
  3460. radios[i].checked = false;
  3461. i++;
  3462. }
  3463. document.getElementById('move_dest').classList.remove('alert-danger');
  3464. }
  3465. function load_modal_elements() {
  3466. modal = document.getElementById('myModal');
  3467. var span = document.getElementById('close_modal');
  3468. span.onclick = function() {
  3469. modal.style.display = 'none';
  3470. }
  3471. window.onclick = function(event) {
  3472. if (event.target == modal) {
  3473. modal.style.display = 'none';
  3474. }
  3475. }
  3476. }
  3477. window.onload = load_modal_elements;
  3478. //]]>
  3479. </script>\n";
  3480. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3481. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3482. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3483. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3484. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3485. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3486. <input type='hidden' name='iassign_current' value='' />";
  3487. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3488. $section = $course_sections[0];
  3489. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3490. for ($k = 0; $k < count($ids_sections); $k++) {
  3491. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3492. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3493. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3494. if ($c_cm) {
  3495. if ($ccm->instance == $c_cm->instance) {
  3496. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3497. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3498. }
  3499. else {
  3500. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3501. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3502. }
  3503. }
  3504. }
  3505. $radio_buttons .= "</ul>";
  3506. }
  3507. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3508. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3509. </form>
  3510. </div></div> </div></div>\n";
  3511. print " <style>.modal {
  3512. display: none;
  3513. position: fixed;
  3514. z-index: 1;
  3515. left: 0;
  3516. top: 0;
  3517. width: 100%;
  3518. height: 100%;
  3519. overflow: scroll;
  3520. background-color: rgb(0,0,0);
  3521. background-color: rgba(0,0,0,0.4);
  3522. }
  3523. .modal-content {
  3524. background-color: #fefefe;
  3525. margin: 15% auto;
  3526. padding: 10px 10px;
  3527. border: 1px solid #888;
  3528. width: 50%;
  3529. }
  3530. #close_modal {
  3531. color: #aaa;
  3532. float: right;
  3533. font-size: 28px;
  3534. font-weight: bold;
  3535. margin-top: -15px;
  3536. margin-right: -3px;
  3537. }
  3538. #close_modal:hover,
  3539. #close_modal:focus {
  3540. color: black;
  3541. text-decoration: none;
  3542. cursor: pointer;
  3543. }
  3544. #modal_title {
  3545. min-height: 3rem;
  3546. color: initial;
  3547. background: initial;
  3548. font-size: 1.5rem;
  3549. line-height: 1.5;
  3550. padding: 15px;
  3551. border-bottom: 1px solid #e5e5e5;
  3552. }
  3553. .input_move {
  3554. width: 90%;
  3555. padding: 2px;
  3556. }
  3557. .input_move:hover {
  3558. background: #eff0ef;
  3559. }
  3560. </style>";
  3561. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3562. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3563. for ($j = 0; $j < $i; $j ++) {
  3564. $iassign_current = $iassign_array[$j]->id;
  3565. // receiver=1 - message to teacher
  3566. // receiver=2 - message to student
  3567. $sum_comment = 0;
  3568. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3569. foreach ($iassign_submissions as $iassign_submission) {
  3570. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3571. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3572. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3573. if ($verify_message)
  3574. foreach ($verify_message as $tmp)
  3575. $sum_comment += $tmp;
  3576. } // foreach ($iassign_submissions as $iassign_submission)
  3577. if ($sum_comment == 0)
  3578. $comment_unread = "";
  3579. else {
  3580. $comment_unread_message = get_string('comment_unread', 'iassign');
  3581. if ($sum_comment == 1)
  3582. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3583. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3584. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3585. }
  3586. if ($j == $i - 1)
  3587. $iassign_down = $iassign_array[$j]->id;
  3588. else
  3589. $iassign_down = $iassign_array[$j + 1]->id;
  3590. if ($j > 0)
  3591. $iassign_up = $iassign_array[$j - 1]->id;
  3592. else
  3593. $iassign_up = $iassign_array[$j]->id;
  3594. if ($iassign_array[$j]->visible == 0)
  3595. $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>";
  3596. else
  3597. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3598. $links .= $comment_unread;
  3599. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3600. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3601. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3602. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3603. if ($j==0) // first activity
  3604. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3605. else
  3606. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3607. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3608. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3609. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3610. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3611. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3612. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3613. if (count($iassign_array) > 1) {
  3614. if ($j == 0)
  3615. $links .= $link_down;
  3616. elseif ($j == $i - 1)
  3617. $links .= $link_up;
  3618. else
  3619. $links .= $link_up . $link_down;
  3620. } // if (count($iassign_array) > 1)
  3621. $links .= $link_edit . $link_delete;
  3622. if ($iassign_array[$j]->visible == 0)
  3623. $links .= $link_visible_show;
  3624. else
  3625. $links .= $link_visible_hide;
  3626. $links .= $link_duplicate_activity . $link_move_activity;
  3627. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3628. print '<p>' . $links . '</p>' . "\n";
  3629. }
  3630. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3631. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3632. print '<table width=100% ><tr>' . "\n";
  3633. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3634. print '</tr></table>' . "\n";
  3635. for ($j = 0; $j < $i; $j ++) {
  3636. $icon_status = "";
  3637. $icon_comment = "";
  3638. if ($iassign_array[$j]->visible == 1) {
  3639. $iassign_current = $iassign_array[$j]->id;
  3640. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3641. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3642. $icon_status = "";
  3643. $icon_comment = "";
  3644. if ($iassign_submission) {
  3645. // receiver=1 - message to teacher
  3646. // receiver=2 - message to student
  3647. // $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");
  3648. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3649. $verify_message = $DB->get_record_sql(
  3650. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3651. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3652. if ($verify_message)
  3653. foreach ($verify_message as $tmp)
  3654. $sum_comment = $tmp;
  3655. if ($sum_comment > 0) {
  3656. $comment_unread_message = get_string('comment_unread', 'iassign');
  3657. if ($sum_comment == 1)
  3658. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3659. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3660. }
  3661. // $icon_comment = iassign_icons::insert('comment_unread');
  3662. if ($iassign_array[$j]->type_iassign == 3) {
  3663. if ($iassign_array[$j]->show_answer == 1) {
  3664. if ($iassign_submission->status == 3)
  3665. $icon_status = iassign_icons::insert('correct');
  3666. elseif ($iassign_submission->status == 2)
  3667. $icon_status = iassign_icons::insert('incorrect');
  3668. elseif ($iassign_submission->status == 1)
  3669. $icon_status = iassign_icons::insert('post');
  3670. elseif ($iassign_submission->status == 0)
  3671. $icon_status = iassign_icons::insert('not_post');
  3672. } // if ($iassign_array[$j]->show_answer==1)
  3673. else {
  3674. if ($iassign_submission->status == 0)
  3675. $icon_status = iassign_icons::insert('not_post');
  3676. else
  3677. $icon_status = iassign_icons::insert('post');
  3678. }
  3679. } // if ($iassign_array[$j]->type_iassign == 3)
  3680. } // if ($iassign_submission)
  3681. elseif ($iassign_array[$j]->type_iassign == 3) {
  3682. $icon_status = iassign_icons::insert('not_post');
  3683. } // if ($iassign_array[$j]->type_iassign == 3)
  3684. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3685. } // if ($iassign_array[$j]->visible == 1)
  3686. } // for ($j = 0; $j < $i; $j++)
  3687. } else if (isguestuser()) {
  3688. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3689. print '<table width=100% ><tr>' . "\n";
  3690. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3691. print '</tr></table>' . "\n";
  3692. for ($j = 0; $j < $i; $j ++) {
  3693. $icon_status = "";
  3694. $icon_comment = "";
  3695. if ($iassign_array[$j]->visible == 1) {
  3696. $iassign_current = $iassign_array[$j]->id;
  3697. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3698. print '<p>' . $links . '</p>' . "\n";
  3699. } // if ($iassign_array[$j]->visible == 1)
  3700. }
  3701. }
  3702. print $OUTPUT->box_end();
  3703. } // function show_iassign($title, $iassign_array, $i)
  3704. /// Show message of return
  3705. function return_home_course ($message) {
  3706. //D global $DB, $OUTPUT;
  3707. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3708. //D echo $OUTPUT->box_start();
  3709. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3710. //D echo '<tr><td align="left"><strong>' . "\n";
  3711. //D print_string($message, 'iassign');
  3712. //D echo '</strong></td>' . "\n";
  3713. //D echo '<td width=20% align="right">' . "\n";
  3714. //D echo $link_return;
  3715. //D echo '</td></tr></table>' . "\n";
  3716. //D echo $OUTPUT->box_end();
  3717. //D // echo $OUTPUT->footer();
  3718. redirect(new moodle_url($this->return . '&notice=' . $message));
  3719. exit;
  3720. }
  3721. /// Search comment of activity
  3722. function search_comment_submission ($iassign_submissionid) {
  3723. global $USER, $DB, $OUTPUT, $COURSE;
  3724. // $context = context_course::instance($COURSE->id);
  3725. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3726. $colorEdit2 = "#d2e5fc";
  3727. $has_capability = 0;
  3728. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3729. $text = "";
  3730. if ($comments) {
  3731. $even = 1;
  3732. foreach ($comments as $tmp) {
  3733. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3734. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3735. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3736. // $text .= $tmp->comment . "</td></tr>";
  3737. //} else {
  3738. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3739. $avatar = new user_picture($user_data);
  3740. $avatar->courseid = $COURSE->id;
  3741. $avatar->link = true;
  3742. $user_picture = $OUTPUT->render($avatar);
  3743. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3744. if ($even) {
  3745. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit1 . "'>$user_picture</td><td bgcolor='" . $colorEdit1 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3746. $even = 0;
  3747. } else {
  3748. $text .= "<tr><td style='vertical-align: middle; width: 55px !important;' bgcolor='" . $colorEdit2 . "'>$user_picture</td><td bgcolor='" . $colorEdit2 . "' style='padding-left: 0px !important;'><b style='font-size: 1.1rem;'>" . $user_data->firstname . "</b>&nbsp;<span style='color: #686969; font-size: 90%'><i class='fa fa-clock-o' aria-hidden='true' style='margin-left: 2rem; margin-right: .1rem;'></i> " . userdate($tmp->timecreated) . "</span></br>\n";
  3749. $even = 1;
  3750. }
  3751. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3752. } // foreach ($comments as $tmp)
  3753. }
  3754. return $text;
  3755. }
  3756. /// Update comment of activity
  3757. function update_comment ($iassign_submissionid) {
  3758. global $USER, $DB, $OUTPUT;
  3759. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3760. $receiver = 1; // student message to teacher
  3761. else
  3762. $receiver = 2; // teacher message to student
  3763. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3764. if ($verify_message) {
  3765. foreach ($verify_message as $message) {
  3766. if ($message->receiver == $receiver) {
  3767. $newentry = new stdClass();
  3768. $newentry->id = $message->id;
  3769. $newentry->return_status = 1;
  3770. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3771. print_error('error_update', 'iassign');
  3772. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3773. } // if ($message->receiver == $receiver)
  3774. // Trigger module viewed event.
  3775. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3776. 'objectid' => $this->iassign->id,
  3777. 'context' => $this->context
  3778. ));
  3779. $event->add_record_snapshot('course', $this->course);
  3780. $event->trigger();
  3781. } // foreach ($verify_message as $message)
  3782. }
  3783. }
  3784. /// Record comment of activity
  3785. function write_comment_submission () {
  3786. global $USER, $CFG, $DB;
  3787. $id = $this->cm->id;
  3788. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3789. $row = optional_param('row', 0, PARAM_INT);
  3790. $column = optional_param('column', 0, PARAM_INT);
  3791. $sum_comment = 0;
  3792. $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);
  3793. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3794. $str1 = trim($submission_comment);
  3795. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3796. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3797. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3798. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3799. $receiver = 1; // student message to teacher
  3800. $this->action = 'view';
  3801. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3802. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3803. } else {
  3804. $receiver = 2; // teacher message to student
  3805. $this->action = 'viewsubmission';
  3806. //D $tousers = array(); //MOOC 2016
  3807. //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
  3808. }
  3809. //MOOC 2016: foi p/ 15 linhas acima:
  3810. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3811. // verificar se existe uma submissão para o exercício e aluno informados
  3812. if (!$iassign_submission) {
  3813. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3814. }
  3815. if (!$iassign_submission) {
  3816. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3817. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3818. $this->iassign_submission_current = $id_submission;
  3819. } else {
  3820. $id_submission = $iassign_submission->id;
  3821. } // if (!$iassign_submission)
  3822. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3823. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3824. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3825. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3826. $comments = $DB->get_record_sql(
  3827. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3828. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3829. if ($comments)
  3830. foreach ($comments as $tmp)
  3831. $sum_comment = $tmp;
  3832. if ($sum_comment == 0) {
  3833. $newentry = new stdClass();
  3834. $newentry->iassign_submissionid = $id_submission;
  3835. $newentry->comment_authorid = $USER->id;
  3836. $newentry->timecreated = time();
  3837. $newentry->comment = $submission_comment;
  3838. $newentry->receiver = $receiver;
  3839. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3840. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3841. //T $eventdata = new stdClass();
  3842. //T $eventdata->component = 'mod_iassign'; //your component name
  3843. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3844. //T $eventdata->userfrom = $USER;
  3845. //T $eventdata->userto = $touser;
  3846. //T $eventdata->subject = "Teste de Subject";
  3847. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3848. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3849. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3850. //T $eventdata->smallmessage = "Teste de Mensagem";
  3851. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3852. //T // alteracao tulio faria
  3853. //T //message_send($eventdata);
  3854. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3855. // Trigger module viewed event.
  3856. $event = \mod_iassign\event\submission_comment_created::create(array(
  3857. 'objectid' => $this->iassign->id,
  3858. 'context' => $this->context
  3859. ));
  3860. $event->add_record_snapshot('course', $this->course);
  3861. $event->trigger();
  3862. }
  3863. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3864. // if ($this->action=='viewsubmission') {
  3865. // echo $OUTPUT->header();
  3866. // $this->return_last('confirm_add_comment', $link_return);
  3867. // die;
  3868. // }
  3869. return true;
  3870. } // function write_comment_submission()
  3871. /// Writes a new submission
  3872. // The first student answer is under 'function get_answer()'
  3873. function new_submission ($iassignid, $id_user, $receiver) {
  3874. global $USER, $DB, $OUTPUT;
  3875. $newentry = new stdClass();
  3876. $newentry->iassign_statementid = $iassignid;
  3877. $newentry->userid = $id_user;
  3878. $newentry->timecreated = time();
  3879. $newentry->timemodified = time();
  3880. $newentry->answer = 0; // student only submit message
  3881. if ($receiver == 2) // teacher message to student (write id teacher)
  3882. $newentry->teacher = $USER->id;
  3883. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3884. return_home_course('error_insert_submissions');
  3885. else {
  3886. // Trigger module view event
  3887. $event = \mod_iassign\event\submission_created::create(array(
  3888. 'objectid' => $this->iassign->id,
  3889. 'context' => $this->context
  3890. ));
  3891. $event->add_record_snapshot('course', $this->course);
  3892. $event->trigger();
  3893. }
  3894. return $newentry->id;
  3895. }
  3896. /// Return to a specific address of page
  3897. function return_last ($message, $link_return) {
  3898. global $DB, $OUTPUT;
  3899. print $OUTPUT->box_start();
  3900. print '<table width=100% border=0 valign="top">' . "\n";
  3901. print '<tr><td align="left"><strong>' . "\n";
  3902. print_string($message, 'iassign');
  3903. print '</strong></td>' . "\n";
  3904. print '<td width=20% align="right">' . "\n";
  3905. print $link_return;
  3906. print '</td></tr></table>' . "\n";
  3907. print $OUTPUT->box_end();
  3908. print $OUTPUT->footer();
  3909. die();
  3910. } // function return_last($message, $link_return)
  3911. } // class iassign
  3912. /// Class for manage activities
  3913. class activity {
  3914. var $activity;
  3915. /// Constructor of class.
  3916. // @param int $id Id of activity
  3917. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3918. //D public function activity($id) { self::__construct($id); }
  3919. function __construct ($id) {
  3920. global $DB;
  3921. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3922. if (empty($this->activity))
  3923. $this->activity = null;
  3924. }
  3925. /// Get an activity
  3926. // @return NULL
  3927. function get_activity () {
  3928. if ($this->activity != null)
  3929. return $this->activity;
  3930. else
  3931. return null;
  3932. }
  3933. /// Delete interactive activities
  3934. function delete ($return) {
  3935. global $USER, $CFG, $DB, $OUTPUT;
  3936. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3937. $output = $OUTPUT->header();
  3938. $output .= $OUTPUT->box_start();
  3939. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3940. if ($iassign_submission_currents) {
  3941. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3942. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3943. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3944. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3945. $output .= $OUTPUT->box_end();
  3946. $output .= $OUTPUT->footer();
  3947. print $output;
  3948. die();
  3949. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3950. } // if ($iassign_submission_currents)
  3951. else
  3952. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3953. $output .= '<table width=50% border=0>';
  3954. $output .= '<tr valign="top"><td>';
  3955. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3956. $output .= '</td><td>';
  3957. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3958. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3959. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3960. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3961. $output .= "</form>\n";
  3962. $output .= '</td><td>';
  3963. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3964. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3965. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3966. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3967. $output .= "</form>\n";
  3968. $output .= '</td></tr></table>' . "\n";
  3969. $output .= $OUTPUT->box_end();
  3970. $output .= $OUTPUT->footer();
  3971. print $output;
  3972. } // function delete($return)
  3973. /// Function for confirm the delete of activity
  3974. // @param String $return Url of return
  3975. // @param Object $iassign Object content an activity
  3976. function deleteyes ($return, $iassign) {
  3977. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3978. $msg = '';
  3979. if (!empty($this->activity->id)) {
  3980. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3981. if ($iassign_submission_currents) {
  3982. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3983. foreach ($iassign_submission_currents as $iassign_submission)
  3984. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3985. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3986. } // if ($iassign_submission_currents)
  3987. }
  3988. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3989. // Remove all files associated to this activity:
  3990. $fs = get_file_storage();
  3991. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3992. $this->delete_calendar($this->activity->id);
  3993. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3994. iassign::update_grade_iassign($this->activity->iassignid);
  3995. if ($delete_iassign_current) {
  3996. $iassign->return_home_course('confirm_delete_iassign');
  3997. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3998. } else {
  3999. $iassign->return_home_course('error_confirm_delete_iassign');
  4000. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  4001. }
  4002. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  4003. }
  4004. }
  4005. /// Changes position of activities (between those inside a group of interactive activities)
  4006. // @param $move_action = must be "up" or "down"
  4007. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4008. function move_iassign ($move_action, $target, $return) {
  4009. global $DB, $OUTPUT;
  4010. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4011. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4012. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4013. if ($move_action=="firstdown") {
  4014. $final_position_source = 2;
  4015. $final_position_target = 1;
  4016. }
  4017. else
  4018. if ($move_action=="down") {
  4019. $final_position_target = $this->activity->position;
  4020. $final_position_source = $final_position_target + 1;
  4021. }
  4022. else
  4023. if ($move_action=="up") {
  4024. $final_position_target = $this->activity->position;
  4025. $final_position_source = $final_position_target - 1;
  4026. }
  4027. else { // error:
  4028. print_error('error_update_move_iassign', 'iassign');
  4029. exit;
  4030. }
  4031. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4032. $newentry->id = $this->activity->id; // ID of the "source activity"
  4033. $newentry->position = $final_position_source;
  4034. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4035. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4036. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4037. print_error('error_update_move_iassign', 'iassign');
  4038. }
  4039. else { // first update performed successfully
  4040. $newentry->id = $iassign_target->id;
  4041. $newentry->position = $final_position_target;
  4042. if (!$DB->update_record('iassign_statement', $newentry))
  4043. print_error('error_update_move_iassign', 'iassign');
  4044. }
  4045. redirect($return);
  4046. }
  4047. /// Enable or disable the display of interactive activities
  4048. function visible_iassign ($return) {
  4049. global $DB;
  4050. $newentry = new stdClass();
  4051. $newentry->id = $this->activity->id;
  4052. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4053. if (!$DB->update_record('iassign_statement', $newentry))
  4054. print_error('error_update_visible_iassign', 'iassign');
  4055. redirect($return);
  4056. }
  4057. /// Add news interactive activities (register in table 'iassign_statement')
  4058. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4059. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4060. function new_iassign ($param) {
  4061. global $DB;
  4062. $newentry = new stdClass();
  4063. $newentry->iassignid = $param->iassignid;
  4064. $newentry->name = $param->name;
  4065. $newentry->type_iassign = $param->type_iassign;
  4066. $newentry->store_all_submissions = $param->store_all_submissions;
  4067. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4068. $proposition = $param->proposition;
  4069. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4070. else $proposition_text = $proposition;
  4071. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4072. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4073. //TODO Then get it directly from the form data $_POST!
  4074. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4075. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4076. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4077. $newentry->author_name = $param->author_name;
  4078. $newentry->author_modified_name = $param->author_modified_name;
  4079. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4080. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4081. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4082. $newentry->grade = $param->grade;
  4083. $newentry->timemodified = time();
  4084. $newentry->timecreated = time();
  4085. if ($param->type_iassign == 1) {
  4086. $newentry->timedue = 0;
  4087. $newentry->timeavailable = 0;
  4088. } // if ($param->type_iassign == 1)
  4089. else {
  4090. $newentry->timedue = $param->timedue;
  4091. $newentry->timeavailable = $param->timeavailable;
  4092. }
  4093. $newentry->preventlate = $param->preventlate;
  4094. $newentry->test = $param->test;
  4095. $newentry->special_param1 = $param->special_param1;
  4096. $newentry->visible = $param->visible;
  4097. $newentry->position = $param->position;
  4098. $newentry->max_experiment = $param->max_experiment;
  4099. $newentry->dependency = $param->dependency;
  4100. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4101. $newentry->show_answer = $param->show_answer;
  4102. $id = $DB->insert_record("iassign_statement", $newentry);
  4103. if ($id) {
  4104. $component = 'mod_iassign';
  4105. $filearea = 'exercise';
  4106. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4107. $file = $fs->get_file_by_id($param->file);
  4108. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4109. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4110. //$itemid = $id;
  4111. // File already inserted in other context!
  4112. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4113. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4114. $updateentry = new stdClass();
  4115. $updateentry->id = $id;
  4116. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4117. $updateentry->file = $newfile->get_itemid();
  4118. if (!$DB->update_record("iassign_statement", $updateentry))
  4119. print_error('error_add', 'iassign');
  4120. if ($param->type_iassign == 3)
  4121. iassign::update_grade_iassign($param->iassignid);
  4122. //TODO iLM_HTML5 :: //MOOC2014
  4123. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4124. //D if ($iassign_ilm_configs) {
  4125. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4126. //D if ($iassign_ilm_config->param_type != 'static') {
  4127. //D $newentry = new stdClass();
  4128. //D $newentry->iassign_statementid = $id;
  4129. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4130. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4131. //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});
  4132. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4133. //D print_error('error_add_param', 'iassign');
  4134. //D }
  4135. //D }
  4136. //D }
  4137. // log event --------------------------------------------------------------------------------------
  4138. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4139. // log event --------------------------------------------------------------------------------------
  4140. return $id;
  4141. }
  4142. else
  4143. print_error('error_add', 'iassign');
  4144. } // function new_iassign($param)
  4145. /// Add the calendar entries for this iassign
  4146. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4147. // @return bool
  4148. static function add_calendar ($iassignid) {
  4149. global $DB, $CFG;
  4150. require_once($CFG->dirroot . '/calendar/lib.php');
  4151. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4152. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4153. $event = new stdClass();
  4154. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4155. $event->description = $iassign_statement_activity_item->name;
  4156. $event->courseid = $iassign->course;
  4157. $event->groupid = 0;
  4158. $event->userid = 0;
  4159. $event->modulename = 'iassign';
  4160. $event->instance = $iassign->id;
  4161. $event->eventtype = 'due';
  4162. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4163. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4164. calendar_event::create($event);
  4165. }
  4166. /// Update the calendar entries for this iassign
  4167. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4168. // @return bool
  4169. function update_calendar ($iassignid, $olddescription) {
  4170. global $DB, $CFG;
  4171. require_once($CFG->dirroot . '/calendar/lib.php');
  4172. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4173. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4174. $event = new stdClass();
  4175. $event->id = 0;
  4176. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4177. if ($events) {
  4178. foreach ($events as $value) {
  4179. if ($value->description == $olddescription) {
  4180. $event->id = $value->id;
  4181. }
  4182. }
  4183. }
  4184. if ($event->id != 0) {
  4185. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4186. $event->description = $iassign_statement_activity_item->name;
  4187. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4188. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4189. $calendarevent = calendar_event::load($event->id);
  4190. $calendarevent->update($event);
  4191. } else
  4192. $this->add_calendar($iassignid);
  4193. }
  4194. /// Update the calendar entries for this iassign
  4195. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4196. // @return bool
  4197. function delete_calendar ($iassignid) {
  4198. global $DB, $CFG;
  4199. require_once($CFG->dirroot . '/calendar/lib.php');
  4200. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4201. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4202. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4203. if ($events) {
  4204. foreach ($events as $value) {
  4205. if ($value->description == $iassign_statement_activity_item->name) {
  4206. $DB->delete_records('event', array('id' => $value->id));
  4207. }
  4208. }
  4209. }
  4210. }
  4211. /// Update interactive activities
  4212. function update_iassign ($param) {
  4213. global $DB;
  4214. $component = 'mod_iassign';
  4215. $filearea = 'exercise';
  4216. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4217. $file = $fs->get_file_by_id($param->file);
  4218. $fileold = $fs->get_file_by_id($param->fileold);
  4219. if ($param->file != $param->fileold) {
  4220. if ($fileold) {
  4221. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4222. foreach ($fileoldarea as $value) {
  4223. $value->delete();
  4224. }
  4225. }
  4226. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4227. $itemid = $file->get_itemid() + $param->iassign_id;
  4228. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4229. $param->file = $newfile->get_itemid();
  4230. } else
  4231. $param->file = $file->get_itemid();
  4232. } else {
  4233. $param->file = $file->get_itemid();
  4234. }
  4235. $newentry = new stdClass();
  4236. $newentry->id = $param->iassign_id;
  4237. $newentry->name = $param->name;
  4238. $newentry->type_iassign = $param->type_iassign;
  4239. $newentry->store_all_submissions = $param->store_all_submissions;
  4240. //2019 $newentry->proposition = $param->proposition;
  4241. $proposition = $param->proposition;
  4242. if (is_array($proposition))
  4243. $proposition_text = $proposition['text'];
  4244. else
  4245. $proposition_text = $proposition;
  4246. $newentry->proposition = $proposition_text;
  4247. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4248. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4249. $newentry->grade = $param->grade;
  4250. $newentry->author_modified_name = $param->author_modified_name;
  4251. $newentry->timemodified = time();
  4252. if ($param->type_iassign == 1) {
  4253. $newentry->timedue = 0;
  4254. $newentry->timeavailable = 0;
  4255. } // if ($param->type_iassign == 1)
  4256. else {
  4257. $newentry->timedue = $param->timedue;
  4258. $newentry->timeavailable = $param->timeavailable;
  4259. }
  4260. $newentry->preventlate = $param->preventlate;
  4261. $newentry->test = $param->test;
  4262. $newentry->special_param1 = $param->special_param1;
  4263. $newentry->visible = $param->visible;
  4264. $newentry->max_experiment = $param->max_experiment;
  4265. $newentry->dependency = $param->dependency;
  4266. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4267. $newentry->show_answer = $param->show_answer;
  4268. if (!$DB->update_record("iassign_statement", $newentry))
  4269. print_error('error_update', 'iassign');
  4270. if ($param->type_iassign == 3) {
  4271. iassign::update_grade_iassign($param->iassignid);
  4272. }
  4273. //$id = $newentry->id; // MOOC 2016 --- inicio
  4274. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4275. //if ($iassign_activity_item_configs) {
  4276. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4277. // $newentry = new stdClass();
  4278. // $newentry->id = $iassign_activity_item_config->id;
  4279. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4280. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4281. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4282. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4283. // print_error('error_edit_param', 'iassign');
  4284. // }
  4285. // } // MOOC 2016 --- final
  4286. // log event --------------------------------------------------------------------------------------
  4287. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4288. // log event --------------------------------------------------------------------------------------
  4289. return $newentry->id;
  4290. // if ($param->type_iassign==3)
  4291. // $this->update_grade_iassign($param->iassignid);
  4292. } // function update_iassign($param)
  4293. /// Show information of activity
  4294. function show_info_iassign () {
  4295. global $DB, $OUTPUT;
  4296. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4297. if ($this->activity->type_iassign == 3) {
  4298. if ($this->activity->dependency == 0) {
  4299. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4300. } else {
  4301. $dependencys = explode(';', $this->activity->dependency);
  4302. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4303. foreach ($dependencys as $dependency) {
  4304. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4305. if ($dependencyiassign)
  4306. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4307. } // foreach ($dependencys as $dependency)
  4308. } // if ($iassign_statement_activity_item->dependency == 0)
  4309. if ($this->activity->max_experiment == 0)
  4310. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4311. else
  4312. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4313. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4314. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4315. print $OUTPUT->box($output);
  4316. } // function show_info_iassign()
  4317. /// Shows date of opening and closing activities
  4318. function view_dates () {
  4319. global $USER, $CFG, $DB, $OUTPUT;
  4320. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4321. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4322. $status_iassign = "";
  4323. $status_iassign1 = "";
  4324. $status_iassign2 = "";
  4325. if ($this->activity->type_iassign == 1) // activity of type example
  4326. $type_iassign = get_string('example_iassign', 'iassign');
  4327. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4328. $type_iassign = get_string('test_iassign', 'iassign');
  4329. if ($this->activity->timeavailable > time()) {
  4330. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4331. } elseif ($this->activity->timedue < time()) {
  4332. $status_iassign = get_string('last_timedue', 'iassign');
  4333. }
  4334. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4335. $type_iassign = get_string('exercise_iassign', 'iassign');
  4336. if ($this->activity->timeavailable > time()) {
  4337. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4338. } elseif ($this->activity->timedue < time()) { // after delivery
  4339. $status_iassign = get_string('last_timedue', 'iassign');
  4340. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4341. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4342. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4343. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4344. if ($this->activity->test == 1) // allowed to test after of deadline
  4345. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4346. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4347. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4348. } // elseif ($iassign_statement_activity_item->test == 0)
  4349. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4350. } // elseif ($iassign_statement_activity_item->timedue < time())
  4351. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4352. $output = '<table width=100% >' . "\n";
  4353. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4354. $output .= '<tr>' . "\n";
  4355. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4356. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4357. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4358. // leo $output .= '<td width=80%>' . $type_iassign;
  4359. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4360. // $output .= '</td>' . "\n";
  4361. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4362. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4363. $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>";
  4364. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4365. } else {
  4366. $link_next = "";
  4367. $link_previous = "";
  4368. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4369. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4370. // previous_activity
  4371. if ($iassign_previous) {
  4372. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4373. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4374. } // next_activity
  4375. if ($iassign_next) {
  4376. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4377. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4378. }
  4379. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4380. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4381. $output .= '</tr></table>' . "\n";
  4382. $output .= '<table width=100% >' . "\n";
  4383. if ($this->activity->type_iassign > 1) {
  4384. if ($this->activity->timeavailable)
  4385. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4386. if ($this->activity->timedue)
  4387. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4388. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4389. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4390. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4391. $output .= '</table>' . "\n";
  4392. print $OUTPUT->box($output);
  4393. } // function view_dates()
  4394. } // class activity
  4395. /// Class to manage Interactive Learning Module (iLM)
  4396. class ilm {
  4397. var $ilm;
  4398. /// Constructor of class
  4399. // @param int $id Id of iLM
  4400. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4401. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4402. function __construct ($id) {
  4403. global $DB;
  4404. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4405. if (empty($this->ilm))
  4406. $this->ilm = null;
  4407. }
  4408. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4409. // @calledby view_iassign_current()
  4410. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4411. global $USER, $CFG, $DB;
  4412. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4413. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4414. $typec = strtolower($iassign_ilm->type);
  4415. require_once 'ilm_handlers/' . $typec . '.php';
  4416. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4417. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4418. return $retorno;
  4419. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4420. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4421. // @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);
  4422. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4423. // @param Object $file File in use in activity
  4424. // @return int Return the id of log
  4425. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4426. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4427. $newentry = new stdClass();
  4428. $newentry->iassign_statementid = $iassign_activity_itemid;
  4429. $newentry->userid = $USER->id;
  4430. $newentry->file = $content_or_id_from_ilm_security;
  4431. $newentry->timecreated = time();
  4432. $newentry->view = 1;
  4433. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4434. if (!$id_iLM_security) {
  4435. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4436. } // from (!$DB->insert_record("iassign_security", $newentry))
  4437. return $id_iLM_security;
  4438. }
  4439. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4440. // @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);
  4441. // @param int $userid
  4442. // @param int $iassign_activity_itemid Id of iassign statement
  4443. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4444. global $DB;
  4445. // 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")
  4446. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4447. }
  4448. } // class ilm
  4449. /// Class to manage settings of iLM.
  4450. class ilm_settings {
  4451. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4452. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4453. // @param int $ilm_id Id of iLM
  4454. // @param array $options An array with options for create dynamic tag html APPLET
  4455. // @return string Return with a tag html APPLET created
  4456. static function build_ilm_tags ($ilm_id, $options = array()) {
  4457. global $DB;
  4458. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4459. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4460. $typec = strtolower($iassign_ilm->type);
  4461. require_once 'ilm_handlers/' . $typec . '.php';
  4462. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4463. return $retorno;
  4464. } // static function build_ilm_tags($ilm_id, $options = array())
  4465. /// Function for get modified date of iLM file
  4466. // @param string $file_jar String with Ids of iLM files
  4467. // @return string Return with the filenames and modified date
  4468. static function applet_filetime ($file_jar) {
  4469. $filetime = "";
  4470. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4471. $files_jar = explode(",", $file_jar);
  4472. foreach ($files_jar as $one_file) {
  4473. $file = $fs->get_file_by_id($one_file);
  4474. if ($file)
  4475. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4476. }
  4477. return $filetime;
  4478. }
  4479. /// Function for verify an default applet
  4480. // @param String $file_jar String containing an list de ids of applet files
  4481. // @return boolean Return true or fale if applet is default
  4482. static function applet_default ($file_jar) {
  4483. $is_default = true;
  4484. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4485. $files_jar = explode(",", $file_jar);
  4486. foreach ($files_jar as $one_file) {
  4487. $file = $fs->get_file_by_id($one_file);
  4488. if ($file)
  4489. $is_default &= ($file->get_itemid() == 0);
  4490. }
  4491. return $is_default;
  4492. }
  4493. /// Function for get form variables for add, edit, or copy iLM
  4494. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4495. // @see settings_form.php
  4496. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4497. // @param int $ilm_id Id of iLM
  4498. // @param string $action String with the action
  4499. // @return object Return an object with forms variables
  4500. static function add_edit_copy_ilm ($ilm_id, $action) {
  4501. global $USER, $DB, $CFG;
  4502. require_once('settings_form.php'); // put the form
  4503. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4504. $param = new stdClass();
  4505. $param->action = $action;
  4506. $param->ilm_id = $ilm_id;
  4507. $CFG->action_ilm = $action;
  4508. $CFG->ilm_id = $ilm_id;
  4509. if ($action == 'add') {
  4510. $param->title = get_string('add_ilm', 'iassign');
  4511. $param->name = "";
  4512. $param->version = "";
  4513. $param->url = "";
  4514. $param->description = "";
  4515. $param->extension = "";
  4516. $param->author = $USER->id;
  4517. $param->file_jar = "";
  4518. $param->file_jar_static = "";
  4519. $param->file_class = "";
  4520. $param->width = 800;
  4521. $param->height = 600;
  4522. $param->enable = 0; // 0 - hide / 1 - show
  4523. $param->timecreated = time();
  4524. $param->timemodified = time();
  4525. $param->evaluate = 0;
  4526. $param->parent = 0;
  4527. }
  4528. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4529. if ($iassign_ilm) {
  4530. $description = json_decode($iassign_ilm->description);
  4531. $param->title = get_string('edit_ilm', 'iassign');
  4532. $param->id = $iassign_ilm->id;
  4533. $param->name_ilm = $iassign_ilm->name;
  4534. $param->name = $iassign_ilm->name;
  4535. $param->version = $iassign_ilm->version;
  4536. $param->ilm_type = $iassign_ilm->type;
  4537. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4538. $param->url = $iassign_ilm->url;
  4539. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4540. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4541. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4542. if (!isset($description->{current_language()})) {
  4543. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4544. else
  4545. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4546. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4547. }
  4548. else
  4549. $param->description = $description->{current_language()};
  4550. $param->description_lang = $iassign_ilm->description;
  4551. $param->extension = $iassign_ilm->extension;
  4552. $param->author = $iassign_ilm->author;
  4553. $param->file_jar = $iassign_ilm->file_jar;
  4554. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4555. $param->file_class = $iassign_ilm->file_class;
  4556. $param->width = $iassign_ilm->width;
  4557. $param->height = $iassign_ilm->height;
  4558. $param->enable = $iassign_ilm->enable;
  4559. $param->timecreated = $iassign_ilm->timecreated;
  4560. $param->timemodified = time();
  4561. $param->evaluate = $iassign_ilm->evaluate;
  4562. $param->parent = $iassign_ilm->parent;
  4563. }
  4564. }
  4565. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4566. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4567. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4568. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4569. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4570. // echo "Sem dados<br/>"; exit;
  4571. return;
  4572. }
  4573. $description = json_decode($iassign_ilm->description);
  4574. if ($iassign_ilm) {
  4575. if ($iassign_ilm->parent == 0)
  4576. $iassign_ilm->parent = $ilm_id;
  4577. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4578. $param->title = get_string('new_version_ilm', 'iassign');
  4579. $param->name_ilm = $iassign_ilm->name;
  4580. $param->name = $iassign_ilm->name;
  4581. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4582. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4583. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4584. $param->ilm_type = $iassign_ilm->type;
  4585. $param->url = $iassign_ilm->url;
  4586. $param->description = $description->{current_language()};
  4587. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4588. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4589. $param->extension = $iassign_ilm->extension;
  4590. $param->author = $USER->id;
  4591. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4592. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4593. $param->file_jar_static = '';
  4594. $param->file_class = $iassign_ilm->file_class;
  4595. $param->width = $iassign_ilm->width;
  4596. $param->height = $iassign_ilm->height;
  4597. $param->enable = 0;
  4598. $param->timecreated = time();
  4599. $param->timemodified = time();
  4600. $param->evaluate = $iassign_ilm->evaluate;
  4601. $param->parent = $iassign_ilm->parent;
  4602. }
  4603. }
  4604. elseif ($action == 'copy') {
  4605. $description = json_decode($iassign_ilm->description);
  4606. if ($iassign_ilm) {
  4607. if ($iassign_ilm->parent == 0)
  4608. $iassign_ilm->parent = $ilm_id;
  4609. $param->title = get_string('copy_ilm', 'iassign');
  4610. $param->id = $iassign_ilm->id;
  4611. $param->name_ilm = $iassign_ilm->name;
  4612. $param->name = $iassign_ilm->name;
  4613. $param->version = "";
  4614. $param->ilm_type = $iassign_ilm->type;
  4615. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4616. $param->url = $iassign_ilm->url;
  4617. $param->description = $description->{current_language()};
  4618. $param->description_lang = $iassign_ilm->description;
  4619. $param->extension = $iassign_ilm->extension;
  4620. $param->author = $USER->id;
  4621. $param->file_jar = '';
  4622. $param->file_jar_static = '';
  4623. $param->file_class = $iassign_ilm->file_class;
  4624. $param->width = $iassign_ilm->width;
  4625. $param->height = $iassign_ilm->height;
  4626. $param->enable = 0;
  4627. $param->timecreated = time();
  4628. $param->timemodified = time();
  4629. $param->evaluate = $iassign_ilm->evaluate;
  4630. $param->parent = $iassign_ilm->parent;
  4631. }
  4632. }
  4633. return $param;
  4634. } // static function add_edit_copy_ilm($ilm_id, $action)
  4635. /// Function for save iLM file in moodledata
  4636. // @param int $itemid Itemid of file save in draft (upload file)
  4637. // @param int $ilm_id Id of iLM
  4638. // @return string Return an string with ids of iLM files
  4639. static function new_file_ilm ($itemid, $iassign_ilm) {
  4640. global $CFG, $USER, $DB;
  4641. $return = null;
  4642. $file_jar = array();
  4643. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4644. $contextuser = context_user::instance($USER->id);
  4645. $contextsystem = context_system::instance();
  4646. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4647. if ($files_ilm) {
  4648. foreach ($files_ilm as $value) {
  4649. // CHECK IF file is HTML type
  4650. if ($iassign_ilm->type == 1) {
  4651. // Check if the file extension is ZIP
  4652. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4653. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4654. if ((strtolower($ext) == 'zip')) {
  4655. // Coping...:
  4656. $destination = 'ilm_debug/' . $value->get_filename();
  4657. $value->copy_content_to($destination);
  4658. // Extracting content...:
  4659. $zip = new ZipArchive();
  4660. $extracted = './ilm';
  4661. $dir = "";
  4662. if ($zip->open($destination) === TRUE) {
  4663. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4664. if (is_dir($dir)) {
  4665. $i = 1;
  4666. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4667. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4668. $i ++;
  4669. }
  4670. $name = $previous . "_" . $i;
  4671. $dir = './ilm/' . $name . "/";
  4672. $j = 0;
  4673. while ($item_name = $zip->getNameIndex($j)) {
  4674. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4675. $j++;
  4676. }
  4677. $zip->close();
  4678. }
  4679. $zip->open($destination);
  4680. $zip->extractTo($extracted);
  4681. $zip->close();
  4682. // After the extraction, remove it from DEBUG
  4683. unlink($destination);
  4684. } else { // Error trying to open destination...
  4685. // After the extraction error, also remove it from DEBUG
  4686. unlink($destination);
  4687. print_error('error_add_ilm_zip', 'iassign');
  4688. }
  4689. return $dir;
  4690. }
  4691. } // if ($iassign_ilm->type == 1)
  4692. if ($value->get_filename() != '.') {
  4693. $file_ilm = array(
  4694. 'userid' => $USER->id,
  4695. 'contextid' => $contextsystem->id,
  4696. 'component' => 'mod_iassign',
  4697. 'filearea' => 'ilm',
  4698. 'itemid' => rand(1, 999999999),
  4699. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4700. 'filename' => $value->get_filename());
  4701. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4702. array_push($file_jar, $file_ilm->get_id());
  4703. }
  4704. }
  4705. if (!empty($file_jar)) {
  4706. $return = implode(",", $file_jar);
  4707. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4708. foreach ($old_file_jar as $value) {
  4709. $file = $fs->get_file_by_id($value);
  4710. if ($file)
  4711. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4712. }
  4713. }
  4714. }
  4715. else // if ($files_ilm)
  4716. $return = $iassign_ilm->file_jar;
  4717. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4718. return $return;
  4719. } // static function new_file_ilm($itemid, $iassign_ilm)
  4720. /// Function for save in database an new iLM
  4721. // @param object $param An object with iLM params
  4722. static function new_ilm ($itemid) {
  4723. global $CFG, $USER, $OUTPUT;
  4724. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4725. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4726. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4727. }
  4728. $pathtemp = $CFG->dataroot . '/temp/';
  4729. $contextuser = context_user::instance($USER->id);
  4730. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4731. $zip = new zip_packer();
  4732. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4733. foreach ($files as $file) {
  4734. if (!$file->is_directory())
  4735. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4736. }
  4737. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4738. // Verifica se o pacote possui o XML
  4739. if (!$application_xml) {
  4740. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4741. return;
  4742. } else {
  4743. $missing = "";
  4744. if (!isset($application_xml->name)) {
  4745. $missing .= "name";
  4746. }
  4747. if (!isset($application_xml->version)) {
  4748. $missing .= ", version";
  4749. }
  4750. if (!isset($application_xml->type)) {
  4751. $missing .= ", type";
  4752. }
  4753. if (!isset($application_xml->extension)) {
  4754. $missing .= ", extension";
  4755. }
  4756. if (!isset($application_xml->file_jar)) {
  4757. $missing .= ", file_jar";
  4758. }
  4759. if (!isset($application_xml->file_class)) {
  4760. $missing .= ", file_class";
  4761. }
  4762. if (!isset($application_xml->width)) {
  4763. $missing .= ", width";
  4764. }
  4765. if (!isset($application_xml->height)) {
  4766. $missing .= ", height";
  4767. }
  4768. if (!isset($application_xml->evaluate)) {
  4769. $missing .= ", evaluate";
  4770. }
  4771. if (strlen($missing) > 2) {
  4772. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4773. return;
  4774. }
  4775. }
  4776. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4777. $typec = strtolower($application_xml->type);
  4778. require_once 'ilm_handlers/' . $typec . '.php';
  4779. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4780. return $retorno;
  4781. } // static function new_ilm($itemid)
  4782. /// Function for save in database an iLM edit
  4783. // @param object $param An object with iLM params
  4784. static function edit_ilm ($param, $itemid) {
  4785. // Descobrir o tipo de iLM:
  4786. global $DB, $USER, $CFG;
  4787. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4788. $pathtemp = $CFG->dataroot . '/temp/';
  4789. $contextuser = context_user::instance($USER->id);
  4790. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4791. $zip = new zip_packer();
  4792. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4793. $files_extract = null;
  4794. foreach ($files as $file) {
  4795. if (!$file->is_directory())
  4796. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4797. }
  4798. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4799. $typec = strtolower($iassign_t->type);
  4800. require_once 'ilm_handlers/' . $typec . '.php';
  4801. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4802. }
  4803. /// Function for register the new iLM (in database and in the directory)
  4804. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4805. // @param object $param An object with iLM params
  4806. static function copy_new_version_ilm ($param) {
  4807. global $DB, $CFG, $USER;
  4808. $itemid = $param->file;
  4809. $pathtemp = $CFG->dataroot . '/temp/';
  4810. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4811. //D echo "pathtemp=$pathtemp<br/>";
  4812. $contextuser = context_user::instance($USER->id);
  4813. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4814. $zip = new zip_packer();
  4815. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4816. $files_extract = null;
  4817. foreach ($files as $file) {
  4818. if (!$file->is_directory())
  4819. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4820. }
  4821. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4822. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4823. $typec = strtolower($iassign_t->type);
  4824. require_once 'ilm_handlers/' . $typec . '.php';
  4825. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4826. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4827. } // static function copy_new_version_ilm($param)
  4828. //VER::
  4829. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4830. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4831. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4832. /// Function for change visibility of iLM
  4833. // @param int $ilm_id Id of iLM
  4834. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4835. static function visible_ilm ($ilm_id, $status) {
  4836. global $DB;
  4837. if ($status == 0)
  4838. $visible = 1;
  4839. else
  4840. $visible = 0;
  4841. $newentry = new stdClass();
  4842. $newentry->id = $ilm_id;
  4843. $newentry->enable = $visible;
  4844. if (!$DB->update_record("iassign_ilm", $newentry))
  4845. error(get_string('error_edit_ilm', 'iassign'));
  4846. }
  4847. /// Function for confirm change default iLM
  4848. // @param int $ilm_id Id of iLM
  4849. // @param int $ilm_parent Id of parent iLM
  4850. // @return string Return with an string for create default page confirmation
  4851. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4852. global $OUTPUT, $DB;
  4853. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4854. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4855. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4856. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4857. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4858. return $return;
  4859. }
  4860. /// Function for change the default iLM
  4861. // @see settings_ilm.php
  4862. // @param int $ilm_id Id of iLM
  4863. // @return int Return Id of default iLM
  4864. static function default_ilm ($ilm_id) {
  4865. global $DB;
  4866. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4867. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4868. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4869. $iassign_ilm_default->id = $iassign_ilm->id;
  4870. $iassign_ilm_default->parent = 0;
  4871. $iassign_ilm->parent = $iassign_ilm_default->id;
  4872. $iassign_ilm->id = 0;
  4873. $iassign_ilm_default->enable = 1;
  4874. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4875. print_error('error_edit_ilm', 'iassign');
  4876. }
  4877. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4878. if (!$inserted) {
  4879. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4880. print_error($msg_error);
  4881. //xx print_error('error_add_ilm', 'iassign');
  4882. }
  4883. return $iassign_ilm_default->id;
  4884. } // static function default_ilm ($ilm_id)
  4885. /// Function for confirm delete iLM
  4886. // @param int $ilm_id Id of iLM
  4887. // @param int $ilm_parent Id of parent iLM
  4888. // @return string Return with an string for create delete page confirmation
  4889. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4890. global $OUTPUT, $DB;
  4891. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4892. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4893. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4894. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4895. }
  4896. /// Function for delete directory where the iLM is allocated.
  4897. // @param string $dirPath
  4898. // @throws InvalidArgumentException
  4899. public static function delete_dir ($dirPath) {
  4900. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4901. $dirPath .= '/';
  4902. }
  4903. $files = glob($dirPath . '*', GLOB_MARK);
  4904. foreach ($files as $file) {
  4905. if (is_dir($file)) {
  4906. ilm_settings::delete_dir($file);
  4907. } else {
  4908. unlink($file);
  4909. }
  4910. }
  4911. rmdir($dirPath);
  4912. }
  4913. /// Function for delete iLM
  4914. // @param int $ilm_id Id of iLM
  4915. // @return int Return Id of parent iLM
  4916. static function delete_ilm ($ilm_id) {
  4917. global $DB;
  4918. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4919. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4920. $typec = strtolower($iassign_ilm->type);
  4921. require_once 'ilm_handlers/' . $typec . '.php';
  4922. $retorno = $typec::delete_ilm($ilm_id);
  4923. return $retorno;
  4924. }
  4925. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4926. // @param int $ilm_id Id of iLM
  4927. static function export_ilm ($ilm_id) {
  4928. global $DB;
  4929. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4930. if (!$iassign_ilm) return; // security debug...
  4931. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4932. $typec = strtolower($iassign_ilm->type);
  4933. if (!$typec) $typec = "html5"; // security debug...
  4934. require_once 'ilm_handlers/' . $typec . '.php';
  4935. $typec::export_ilm($ilm_id);
  4936. } // static function export_ilm($ilm_id)
  4937. //TODO iLM_HTML5 :: //MOOC 2016
  4938. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4939. // @param int $ilm_id Id of iLM
  4940. static function export_update_ilm ($ilm_id) {
  4941. global $DB, $CFG;
  4942. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4943. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4944. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4945. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4946. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4947. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4948. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4949. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4950. $upgrade_descriptor .= '</upgrade>' . "\n";
  4951. file_put_contents($xml_filename, $upgrade_descriptor);
  4952. header("Pragma: public");
  4953. header("Expires: 0");
  4954. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4955. header("Cache-Control: private", false);
  4956. header('Content-Type: application/xml; charset=utf-8');
  4957. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4958. header("Content-Length: " . @filesize($xml_filename));
  4959. set_time_limit(0);
  4960. @readfile("$xml_filename") || die("File not found.");
  4961. unlink($xml_filename);
  4962. exit;
  4963. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4964. /// Function for save iLM from XML descriptor
  4965. // @param array $application_xml Data of XML descriptor
  4966. // @param array $files_extract Filenames of extract files
  4967. // @return array Return an array content id of JAR files
  4968. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4969. global $CFG, $USER;
  4970. // Tratamento diferenciado se for do tipo HTML5:
  4971. $source = "";
  4972. $diretorio = "";
  4973. if (strtolower($application_xml->type) == 'html5') {
  4974. $i = 0;
  4975. foreach ($files_extract as $key => $value) {
  4976. $file = $CFG->dataroot . '/temp/' . $key;
  4977. // Verifica se já existe a pasta no diretório dos iLM:
  4978. if ($i == 0) {
  4979. $source = $file;
  4980. if (file_exists("ilm/" . basename($file))) {
  4981. $j = 1;
  4982. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4983. $j ++;
  4984. }
  4985. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4986. // mkdir($diretorio, 0777, true);
  4987. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4988. }
  4989. else {
  4990. $diretorio = 'ilm/' . basename($file);
  4991. // mkdir($diretorio, 0777, true);
  4992. mkdir($diretorio, 0755, true);
  4993. }
  4994. break;
  4995. }
  4996. $i ++;
  4997. }
  4998. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4999. if ($item->isDir()) {
  5000. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  5001. }
  5002. else {
  5003. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  5004. }
  5005. }
  5006. ilm_settings::delete_dir($source);
  5007. return "./" . $diretorio;
  5008. }
  5009. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5010. $file_jar = array();
  5011. $files_ilm = explode(",", $application_xml->file_jar);
  5012. $contextsystem = context_system::instance();
  5013. foreach ($files_ilm as $value) {
  5014. $file_ilm = array(
  5015. 'userid' => $USER->id,
  5016. 'contextid' => $contextsystem->id,
  5017. 'component' => 'mod_iassign',
  5018. 'filearea' => 'ilm',
  5019. 'itemid' => rand(1, 999999999),
  5020. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5021. 'filename' => $value);
  5022. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5023. array_push($file_jar, $file_ilm->get_id());
  5024. }
  5025. foreach ($files_extract as $key => $value) {
  5026. $file = $CFG->dataroot . '/temp/' . $key;
  5027. if (file_exists($file))
  5028. unlink($file);
  5029. }
  5030. return $file_jar;
  5031. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5032. /// Function for import the iLM from an package
  5033. // @param int $itemid Itemid of zip file
  5034. static function import_ilm ($itemid) {
  5035. global $CFG, $USER, $OUTPUT;
  5036. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5037. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5038. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5039. }
  5040. $pathtemp = $CFG->dataroot . '/temp/';
  5041. $contextuser = context_user::instance($USER->id);
  5042. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5043. $zip = new zip_packer();
  5044. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5045. foreach ($files as $file) {
  5046. if (!$file->is_directory())
  5047. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5048. }
  5049. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5050. // Verifica se o pacote possui o XML
  5051. if (!$application_xml) {
  5052. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5053. return;
  5054. } else {
  5055. $missing = "";
  5056. if (!isset($application_xml->name)) {
  5057. $missing .= "name";
  5058. }
  5059. if (!isset($application_xml->version)) {
  5060. $missing .= ", version";
  5061. }
  5062. if (!isset($application_xml->type)) {
  5063. $missing .= ", type";
  5064. }
  5065. if (!isset($application_xml->extension)) {
  5066. $missing .= ", extension";
  5067. }
  5068. if (!isset($application_xml->file_jar)) {
  5069. $missing .= ", file_jar";
  5070. }
  5071. if (!isset($application_xml->file_class)) {
  5072. $missing .= ", file_class";
  5073. }
  5074. if (!isset($application_xml->width)) {
  5075. $missing .= ", width";
  5076. }
  5077. if (!isset($application_xml->height)) {
  5078. $missing .= ", height";
  5079. }
  5080. if (!isset($application_xml->evaluate)) {
  5081. $missing .= ", evaluate";
  5082. }
  5083. if (strlen($missing) > 2) {
  5084. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5085. return;
  5086. }
  5087. }
  5088. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5089. $typec = strtolower($application_xml->type);
  5090. require_once 'ilm_handlers/' . $typec . '.php';
  5091. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5092. } // static function import_ilm($itemid)
  5093. /// Function for list iLM defaults
  5094. // @return string Return an string with a table of iLM
  5095. static function list_ilm () {
  5096. global $DB, $OUTPUT;
  5097. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5098. $str = '';
  5099. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5100. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5101. if ($iassign_ilm) {
  5102. foreach ($iassign_ilm as $ilm) {
  5103. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5104. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5105. $str .= '<tr><td>';
  5106. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5107. $str .= '<tr>';
  5108. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5109. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5110. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5111. $str .= '</tr>';
  5112. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5113. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5114. $str .= '</table>';
  5115. $str .= '</td></tr>';
  5116. }
  5117. }
  5118. $str .= '</table>';
  5119. return $str;
  5120. }
  5121. /// Function for download and install an upgrade of an iLM
  5122. // @param int $ilm_id Id of iLM
  5123. static function upgrade_ilm ($ilm_id) {
  5124. global $DB, $CFG, $USER;
  5125. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5126. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5127. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5128. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5129. if (!$result)
  5130. print_error('error_upgrade_ilm', 'iassign');
  5131. else {
  5132. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5133. $extension = explode(".", $zip_filename);
  5134. if ($extension[count($extension) - 1] != 'ipz') {
  5135. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5136. die;
  5137. }
  5138. $zip = new zip_packer();
  5139. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5140. $contextuser = context_user::instance($USER->id);
  5141. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5142. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5143. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5144. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5145. if (file_exists($zip_filename))
  5146. unlink($zip_filename);
  5147. if (empty($file_jar)) {
  5148. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5149. print_error($msg_error);
  5150. //xx print_error('error_add_ilm', 'iassign');
  5151. }
  5152. else {
  5153. $newentry = new stdClass();
  5154. $newentry->name = (String) $application_xml->name;
  5155. $newentry->version = (String) $application_xml->version;
  5156. $newentry->url = (String) $application_xml->url;
  5157. $newentry->description = $description_str;
  5158. $newentry->extension = strtolower((String) $application_xml->extension);
  5159. $newentry->file_jar = implode(",", $file_jar);
  5160. $newentry->file_class = (String) $application_xml->file_class;
  5161. $newentry->width = (String) $application_xml->width;
  5162. $newentry->height = (String) $application_xml->height;
  5163. $newentry->enable = 0;
  5164. $newentry->timemodified = time();
  5165. $newentry->author = $USER->id;
  5166. $newentry->timecreated = time();
  5167. $newentry->evaluate = (String) $application_xml->evaluate;
  5168. $newentry->parent = $ilm_id;
  5169. }
  5170. }
  5171. return $iassign_ilm->id;
  5172. } // static function upgrade_ilm($ilm_id)
  5173. //MOOC2014 -- inicio
  5174. //TODO: REVIEW
  5175. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5176. // static function move_iassign($ilm_id)
  5177. //MOOC2014 -- final
  5178. /// Function for list iLM versions with all informations
  5179. // @return string Return an string with a table of iLM
  5180. static function view_ilm ($ilmid, $from) {
  5181. global $DB;
  5182. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5183. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5184. $typec = strtolower($iassign_ilm->type);
  5185. require_once 'ilm_handlers/' . $typec . '.php';
  5186. $retorno = $typec::view_ilm($ilmid, $from);
  5187. return $retorno;
  5188. }
  5189. /// Function for get form variables for add, edit, or copy iLM params
  5190. // @param int $ilm_param_id Id of iLM param
  5191. // @param string $action String with the action
  5192. // @return object Return an object with forms variables
  5193. static function add_edit_copy_param ($ilm_param_id, $action) {
  5194. global $DB;
  5195. require_once('params_form.php');
  5196. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5197. $param = new stdClass();
  5198. $param->action = $action;
  5199. $param->ilm_param_id = $ilm_param_id;
  5200. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5201. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5202. $type = $iassign_ilm_config->param_type;
  5203. if ($action == 'add') {
  5204. $param->title = get_string('add_ilm', 'iassign');
  5205. $param->iassign_ilmid = $ilm_param_id;
  5206. $param->param_name = "";
  5207. $param->param_value = "";
  5208. $param->description = "";
  5209. $param->visible = 1;
  5210. }
  5211. elseif ($action == 'edit') {
  5212. if ($iassign_ilm_config) {
  5213. $param->title = get_string('edit_ilm', 'iassign');
  5214. $param->id = $iassign_ilm_config->id;
  5215. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5216. $param->param_type = $type; //MOOC2014
  5217. $param->param_name = $iassign_ilm_config->param_name;
  5218. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5219. $param->param_value = $iassign_ilm_config->param_value;
  5220. else //MOOC2014
  5221. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5222. $param->param_value = $iassign_ilm_config->param_value;
  5223. $param->description = $iassign_ilm_config->description;
  5224. $param->visible = $iassign_ilm_config->visible;
  5225. }
  5226. }
  5227. elseif ($action == 'copy') {
  5228. if ($iassign_ilm_config) {
  5229. $param->title = get_string('copy_ilm', 'iassign');
  5230. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5231. $param->param_type = $type; //MOOC2014
  5232. $param->param_name = $iassign_ilm_config->param_name;
  5233. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5234. $param->param_value = $iassign_ilm_config->param_value;
  5235. else //MOOC2014
  5236. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5237. $param->description = $iassign_ilm_config->description;
  5238. $param->visible = $iassign_ilm_config->visible;
  5239. }
  5240. }
  5241. return $param;
  5242. } // static function add_edit_copy_param($ilm_param_id, $action)
  5243. /// Function for change visibility of iLM param
  5244. // @param int $ilm_param_id Id of iLM param
  5245. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5246. static function visible_param ($ilm_param_id, $status) {
  5247. global $DB, $CFG;
  5248. if ($status == 0)
  5249. $visible = 1;
  5250. else
  5251. $visible = 0;
  5252. $newentry = new stdClass();
  5253. $newentry->id = $ilm_param_id;
  5254. $newentry->visible = $visible;
  5255. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5256. error(get_string('error_edit_param', 'iassign'));
  5257. }
  5258. /// Function for save in database an new iLM param
  5259. // @param object $param An object with iLM params
  5260. static function add_param ($param) {
  5261. global $DB;
  5262. $newentry = new stdClass();
  5263. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5264. //MOOC2014 $newentry->param_name = $param->param_name;
  5265. $newentry->param_type = $param->param_type; //MOOC2014
  5266. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5267. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5268. $newentry->param_value = $param->param_value;
  5269. else //MOOC2014
  5270. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5271. $newentry->description = $param->description;
  5272. $newentry->visible = $param->visible;
  5273. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5274. if (!$newentry->id) {
  5275. print_error('error_add_param', 'iassign');
  5276. }
  5277. }
  5278. /// Function for save in database a iLM param edit
  5279. // @param object $param An object with iLM params
  5280. static function edit_param ($param) {
  5281. global $DB;
  5282. $updentry = new stdClass();
  5283. $updentry->id = $param->id;
  5284. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5285. $updentry->param_type = $param->param_type; //MOOC2014
  5286. // $updentry->param_name = $param->param_name;
  5287. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5288. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5289. $updentry->param_value = $param->param_value;
  5290. else //MOOC2014
  5291. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5292. $updentry->description = $param->description;
  5293. $updentry->visible = $param->visible;
  5294. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5295. error(get_string('error_edit_param', 'iassign'));
  5296. }
  5297. }
  5298. /// Function for save in database a iLM param copy
  5299. // @param object $param An object with iLM params
  5300. static function copy_param ($param) {
  5301. global $DB;
  5302. $newentry = new stdClass();
  5303. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5304. //$newentry->param_name = $param->param_name;
  5305. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5306. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5307. $newentry->param_value = $param->param_value;
  5308. else //MOOC2014
  5309. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5310. $newentry->description = $param->description;
  5311. $newentry->visible = $param->visible;
  5312. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5313. if (!$newentry->id) {
  5314. print_error('error_add_param', 'iassign');
  5315. }
  5316. }
  5317. /// Function for delete iLM param of database
  5318. // @param int $param_id Id of iLM param
  5319. static function delete_param ($param_id) {
  5320. global $DB;
  5321. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5322. print_error('error_delete_param', 'iassign');
  5323. }
  5324. }
  5325. } // class ilm_settings
  5326. /// Class for manage iLM files (editor).
  5327. class ilm_manager {
  5328. var $id; // course id
  5329. var $url;
  5330. var $from;
  5331. /// Constructor for the base ilm_manager class
  5332. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5333. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5334. function __construct ($id, $url, $from) {
  5335. $this->id = $id; // course id
  5336. $this->url = $url;
  5337. $this->from = $from;
  5338. }
  5339. /// Function to get iAssign content file in Moodle data (exercise)
  5340. // @calledby x function preview_ilm($iassign_ilm) :
  5341. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5342. function get_file_ilm () {
  5343. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5344. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5345. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5346. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5347. $md_file = $fs->get_file_by_id($fileid);
  5348. $ilm_content_file = $md_file->get_content();
  5349. return $ilm_content_file;
  5350. }
  5351. /// Function for creating a new file from the iLM online editor
  5352. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5353. function ilm_editor_new () {
  5354. global $CFG, $DB, $OUTPUT, $PAGE;
  5355. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5356. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5357. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5358. $context = context_course::instance($this->id);
  5359. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5360. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5361. if (!$iassign) {
  5362. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5363. die();
  5364. }
  5365. $temp = explode(",", $iassign->extension);
  5366. $extension = $temp[0]; // default extension for this iLM
  5367. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5368. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5369. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5370. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5371. if ($stringArchiveContent != NULL) {
  5372. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5373. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5374. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5375. $filename = optional_param('filename', NULL, PARAM_RAW);
  5376. //Leo $filename = iassign_utils::format_filename($filename); //
  5377. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5378. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5379. //2019/02 $arrayfilename = explode(".", $filename);
  5380. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5381. //2019/02 $count_dots = count($arrayfilename);
  5382. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5383. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5384. //2019/02 if ($last_name != $extension)
  5385. //2019/02 $filename = $filename . '.' . $extension;
  5386. //2019/02 }
  5387. //2019/02 else { // no extension...
  5388. //2019/02 $filename = $filename . '.' . $extension;
  5389. //2019/02 }
  5390. // Store the name of recent created file
  5391. $_SESSION['file_name'] = $filename;
  5392. //$this->write_file_iassign($string, $filename);
  5393. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5394. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5395. die();
  5396. }
  5397. else { // if ($stringArchiveContent != NULL)
  5398. // iLM On-line editor
  5399. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5400. $str_get_iLM = "window.frames.iLM";
  5401. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5402. }
  5403. else { // otherwise it is JAR named 'iLM'
  5404. $str_get_iLM = "document.iLM";
  5405. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5406. }
  5407. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5408. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5409. $files_array = '';
  5410. foreach ($files as $value) {
  5411. if ($value->get_filename() != ".")
  5412. $files_array .= "'" . $value->get_filename() . "',";
  5413. }
  5414. $files_array .= "''";
  5415. $file = null;
  5416. $ia_content = "";
  5417. $filename = "";
  5418. $error_files_exists = get_string('error_file_exists', 'iassign');
  5419. $output = "<script type='text/javascript'>
  5420. //<![CDATA[
  5421. //D alert('locallib.php: ilm_editor_new');
  5422. function submit_iLM_Answer () {
  5423. var docFormOnLineEditor = document.formEnvio;
  5424. var resposta_exerc = new Array(3);
  5425. var valor_resposta = new Array(3);
  5426. var sessao = new Array(3);
  5427. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5428. resposta_exerc[0] = doc_iLM.getAnswer();
  5429. valor_resposta[0] = doc_iLM.getEvaluation();
  5430. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5431. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5432. var files = new Array(" . $files_array . ");
  5433. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5434. if (docFormOnLineEditor.filename.value=='') {
  5435. // ERROR: the file name is empty
  5436. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5437. return false;
  5438. }
  5439. // }
  5440. for (i=0; i<files.length; i++) {
  5441. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5442. alert('" . $error_files_exists . "');
  5443. return false;
  5444. }
  5445. }
  5446. docFormOnLineEditor.submit();
  5447. return true;
  5448. }
  5449. //]]>
  5450. </script>\n";
  5451. $output .= "
  5452. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5453. $output .= $OUTPUT->box_start();
  5454. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5455. $output .= "
  5456. <table width='100%' cellpadding='20'>
  5457. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5458. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5459. </tr>
  5460. </table>\n";
  5461. $output .= $OUTPUT->box_end();
  5462. $output .= "<center>\n";
  5463. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5464. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5465. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5466. $output .= $output_ilm;
  5467. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5468. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5469. </center>
  5470. </form>\n";
  5471. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5472. $PAGE->navbar->add($title);
  5473. $PAGE->set_title($title);
  5474. $PAGE->set_heading($title); // insert title above the navigation bar
  5475. print $OUTPUT->header();
  5476. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5477. print $output;
  5478. print $OUTPUT->footer();
  5479. }
  5480. die();
  5481. } // function ilm_editor_new()
  5482. /// Function for editing an file in online editor
  5483. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5484. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5485. global $CFG, $DB, $OUTPUT, $PAGE;
  5486. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5487. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5488. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5489. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5490. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5491. // If iLM is not registered, error!
  5492. if (!$iassign) {
  5493. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5494. die;
  5495. }
  5496. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5497. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5498. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5499. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5500. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5501. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5502. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5503. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5504. if ($stringArchiveContent != NULL) {
  5505. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5506. die();
  5507. } else { // if ($stringArchiveContent != NULL)
  5508. $end_file = '';
  5509. if ($content_file) {
  5510. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5511. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5512. }
  5513. $temp = explode(",", $iassign->extension);
  5514. $extension = $temp[0]; // default extension for this iLM
  5515. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5516. $str_get_iLM = "window.frames.iLM";
  5517. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5518. } else { // otherwise it is JAR named 'iLM'
  5519. $str_get_iLM = "document.iLM";
  5520. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5521. }
  5522. $output = "<script type='text/javascript'>
  5523. //<![CDATA[
  5524. function submit_iLM_Answer () {
  5525. var docFormEditor = document.formEnvio;
  5526. var activityAnswer; // to get activity answer (text)
  5527. var activityValue; // to get activity answer value (float)
  5528. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5529. //activityAnswer = doc_iLM.getAnswer();
  5530. //activityValue = doc_iLM.getEvaluation();
  5531. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5532. activityValue = " . $str_get_iLM . ".getEvaluation();
  5533. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5534. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5535. docFormEditor.submit();
  5536. return true;
  5537. }
  5538. //]]>
  5539. </script>\n";
  5540. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5541. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5542. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5543. // return true;
  5544. // }
  5545. $output .= "
  5546. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5547. $output .= $OUTPUT->box_start();
  5548. $output .= "
  5549. <table width='100%' cellpadding='20'>
  5550. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5551. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5552. <input type='hidden' name='filename' value='$filename'/></td>
  5553. <td>
  5554. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5555. </tr>
  5556. </table>\n";
  5557. $output .= $OUTPUT->box_end();
  5558. $output .= " <center>\n";
  5559. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5560. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5561. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5562. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5563. </center>
  5564. </form>\n";
  5565. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5566. $PAGE->navbar->add($title);
  5567. $PAGE->set_title($title);
  5568. $PAGE->set_heading($title); // insert title above the navigation bar
  5569. print $OUTPUT->header();
  5570. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5571. print $output;
  5572. print $OUTPUT->footer();
  5573. } // else if ($stringArchiveContent != NULL)
  5574. die();
  5575. } // function ilm_editor_update()
  5576. /// Function for write iAssign file in Moodle data (exercise)
  5577. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5578. // @param string $stringArchiveContent Content of iassign file
  5579. // @param string $filename Filename of iassign file
  5580. function write_file_iassign ($stringArchiveContent, $filename) {
  5581. global $USER;
  5582. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5583. $context = context_course::instance($this->id);
  5584. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5585. $dirid = $this->get_dir_ilm('dirid');
  5586. $dir = $fs->get_file_by_id($dirid);
  5587. $fileinfo = array('contextid' => $context->id, // ID of course
  5588. 'component' => 'mod_iassign', // usually = table name
  5589. 'filearea' => 'activity', // usually = table name
  5590. 'itemid' => 0, // usually = ID of row in table
  5591. 'filepath' => '/', // any path beginning and ending whith '/'
  5592. 'userid' => $USER->id,
  5593. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5594. 'filename' => $filename); // any filename
  5595. // Create file containing text. '$stringArchiveContent'
  5596. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5597. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5598. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5599. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5600. // 'Activité interactive enregistrée avec succès sous le nom:';
  5601. // 'Atividade interativa gravada com sucesso sob o nome:'
  5602. $output = "
  5603. <script type='text/javascript'>
  5604. //<![CDATA[
  5605. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5606. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5607. //]]>
  5608. </script>";
  5609. print $output;
  5610. die();
  5611. }
  5612. /// Function for write iAssign file in Moodle data (exercise)
  5613. // @param string $stringArchiveContent Content of iassign file
  5614. // @param string $filename Filename of iassign file
  5615. // @param int $itemid Itemid of iassign file
  5616. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5617. global $OUTPUT, $USER;
  5618. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5619. $context = context_course::instance($this->id);
  5620. $dirid = $this->get_dir_ilm('dirid');
  5621. if ($stringArchiveContent != (-1)) {
  5622. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5623. $file = $fs->get_file_by_id($fileid);
  5624. if (!$file) {
  5625. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5626. die;
  5627. }
  5628. $fileinfo = array('contextid' => $context->id, // ID of context
  5629. 'component' => 'mod_iassign', // usually = table name
  5630. 'filearea' => 'activity', // usually = table name
  5631. 'itemid' => 0, // usually = ID of row in table
  5632. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5633. 'userid' => $USER->id,
  5634. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5635. 'license' => 'allrightsreserved', // allrightsreserved
  5636. 'timecreated' => $file->get_timecreated(),
  5637. 'filename' => $file->get_filename()); // any filename
  5638. $file->delete();
  5639. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5640. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5641. }
  5642. $output = "<script type='text/javascript'>
  5643. //<![CDATA[
  5644. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5645. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5646. //]]>
  5647. </script>";
  5648. print $output;
  5649. die();
  5650. }
  5651. /// Function for create an tag for iAssign filter
  5652. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5653. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5654. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5655. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5656. // @param int $fileid Id of file
  5657. // @return string Return an string with an tag of iassign filter
  5658. function tag_ilm ($fileid) {
  5659. global $DB;
  5660. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5661. $width = '600';
  5662. $height = '400';
  5663. $file = $fs->get_file_by_id($fileid);
  5664. $filetype = explode(".", $file->get_filename());
  5665. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5666. foreach ($iassign_ilm as $value) {
  5667. $extensions = explode(",", $value->extension);
  5668. if (in_array($filetype[1], $extensions)) {
  5669. $width = $value->width;
  5670. $height = $value->height;
  5671. }
  5672. }
  5673. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5674. }
  5675. /// Function for delete iAssign file in Moodle data (exercise)
  5676. function delete_file_ilm () {
  5677. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5678. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5679. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5680. $file = $fs->get_file_by_id($fileid);
  5681. if ($file)
  5682. $file->delete();
  5683. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5684. die();
  5685. }
  5686. /// Function for delete selected iAssign file in Moodle data (exercise)
  5687. function delete_selected_ilm () {
  5688. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5689. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5690. $context = context_course::instance($this->id);
  5691. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5692. $dirid = $this->get_dir_ilm('dirid');
  5693. foreach ($files_id as $file_id) {
  5694. $file = $fs->get_file_by_id($file_id);
  5695. if ($file) {
  5696. if (!$file->is_directory())
  5697. $file->delete();
  5698. else {
  5699. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5700. foreach ($files_delete as $value)
  5701. $value->delete();
  5702. $file->delete();
  5703. }
  5704. }
  5705. }
  5706. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5707. die();
  5708. }
  5709. /// Function for duplicate iAssign file from "online" edition
  5710. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5711. function duplicate_file_ilm () {
  5712. global $USER, $COURSE;
  5713. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5714. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5715. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5716. $filename = optional_param('filename', NULL, PARAM_RAW);
  5717. $file = $fs->get_file_by_id($fileid);
  5718. $context = context_course::instance($this->id);
  5719. $fileinfo = array(
  5720. 'contextid' => $context->id, // ID of context
  5721. 'component' => 'mod_iassign', // usually = table name
  5722. 'filearea' => 'activity', // usually = table name
  5723. 'itemid' => 0, // usually = ID of row in table
  5724. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5725. 'userid' => $USER->id,
  5726. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5727. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5728. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5729. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5730. die();
  5731. }
  5732. /// Function for rename iAssign file
  5733. function rename_file_ilm () {
  5734. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5735. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5736. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5737. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5738. $file = $fs->get_file_by_id($fileid);
  5739. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5740. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5741. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5742. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5743. die();
  5744. }
  5745. /// Function for get iassign file for iassign form
  5746. function add_ilm () {
  5747. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5748. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5749. $output = "
  5750. <script type='text/javascript'>
  5751. //<![CDATA[
  5752. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5753. iassign_file_link.innerHTML = '$filename';
  5754. window.opener.document.forms['mform1'].file.value='$fileid';
  5755. window.opener.document.forms['mform1'].filename.value='$filename';
  5756. window.close();
  5757. //]]>
  5758. </script>";
  5759. print $output;
  5760. die();
  5761. }
  5762. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5763. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5764. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5765. function preview_ilm ($courseid, $iassign_ilm) {
  5766. global $OUTPUT, $CFG, $USER;
  5767. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5768. $title = get_string('modulename', 'iassign'); // iAssign
  5769. print $OUTPUT->header();
  5770. print $OUTPUT->box_start();
  5771. $javascript = "
  5772. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5773. <script type='text/javascript'>
  5774. //<![CDATA[
  5775. function submit_close () {
  5776. window.opener.location.reload();
  5777. window.close();
  5778. }
  5779. //]]>
  5780. </script>\n";
  5781. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5782. // to the complete "applet" tag
  5783. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5784. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5785. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5786. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5787. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5788. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5789. if ($ilm_name != "ivprog") {
  5790. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5791. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5792. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5793. } else {
  5794. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5795. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5796. $timecreated = time();
  5797. $token = md5($timecreated);
  5798. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5799. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5800. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5801. $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)
  5802. }
  5803. $html = "
  5804. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5805. <table border='1'>
  5806. <tr><td>
  5807. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5808. <!-- iLM calls : end -->
  5809. </td></tr>
  5810. </table>
  5811. <table>
  5812. <tr>
  5813. <td align='center'>
  5814. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5815. </td></tr>
  5816. </table>
  5817. </form>\n";
  5818. print $javascript . $html;
  5819. print $OUTPUT->box_end();
  5820. //NAO echo format_string($html); // Moodle 3.X
  5821. die();
  5822. } // function preview_ilm($courseid, $iassign_ilm)
  5823. //r_ function preview_ilm ($iassign_ilm)
  5824. //r_ /// Function for preview iassign file from iassign filter.
  5825. //r_ function preview_ilm() {
  5826. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5827. //r_ $tag_filter = $this->tag_ilm($fileid);
  5828. //r_ $javascript = "<script type='text/javascript'>
  5829. //r_ //<![CDATA[
  5830. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5831. //r_ //]]>
  5832. //r_ </script>";
  5833. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5834. //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>
  5835. //r_ </table></form></body></html>";
  5836. //r_ echo $javascript . format_text($html);
  5837. //r_ die;
  5838. //r_ }
  5839. /// Function for export an package (zip) of iassign files
  5840. function export_files_ilm () {
  5841. global $CFG;
  5842. $context = context_course::instance($this->id);
  5843. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5844. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5845. $zip = new zip_archive();
  5846. $zip->open($zip_filename);
  5847. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5848. foreach ($files_id as $file_id) {
  5849. $file = $fs->get_file_by_id($file_id);
  5850. if (!$file->is_directory())
  5851. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5852. else {
  5853. $zip->add_directory($file->get_filepath());
  5854. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5855. foreach ($files_zip as $value) {
  5856. if (!$value->is_directory())
  5857. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5858. else
  5859. $zip->add_directory($value->get_filepath());
  5860. }
  5861. }
  5862. }
  5863. $zip->close();
  5864. header("Pragma: public");
  5865. header("Expires: 0");
  5866. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5867. header("Cache-Control: private", false);
  5868. header("Content-Type: application/zip");
  5869. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5870. header("Content-Transfer-Encoding: binary");
  5871. header("Content-Length: " . @filesize($zip_filename));
  5872. set_time_limit(0);
  5873. @readfile("$zip_filename") || die("File not found.");
  5874. unlink($zip_filename);
  5875. exit;
  5876. }
  5877. /// Function of execute a command in button editor tinymce
  5878. // @param int $fileid Id of file
  5879. function tinymce_ilm ($fileid) {
  5880. $tag_filter = $this->tag_ilm($fileid);
  5881. $output = "<script type='text/javascript'>
  5882. //<![CDATA[
  5883. var tag_filter = '$tag_filter';
  5884. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5885. // all right, insert it
  5886. } else {
  5887. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5888. }
  5889. // window.close();
  5890. //]]>
  5891. </script>\n";
  5892. print $output;
  5893. die();
  5894. }
  5895. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5896. /// Function to add content to the Editor Window
  5897. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5898. // @param int $fileid Id of file
  5899. function editor_ilm ($fileid, $editor) {
  5900. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5901. $output1 = "<script type='text/javascript'>
  5902. //<![CDATA[
  5903. var tag_filter = '$tag_filter';\n";
  5904. if ($editor == 'atto') {
  5905. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5906. } elseif ($editor == 'tinyMCE') {
  5907. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5908. } else
  5909. $output2 = "";
  5910. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5911. window.close();
  5912. //]]>
  5913. </script>\n";
  5914. //D var_dump($output);
  5915. print $output1 . $output2 . $output3;
  5916. die();
  5917. }
  5918. /// Function to add content to the Atto Editor Window
  5919. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5920. // @param int $fileid Id of file
  5921. function atto_ilm ($fileid) {
  5922. global $CFG, $DB;
  5923. $tag_filter = $this->tag_ilm($fileid);
  5924. $output = "<script type='text/javascript'>
  5925. //<![CDATA[
  5926. var tag_filter = '$tag_filter';
  5927. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5928. // all right, insert iLM tag to this editor
  5929. } else {
  5930. // error trying to insert
  5931. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5932. }
  5933. //window.close();
  5934. //]]>
  5935. </script>\n";
  5936. print $output;
  5937. die();
  5938. }
  5939. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5940. // @param string $key Key for return information
  5941. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5942. function get_dir_ilm ($key) {
  5943. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5944. $context = context_course::instance($this->id);
  5945. $dirid = optional_param('dirid', 0, PARAM_INT);
  5946. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5947. if ($dirid == 0) {
  5948. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5949. $dirid = $dir->get_id();
  5950. }
  5951. else {
  5952. $dir = $fs->get_file_by_id($dirid);
  5953. $dir_base = $dir->get_filepath();
  5954. }
  5955. $dir_parent = $dir->get_parent_directory();
  5956. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5957. return $data[$key];
  5958. }
  5959. /// Function for create an new dir
  5960. function new_dir_ilm () {
  5961. global $USER;
  5962. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5963. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5964. $dir_base = $this->get_dir_ilm('dir_base');
  5965. $context = context_course::instance($this->id);
  5966. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5967. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5968. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5969. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5970. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5971. }
  5972. /// Function for delete an dir
  5973. function delete_dir_ilm () { //
  5974. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5975. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5976. $context = context_course::instance($this->id);
  5977. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5978. $dir_parent = $this->get_dir_ilm('dir_parent');
  5979. if ($dir) {
  5980. if ($dir->is_directory()) {
  5981. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5982. foreach ($files_delete as $value)
  5983. $value->delete();
  5984. $dir->delete();
  5985. }
  5986. }
  5987. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5988. die();
  5989. }
  5990. /// Function for rename an dir
  5991. function rename_dir_ilm () {
  5992. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5993. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5994. $context = context_course::instance($this->id);
  5995. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5996. $dir_parent = $this->get_dir_ilm('dir_parent');
  5997. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5998. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5999. if ($dir->is_directory()) {
  6000. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  6001. foreach ($files_rename_path as $value)
  6002. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  6003. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  6004. }
  6005. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6006. die();
  6007. }
  6008. /// Function for move an dir and your content for other dir
  6009. function selected_move_ilm () {
  6010. global $PAGE, $OUTPUT, $CFG;
  6011. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6012. $context = context_course::instance($this->id);
  6013. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6014. $dirid = $this->get_dir_ilm('dirid');
  6015. $dir_base = $this->get_dir_ilm('dir_base');
  6016. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6017. $code_javascript_ilm = "
  6018. <script type='text/javascript'>
  6019. //<![CDATA[
  6020. function getRadiobutton () {
  6021. var radioButtons = document.getElementsByTagName('input');
  6022. var param = '';
  6023. for (var counter=0; counter < radioButtons.length; counter++) {
  6024. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6025. param = radioButtons[counter].value;
  6026. }
  6027. return param;
  6028. }
  6029. function move_selected_ilm () {
  6030. var msgAnswer;
  6031. if (getRadiobutton() != '') {
  6032. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6033. if (msgAnswer)
  6034. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6035. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6036. }
  6037. else
  6038. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6039. }
  6040. function cancel_selected_ilm () {
  6041. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6042. }
  6043. //]]>
  6044. </script>\n";
  6045. $title = get_string('move_files', 'iassign');
  6046. $PAGE->set_title($title);
  6047. $PAGE->set_pagelayout('base');
  6048. print $OUTPUT->header();
  6049. print $OUTPUT->heading($title);
  6050. $dir_paths = array();
  6051. print $OUTPUT->box_start();
  6052. print "<center>";
  6053. foreach ($files_id as $file_id) {
  6054. $file = $fs->get_file_by_id($file_id);
  6055. if ($file) {
  6056. if (!$file->is_directory())
  6057. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6058. else {
  6059. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6060. array_push($dir_paths, $file->get_filepath());
  6061. }
  6062. }
  6063. }
  6064. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6065. if ($dir_base != '/') {
  6066. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6067. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6068. }
  6069. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6070. foreach ($files_tree as $file) {
  6071. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6072. $is_parent = false;
  6073. foreach ($dir_paths as $dir) {
  6074. $path = explode("/", $dir);
  6075. array_pop($path);
  6076. $path[count($path) - 1] = '';
  6077. $path = implode("/", $path);
  6078. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6079. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6080. }
  6081. if ($is_parent == false) {
  6082. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6083. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6084. }
  6085. }
  6086. }
  6087. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6088. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6089. print "</center>";
  6090. print $OUTPUT->box_end();
  6091. print $OUTPUT->footer();
  6092. print $code_javascript_ilm;
  6093. die;
  6094. }
  6095. /// Function for move files for an dir
  6096. function move_files_ilm () {
  6097. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6098. $context = context_course::instance($this->id);
  6099. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6100. $dirid = $this->get_dir_ilm('dirid');
  6101. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6102. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6103. foreach ($files_id as $file_id) {
  6104. $file = $fs->get_file_by_id($file_id);
  6105. if ($file) {
  6106. if ($file->is_directory()) {
  6107. $pathname = explode("/", $file->get_filepath());
  6108. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6109. foreach ($files_move_path as $value) {
  6110. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6111. $value->rename($path_move, $value->get_filename());
  6112. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6113. }
  6114. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6115. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6116. $file->rename($path_move, $file->get_filename());
  6117. } else {
  6118. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6119. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6120. }
  6121. }
  6122. }
  6123. //die;
  6124. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6125. die();
  6126. } // function move_files_ilm()
  6127. /// Function for recover files in use on all activities of a course
  6128. function recover_files_ilm () {
  6129. global $DB, $USER;
  6130. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6131. $courseid = optional_param('id', NULL, PARAM_INT);
  6132. $dirid = $this->get_dir_ilm('dirid');
  6133. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6134. $contextfile = context_course::instance($this->id);
  6135. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6136. foreach ($iassigns as $iassign) {
  6137. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6138. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6139. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6140. $context = context_module::instance($cm->id);
  6141. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  6142. if ($files) {
  6143. foreach ($files as $value) {
  6144. $extension = explode(".", $value->get_filename());
  6145. if (!$value->is_directory()) {
  6146. $fileinfo = array('contextid' => $contextfile->id,
  6147. 'component' => 'mod_iassign',
  6148. 'filearea' => 'activity',
  6149. 'itemid' => 0,
  6150. 'filepath' => $this->get_dir_ilm('dir_base'),
  6151. 'userid' => $USER->id,
  6152. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6153. 'license' => 'allrightsreserved',
  6154. 'timecreated' => time(),
  6155. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6156. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6157. }
  6158. }
  6159. } // if ($files)
  6160. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6161. } // foreach ($iassigns as $iassign)
  6162. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6163. die();
  6164. } // function recover_files_ilm()
  6165. /// Auxiliary function the get all files in a given context
  6166. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6167. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6168. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6169. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6170. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6171. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6172. // (NAO s_iassign_statement.file = s_files.id)
  6173. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6174. $dir_base = $this->get_dir_ilm('dir_base');
  6175. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6176. $countf = 0;
  6177. $array_files_id = array(); // all files from this context
  6178. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6179. //$filename = $item_fc->get_filename();
  6180. //$filepath = $item_fc->get_filepath();
  6181. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6182. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6183. // $array_files_aux[] = $item_fc;
  6184. $itemid = $item_fc->get_id();
  6185. if (!in_array($itemid, $array_files_id)) {
  6186. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6187. if ($fileuserid == $userid)
  6188. $filesfrommine[] = $item_fc;
  6189. else
  6190. $filesfromothers[] = $item_fc;
  6191. $array_files_id[] = $itemid;
  6192. $countf++;
  6193. }
  6194. }
  6195. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6196. return $countf;
  6197. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6198. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6199. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6200. function get_all_ilm_files_by_fileid ($fileid) {
  6201. global $DB, $USER;
  6202. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6203. //TODO Criar coluna 'authorid'
  6204. $str_query = "SELECT * FROM {iassign_statement} " .
  6205. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6206. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6207. return $array_iassign_ilm;
  6208. }
  6209. //NN
  6210. //NN
  6211. // Build string with JavaScript code with function to edit/remove/double iLM files
  6212. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6213. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6214. global $CFG;
  6215. $error_files_exists = get_string('error_file_exists', 'iassign');
  6216. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6217. $code_javascript_ilm = "
  6218. <script type='text/javascript'>
  6219. //<![CDATA[
  6220. function preview_ilm (fileid, ilmid) { //JavaScript function
  6221. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6222. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6223. }
  6224. function update_ilm (ilmid, fileid) { //JavaScript function
  6225. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6226. }
  6227. function delete_ilm (ilmid, fileid) { //JavaScript function
  6228. var msgAnswer;
  6229. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6230. if (msgAnswer) {
  6231. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6232. }
  6233. }
  6234. function delete_selected_ilm () { //JavaScript function
  6235. var msgAnswer;
  6236. var param = getCheckbox();
  6237. if (param.join() != '') {
  6238. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6239. if (msgAnswer)
  6240. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6241. }
  6242. else
  6243. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6244. }
  6245. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6246. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6247. }
  6248. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6249. var filenamecopy;
  6250. var i;
  6251. var files = new Array(" . $files_array . ");
  6252. do {
  6253. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6254. } while (filenamecopy == '');
  6255. if (filenamecopy == null)
  6256. return false;\n
  6257. else {
  6258. for (i=0;i<files.length;i++) {
  6259. if (files[i]==filenamecopy) {
  6260. alert('" . $error_files_exists . "');
  6261. return false;\n
  6262. }
  6263. }\n" .
  6264. // @see: function 'duplicate_file_ilm()' above
  6265. "
  6266. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6267. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6268. } // else
  6269. }
  6270. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6271. var filenamecopy;
  6272. var i;
  6273. var files = new Array($files_array);
  6274. do {
  6275. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6276. } while (filenamecopy == '');
  6277. if (filenamecopy == null)
  6278. return false;
  6279. else {
  6280. for (i=0;i<files.length;i++) {
  6281. if (files[i]==filenamecopy) {
  6282. alert('" . $error_files_exists . "');
  6283. return false;
  6284. }
  6285. }
  6286. 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;
  6287. }
  6288. }
  6289. function export_files_ilm () { //JavaScript function
  6290. var param = getCheckbox();
  6291. if (param.join() != '')
  6292. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6293. else
  6294. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6295. }
  6296. function select_all_ilm () { //JavaScript function
  6297. var checkBoxes = document.getElementsByTagName('input');
  6298. var selectAll = document.getElementById('select_all');
  6299. for (var counter=0; counter < checkBoxes.length; counter++) {
  6300. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6301. checkBoxes[counter].checked = selectAll.checked;
  6302. }
  6303. }
  6304. function getCheckbox () { //JavaScript function
  6305. var checkBoxes = document.getElementsByTagName('input');
  6306. var param = new Array();
  6307. for (var counter=0; counter < checkBoxes.length; counter++) {
  6308. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6309. param.push(checkBoxes[counter].value);
  6310. }
  6311. return param;
  6312. }
  6313. function new_dir_ilm () { //JavaScript function
  6314. var dirname = '';
  6315. var i;
  6316. var dirs = new Array(" . $dirs_array . ");
  6317. do {
  6318. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6319. } while (dirname == '');
  6320. if (dirname == null)
  6321. return false;\n
  6322. else {
  6323. for (i=0;i<dirs.length;i++) {
  6324. if (dirs[i]==dirname) {
  6325. alert('" . $error_dir_exists . "');
  6326. return false;\n
  6327. }
  6328. }
  6329. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6330. }
  6331. }
  6332. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6333. var msgAnswer;
  6334. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6335. if (msgAnswer) {
  6336. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6337. }
  6338. }
  6339. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6340. var dirnamecopy;
  6341. var i;
  6342. var dirs = new Array($dirs_array);
  6343. do {
  6344. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6345. } while (dirnamecopy == '');
  6346. if (dirnamecopy == null)
  6347. return false;\n
  6348. else {
  6349. for (i=0;i<dirs.length;i++) {
  6350. if (dirs[i]==dirnamecopy) {
  6351. alert('" . $error_dir_exists . "');
  6352. return false;\n
  6353. }
  6354. }
  6355. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6356. }
  6357. }
  6358. function move_selected_ilm (ilmid) { //JavaScript function
  6359. var param = getCheckbox();
  6360. if (param.join() != '')
  6361. 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();
  6362. else
  6363. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6364. }
  6365. function recover_files_ilm () { //JavaScript function
  6366. var msgAnswer;
  6367. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6368. if (msgAnswer) {
  6369. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6370. }
  6371. }
  6372. window.onload = function() { //JavaScript function
  6373. var xPosition = 0;
  6374. var yPosition = 0;
  6375. element=document.getElementById('new_file');
  6376. while(element) {
  6377. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6378. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6379. element = element.offsetParent;
  6380. }
  6381. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6382. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6383. location.hash = '#new_file';
  6384. };
  6385. //]]>
  6386. </script>\n"; // end of $code_javascript_ilm
  6387. return $code_javascript_ilm;
  6388. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6389. /// List iassign files from course directory
  6390. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6391. function view_files_ilm ($iassign_ilm_class, $extension) {
  6392. global $CFG, $DB, $USER, $OUTPUT;
  6393. $fs = get_file_storage();
  6394. $context = context_course::instance($this->id);
  6395. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6396. $dirid = $this->get_dir_ilm('dirid');
  6397. $dir_base = $this->get_dir_ilm('dir_base');
  6398. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6399. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6400. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6401. $files_array = '';
  6402. foreach ($files_course as $value) {
  6403. if (!$value->is_directory())
  6404. $files_array .= "'" . $value->get_filename() . "',";
  6405. }
  6406. $files_array .= "''";
  6407. $error_files_exists = get_string('error_file_exists', 'iassign');
  6408. $dirs_array = '';
  6409. foreach ($files_course as $value) {
  6410. if ($value->is_directory()) {
  6411. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6412. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6413. }
  6414. }
  6415. $dirs_array .= "''";
  6416. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6417. // TODO Rever o preview pois só deixar ver uma vez.
  6418. $code_javascript_ilm = "
  6419. <script type='text/javascript'>
  6420. //<![CDATA[
  6421. function preview_ilm (fileid, ilmid) {
  6422. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6423. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6424. }
  6425. function update_ilm (ilmid, fileid) {
  6426. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6427. }
  6428. function delete_ilm (ilmid, fileid) {
  6429. var msgAnswer;
  6430. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6431. if (msgAnswer) {
  6432. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6433. }
  6434. }
  6435. function delete_selected_ilm () {
  6436. var msgAnswer;
  6437. var param = getCheckbox();
  6438. if (param.join() != '') {
  6439. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6440. if (msgAnswer)
  6441. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6442. }
  6443. else
  6444. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6445. }
  6446. function add_ilm_iassign (ilmid, filename, fileid) {
  6447. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6448. }
  6449. function duplicate_ilm (ilmid, filename, fileid) {
  6450. var filenamecopy;
  6451. var i;
  6452. var files = new Array($files_array);
  6453. do {
  6454. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6455. } while (filenamecopy == '');
  6456. if (filenamecopy == null)
  6457. return false;\n
  6458. else {
  6459. for (i=0;i<files.length;i++) {
  6460. if (files[i]==filenamecopy) {
  6461. alert('$error_files_exists');
  6462. return false;\n
  6463. }
  6464. }\n" .
  6465. // @see: function 'duplicate_file_ilm()' above
  6466. "
  6467. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6468. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6469. } // else
  6470. }
  6471. function rename_ilm (ilmid, filename, fileid) {
  6472. var filenamecopy;
  6473. var i;
  6474. var files = new Array($files_array);
  6475. do {
  6476. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6477. } while (filenamecopy == '');
  6478. if (filenamecopy == null)
  6479. return false;
  6480. else {
  6481. for (i=0;i<files.length;i++) {
  6482. if (files[i]==filenamecopy) {
  6483. alert('$error_files_exists');
  6484. return false;
  6485. }
  6486. }
  6487. 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;
  6488. }
  6489. }
  6490. function export_files_ilm () {
  6491. var param = getCheckbox();
  6492. if (param.join() != '')
  6493. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6494. else
  6495. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6496. }
  6497. function select_all_ilm () {
  6498. var checkBoxes = document.getElementsByTagName('input');
  6499. var selectAll = document.getElementById('select_all');
  6500. for (var counter=0; counter < checkBoxes.length; counter++) {
  6501. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6502. checkBoxes[counter].checked = selectAll.checked;
  6503. }
  6504. }
  6505. function getCheckbox () {
  6506. var checkBoxes = document.getElementsByTagName('input');
  6507. var param = new Array();
  6508. for (var counter=0; counter < checkBoxes.length; counter++) {
  6509. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6510. param.push(checkBoxes[counter].value);
  6511. }
  6512. return param;
  6513. }
  6514. function new_dir_ilm () {
  6515. var dirname = '';
  6516. var i;
  6517. var dirs = new Array($dirs_array);
  6518. do {
  6519. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6520. } while (dirname == '');
  6521. if (dirname == null)
  6522. return false;\n
  6523. else {
  6524. for (i=0;i<dirs.length;i++) {
  6525. if (dirs[i]==dirname) {
  6526. alert('$error_dir_exists');
  6527. return false;\n
  6528. }
  6529. }
  6530. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6531. }
  6532. }
  6533. function delete_dir_ilm (ilmid, dirid) {
  6534. var msgAnswer;
  6535. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6536. if (msgAnswer) {
  6537. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6538. }
  6539. }
  6540. function rename_dir_ilm (ilmid, dirname, dirid) {
  6541. var dirnamecopy;
  6542. var i;
  6543. var dirs = new Array($dirs_array);
  6544. do {
  6545. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6546. } while (dirnamecopy == '');
  6547. if (dirnamecopy == null)
  6548. return false;\n
  6549. else {
  6550. for (i=0;i<dirs.length;i++) {
  6551. if (dirs[i]==dirnamecopy) {
  6552. alert('$error_dir_exists');
  6553. return false;\n
  6554. }
  6555. }
  6556. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6557. }
  6558. }
  6559. function move_selected_ilm (ilmid) {
  6560. var param = getCheckbox();
  6561. if (param.join() != '')
  6562. 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();
  6563. else
  6564. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6565. }
  6566. function recover_files_ilm () {
  6567. var msgAnswer;
  6568. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6569. if (msgAnswer) {
  6570. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6571. }
  6572. }
  6573. window.onload = function() {
  6574. var xPosition = 0;
  6575. var yPosition = 0;
  6576. element=document.getElementById('new_file');
  6577. while(element) {
  6578. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6579. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6580. element = element.offsetParent;
  6581. }
  6582. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6583. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6584. location.hash = '#new_file';
  6585. };
  6586. //]]>
  6587. </script>\n";
  6588. $output = "";
  6589. $select_all = "";
  6590. $count_files = 0;
  6591. $extensions_allow = array();
  6592. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6593. foreach ($iassign_ilm as $item_iassign_ilm)
  6594. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6595. foreach ($files_course as $value) {
  6596. $filename = $value->get_filename();
  6597. $filepath = $value->get_filepath();
  6598. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6599. $pathname = $pathname[count($pathname) - 1];
  6600. $fileid = $value->get_id();
  6601. $tmp = explode(".", $filename);
  6602. if (count($tmp)>1) // avoid error if the file has no extension
  6603. $filetype = $tmp[1];
  6604. else // probably error...
  6605. $filetype = '';
  6606. $author = $value->get_author();
  6607. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6608. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6609. $extensions = explode(",", $extension);
  6610. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6611. $count_files ++;
  6612. // buscar fileid nas tabelas do iassign
  6613. $list_filein_use = "";
  6614. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6615. if ($iassign_statement_activity_list) {
  6616. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6617. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6618. }
  6619. }
  6620. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6621. if (!$iassign_ilm) {
  6622. $iassign_ilm = new stdClass();
  6623. $iassign_ilm->id = $ilmid;
  6624. }
  6625. // Do not use $var inside "..." - problem with some "unusual" operational system
  6626. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6627. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6628. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6629. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6630. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6631. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6632. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6633. $check_select = "";
  6634. $link_rename = "";
  6635. $link_delete = "";
  6636. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6637. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6638. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6639. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6640. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6641. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6642. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6643. if ($value->get_userid() == $USER->id) {
  6644. if ($iassign_statement_activity_list) {
  6645. $check_select = "";
  6646. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6647. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6648. $link_rename = "";
  6649. } else {
  6650. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6651. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6652. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6653. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6654. }
  6655. }
  6656. if (!in_array($filetype, $extensions_allow)) {
  6657. $link_edit = "";
  6658. $link_add_ilm_iassign = "";
  6659. $link_add_ilm_tinymce = "";
  6660. $link_add_ilm_atto = "";
  6661. $link_filter = "";
  6662. }
  6663. if ($value->is_directory()) {
  6664. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6665. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6666. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6667. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6668. <td><center>$author</center></td>
  6669. <td><center>$timecreated</center></td>
  6670. <td><center>$timemodified</center></td></tr>\n";
  6671. }
  6672. else if ($this->from == 'iassign') {
  6673. $new_id = "";
  6674. $new_class = "";
  6675. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6676. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6677. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6678. }
  6679. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6680. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6681. <td><center>$author</center></td>
  6682. <td><center>$timecreated</center></td>
  6683. <td><center>$timemodified</center></td></tr>\n";
  6684. }
  6685. else if ($this->from == 'block') {
  6686. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6687. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6688. <td><center>$author</center></td>
  6689. <td><center>$timecreated</center></td>
  6690. <td><center>$timemodified</center></td></tr>\n";
  6691. }
  6692. else if ($this->from == 'tinymce') {
  6693. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6694. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6695. <td><center>$author</center></td>
  6696. <td><center>$timecreated</center></td>
  6697. <td><center>$timemodified</center></td></tr>\n";
  6698. }
  6699. else if ($this->from == 'atto') {
  6700. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6701. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6702. <td><center>$author</center></td>
  6703. <td><center>$timecreated</center></td>
  6704. <td><center>$timemodified</center></td></tr>\n";
  6705. }
  6706. }
  6707. }
  6708. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6709. $dir_base = "";
  6710. $header = "";
  6711. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6712. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6713. foreach ($basename as $value) {
  6714. $dir_base .= $value . "/";
  6715. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6716. if ($dir_id) {
  6717. if ($value == "") {
  6718. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6719. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6720. } else {
  6721. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6722. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6723. }
  6724. }
  6725. } // foreach ($basename as $value)
  6726. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6727. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6728. $html .= "
  6729. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6730. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6731. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6732. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6733. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6734. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6735. </table>\n";
  6736. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6737. $html .= "<table width='100%'><tr>\n";
  6738. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6739. if ($count_files != 0) {
  6740. $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";
  6741. $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";
  6742. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6743. }
  6744. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6745. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6746. $html .= "</form>\n";
  6747. print $code_javascript_ilm;
  6748. print $html;
  6749. } // function view_files_ilm($extension)
  6750. } // class ilm_manager
  6751. /// Class to insert of icons
  6752. class iassign_icons {
  6753. static function insert ($icon) {
  6754. global $CFG;
  6755. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6756. return $string;
  6757. }
  6758. }
  6759. /// Class with util functions for plugin manage
  6760. class iassign_utils {
  6761. /// Function to return the filename extension
  6762. // @param string The $filename as an string
  6763. // @return string Return an string (last group after '.')
  6764. static function filename_extension ($filename) {
  6765. if ($filename == null || $filename == '') {
  6766. return null;
  6767. }
  6768. $itens = explode('.', $filename);
  6769. $num = count($itens);
  6770. if ($num < 2) {
  6771. return null;
  6772. }
  6773. return $itens[$num - 1];
  6774. }
  6775. /// Use the PHP class/package ZipArchive to create a Zip file
  6776. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6777. // Warning: ZipArchive::close(): Failure to create temporary file: No such file or directory in /var/www/html/.../lib/filestorage/zip_archive.php on line 224
  6778. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6779. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6780. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6781. $zip = new zip_archive(); //2
  6782. $res = $zip->open($full_path_zip_filename);
  6783. $total_vet = count($vet_student_filename);
  6784. for ($ii=0; $ii<$total_vet; $ii++) {
  6785. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6786. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6787. }
  6788. $ret = $zip->close();
  6789. iassign_utils::download_file($full_path_zip_filename);
  6790. $filenameZip = $zip->filename;
  6791. return array($ret, $zip);
  6792. }
  6793. static function download_file ($zip_filename) {
  6794. header("Pragma: public");
  6795. header("Expires: 0");
  6796. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6797. header("Cache-Control: private", false);
  6798. header("Content-Type: application/zip");
  6799. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6800. header("Content-Transfer-Encoding: binary");
  6801. header("Content-Length: " . @filesize($zip_filename));
  6802. set_time_limit(0);
  6803. @readfile("$zip_filename") || die("File not found.");
  6804. unlink($zip_filename);
  6805. }
  6806. /// Function for format filename remove special caracters
  6807. // @param string $text String for clean
  6808. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6809. // @return string Return an string in clean format
  6810. static function format_filename ($text) {
  6811. if ($text != '.') {
  6812. //D $text = htmlspecialchars(urldecode($text));
  6813. //D echo "locallib.php: format_filename: $text<br/>";
  6814. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6815. $text = json_decode($text)->{current_language()};
  6816. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6817. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6818. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6819. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6820. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6821. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6822. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6823. // E.g. text = "exerc_midpoint.course.geo"
  6824. // 0123456789012345678901234
  6825. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6826. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6827. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6828. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6829. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6830. //$ext = strrpos($text, ".");
  6831. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6832. //$text = str_replace($array1, $array2, $text);
  6833. }
  6834. return $text;
  6835. }
  6836. /// Function to filter characters to the file name to iLM content
  6837. // @param string $text String for clean
  6838. // @param string $ext String ot the extension of the iLM
  6839. // @return string Return an string in clean format
  6840. static function filter_filename_extension ($filename, $ext) {
  6841. if ($filename != '.') {
  6842. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6843. $arrTo = array("_","","","","","","","","","","","","");
  6844. $filename = str_replace($arrFrom, $arrTo, $filename);
  6845. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6846. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6847. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6848. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6849. $index_lastposition = strlen($filenameF);
  6850. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6851. $text = str_replace(".", "_", $text); // erase all other "."
  6852. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6853. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6854. }
  6855. else
  6856. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6857. return $filenameF;
  6858. }
  6859. /// Function for format pathname remove special caracters
  6860. // @param string $text String for clean
  6861. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6862. // @return string Return an string in clean format
  6863. static function format_pathname ($text, $is_lowercase = true) {
  6864. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6865. $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", "-", "_", "", "", "");
  6866. $text = str_replace($array1, $array2, $text);
  6867. if ($is_lowercase)
  6868. $text = strtolower($text);
  6869. return $text;
  6870. }
  6871. /// Function for format file name from iLM original name
  6872. // @param string $text String to build the file neam
  6873. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6874. // @return string Return an string in clean format
  6875. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6876. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6877. $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", "-", "_", "", "", "");
  6878. $index_firstposition_blank = strpos($ilm_name, " ");
  6879. if ($index_firstposition_blank) { // truncate the name!
  6880. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6881. }
  6882. $index_firstposition_dots = strpos($ilm_name, ":");
  6883. if ($index_firstposition_dots) { // truncate the name!
  6884. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6885. }
  6886. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6887. if ($is_lowercase)
  6888. $namefiltered = strtolower($namefiltered);
  6889. return $namefiltered;
  6890. }
  6891. /// Function for insert version in the filename
  6892. // @param string $filename Name of file
  6893. // @return string Return the filename with version
  6894. static function version_filename ($filename) {
  6895. $array_filename = explode('.', $filename);
  6896. if (count($array_filename) > 1)
  6897. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6898. else
  6899. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6900. return $filename;
  6901. }
  6902. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6903. static function remove_code_message ($string) {
  6904. $array = explode("&lt;ia_uc&gt;", $string);
  6905. return $array[0];
  6906. }
  6907. }
  6908. // class iassign_utils
  6909. /// Class with language functions for plugin manage
  6910. class iassign_language {
  6911. /// Function for return text in language or get default language (en)
  6912. // @param string $lang Code of language
  6913. // @param string $description JSON text content all languages
  6914. // @return string Return an string in the language selected
  6915. static function get_description_lang ($lang, $descriptions) {
  6916. $description_lang = "";
  6917. $description = json_decode($descriptions);
  6918. if ($description == null) {
  6919. $description_lang = $descriptions;
  6920. }
  6921. else {
  6922. if (isset($description->{$lang}))
  6923. $description_lang = $description->{$lang};
  6924. else
  6925. if (isset($description->en)) //MOOC2014
  6926. $description_lang = $description->en;
  6927. else //MOOC2014
  6928. $description_lang = "en"; //MOOC2014
  6929. }
  6930. return $description_lang;
  6931. }
  6932. /// Function for return all language supported by iLM
  6933. // @param string $descriptions JSON text content all languages
  6934. // @return string Return as string with all languages
  6935. static function get_all_lang ($descriptions) {
  6936. $langs = "";
  6937. $description = json_decode($descriptions);
  6938. if ($description) {
  6939. foreach ($description as $key => $value) {
  6940. $langs .= $key . " ; ";
  6941. }
  6942. $langs = substr($langs, 0, strlen($langs) - 3);
  6943. }
  6944. return $langs;
  6945. }
  6946. /// Function for convert json in xml //MOOC2014
  6947. // @param string $json JSON text
  6948. // @return string Return as string with xml tags
  6949. static function json_to_xml ($json) {
  6950. $xml = "";
  6951. $json = json_decode($json);
  6952. foreach ($json as $key => $value) {
  6953. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6954. }
  6955. return $xml;
  6956. }
  6957. }
  6958. // class iassign_language
  6959. /// Class with log functions for plugin manage.
  6960. class iassign_log {
  6961. /// Function for insert log event
  6962. // @param string $action Code action of event
  6963. // @param string $information Text for describe action of event
  6964. // @param int $cmid Id of context module
  6965. // @param int $ilmid Id of iLM
  6966. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6967. global $COURSE, $CFG, $USER, $DB;
  6968. $newentry = new stdClass();
  6969. $newentry->time = time();
  6970. $newentry->userid = $USER->id;
  6971. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6972. $newentry->course = $COURSE->id;
  6973. $newentry->cmid = $cmid;
  6974. $newentry->ilmid = $ilmid;
  6975. $newentry->action = $action;
  6976. $newentry->info = $information;
  6977. $newentry->language = current_language();
  6978. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6979. if (ini_get("browscap") && function_exists('get_browse')) {
  6980. $browser = get_browse(null, true);
  6981. $newentry->javascript = $browser['javascript'];
  6982. $newentry->java = $browser['javaapplets'];
  6983. }
  6984. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6985. print_error('error_add_log', 'iassign');
  6986. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6987. } // class iassign_log