locallib.php 382 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239
  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. $comment = false;
  1194. if ($submission_comment)
  1195. $comment = $this->write_comment_submission();
  1196. // receives data of iLM using the current activity
  1197. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $this->activity->get_activity()->iassign_ilmid)); // has automatic evaluation?
  1198. $iassign = $DB->get_record("iassign", array("id" => $this->activity->get_activity()->iassignid)); // activity
  1199. // receives data of submission of current activity
  1200. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  1201. // receives post and get
  1202. $iLM_PARAM_ActivityEvaluation = optional_param('iLM_PARAM_ActivityEvaluation', 0, PARAM_INT); // 1 - activity evaluated as correct / 0 - activity evaluated as incorrect
  1203. $iLM_PARAM_RealGrade = optional_param('iLM_PARAM_RealGrade', 0, PARAM_FLOAT);
  1204. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  1205. $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)
  1206. $MA_POST_Info = optional_param('MA_POST_Info', NULL, PARAM_FORMAT);
  1207. $MA_POST_SystemData = optional_param('MA_POST_SystemData', NULL, PARAM_FORMAT);
  1208. $return_get_answer = optional_param('return_get_answer', 0, PARAM_INT);
  1209. $msg = '';
  1210. if ($this->activity->get_activity()->store_all_submissions == 1) {
  1211. $newentry = new stdClass();
  1212. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1213. $newentry->userid = $this->userid_iassign;
  1214. $newentry->timecreated = time();
  1215. $newentry->grade = round($iLM_PARAM_RealGrade, 2);
  1216. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1217. $DB->insert_record("iassign_allsubmissions", $newentry);
  1218. }
  1219. // Feedback
  1220. // Activity status: 0 => not post 1; => post; 2 => evaluated as incorrect; 3 => evaluated as correct
  1221. $str_action = "view"; // repeat
  1222. if (strtolower($iassign_ilm->name) == "igeom") {
  1223. }
  1224. $title = get_string('evaluate_iassign', 'iassign');
  1225. print $OUTPUT->header();
  1226. print $OUTPUT->box_start();
  1227. // Action = { view ; repeat ; viewsubmission }
  1228. // * '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")
  1229. // * 'repeat' => student explicitly requested to redo the activiy or enter in the last submission under iLM other then iGeom
  1230. // * 'viewsubmission' => teacher/non editing teacher seeing the learner's activity
  1231. $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;
  1232. $return_last = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . '&nbsp;' . get_string('return_iassign', 'iassign') . "</a>";
  1233. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . '&nbsp;' . get_string('activities_page', 'iassign') . "</a>";
  1234. print '<table width=100% >';
  1235. if ($iLM_PARAM_ArchiveContent == - 1 || empty($iLM_PARAM_ArchiveContent)) { // if ($iLM_PARAM_ActivityEvaluation == -1)
  1236. //TODO alterar aqui???
  1237. $this->write_solution = 0; // necessary in order to take note in Moodle 'grade' system
  1238. // empty_answer_post = No solution was posted.
  1239. if ($comment)
  1240. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</br>' . get_string('confirm_add_comment', 'iassign') . '</td>';
  1241. else
  1242. print '<tr><td colspan=2><br>' . get_string('empty_answer_post', 'iassign') . '</td>';
  1243. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1244. } else {
  1245. if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1) { // iLM with automatic evaluator
  1246. if (intval($iLM_PARAM_ActivityEvaluation) == 1) {
  1247. // Correct answer!!
  1248. //TODO apelei - o melhor e' alterar acima o 'write_solution=0'?
  1249. $this->write_solution = 1; //
  1250. $status = 3;
  1251. $grade_student = $iLM_PARAM_RealGrade; // evaluated as correct solution submitted is assigned the note pattern of activity
  1252. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_correct') . '<br>' . get_string('get_answer_correct', 'iassign') . '</td>';
  1253. // log record
  1254. $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;
  1255. // Trigger module viewed event.
  1256. $event = \mod_iassign\event\submission_created::create(array(
  1257. 'objectid' => $this->iassign->id,
  1258. 'context' => $this->context,
  1259. 'other' => $info
  1260. ));
  1261. $event->add_record_snapshot('course', $this->course);
  1262. $event->trigger();
  1263. } else { // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1264. // Wrong answer...: get_answer_incorrect
  1265. $status = 2;
  1266. $grade_student = $iLM_PARAM_RealGrade; // evaluated as incorrect solution
  1267. $msg = '<tr><td colspan=2>' . iassign_icons::insert('feedback_incorrect') . '<br>' . get_string('get_answer_incorrect', 'iassign') . '</td>';
  1268. // log record
  1269. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('feedback_incorrect', 'iassign') .
  1270. '&nbsp;-&nbsp;' . get_string('grade_iassign', 'iassign') . $grade_student;
  1271. // Trigger module viewed event.
  1272. $event = \mod_iassign\event\submission_created::create(array(
  1273. 'objectid' => $this->iassign->id,
  1274. 'context' => $this->context,
  1275. 'other' => $info
  1276. ));
  1277. $event->add_record_snapshot('course', $this->course);
  1278. $event->trigger();
  1279. } // else if (intval($iLM_PARAM_ActivityEvaluation) == 1)
  1280. // Presents to the learner the result of the automatic evaluate?
  1281. if ($this->activity->get_activity()->show_answer == 0) { // no...
  1282. print '<tr><td width=60% ><strong>' . iassign_icons::insert('post') . get_string('get_answer', 'iassign') . '</strong></td>';
  1283. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1284. print '<tr>';
  1285. // log record
  1286. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer', 'iassign');
  1287. // Trigger module viewed event.
  1288. $event = \mod_iassign\event\submission_created::create(array(
  1289. 'objectid' => $this->iassign->id,
  1290. 'context' => $this->context,
  1291. 'other' => $info
  1292. ));
  1293. $event->add_record_snapshot('course', $this->course);
  1294. $event->trigger();
  1295. } else { // yes!!!
  1296. print '<tr><td width=60% ><strong>' . get_string('auto_result', 'iassign') . '</strong></td>';
  1297. print '<td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1298. print '<tr>';
  1299. print $msg;
  1300. }
  1301. } else { // if ($iassign_ilm->evaluate == 1 && $this->activity->get_activity()->automatic_evaluate == 1)
  1302. $status = 1;
  1303. $grade_student = $iLM_PARAM_RealGrade; // iLM not have automatic evaluator
  1304. print '<tr><td colspan=2>' . iassign_icons::insert('post') . get_string('get_answer_post', 'iassign') . '</td>';
  1305. print '<tr><td width=40% align=right>' . $return_last . '&nbsp;' . $link_return . '</td></tr>';
  1306. print '<tr>';
  1307. // log record
  1308. $info = $iassign->name . "&nbsp;-&nbsp;" . $this->activity->get_activity()->name . "&nbsp;-&nbsp;" . get_string('get_answer_post', 'iassign');
  1309. $event = \mod_iassign\event\submission_created::create(array(
  1310. 'objectid' => $this->iassign->id,
  1311. 'context' => $this->context,
  1312. 'other' => $info
  1313. ));
  1314. $event->add_record_snapshot('course', $this->course);
  1315. $event->trigger();
  1316. } // if ($iassign_ilm->evaluate == 1)
  1317. } // if ($iLM_PARAM_ActivityEvaluation == -1)
  1318. print '</tr></table>';
  1319. print $OUTPUT->box_end();
  1320. // add or update evaluate
  1321. if ($this->write_solution == 1) {
  1322. $timenow = time();
  1323. // new record
  1324. if (!$iassign_submission) {
  1325. $newentry = new stdClass();
  1326. $newentry->userid = $this->userid_iassign;
  1327. // $newentry->userid = $USER->id;
  1328. $newentry->iassign_statementid = $this->activity->get_activity()->id;
  1329. $newentry->timecreated = $timenow;
  1330. $newentry->timemodified = $timenow;
  1331. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1332. $newentry->grade = round($grade_student, 2);
  1333. $newentry->status = $status;
  1334. $newentry->experiment = 1;
  1335. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry)) {
  1336. print_error('error_insert', 'iassign');
  1337. } else {
  1338. // Trigger module viewed event.
  1339. $event = \mod_iassign\event\submission_created::create(array(
  1340. 'objectid' => $this->iassign->id,
  1341. 'context' => $this->context
  1342. ));
  1343. $event->add_record_snapshot('course', $this->course);
  1344. $event->trigger();
  1345. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1346. }
  1347. } elseif ($iassign_submission->status != 3) {
  1348. $newentry = new stdClass();
  1349. $newentry->id = $iassign_submission->id;
  1350. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1351. $newentry->userid = $iassign_submission->userid;
  1352. $newentry->timecreated = $iassign_submission->timecreated;
  1353. $newentry->timemodified = $timenow;
  1354. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1355. $newentry->grade = round($grade_student, 2);
  1356. $newentry->status = $status;
  1357. $newentry->experiment = $iassign_submission->experiment + 1;
  1358. if (!$DB->update_record("iassign_submission", $newentry)) {
  1359. print_error('error_update', 'iassign');
  1360. //D depurar...
  1361. //D $stringAux = "ia.class.php: ".$iLM_PARAM_ArchiveContent."<br/> ".utf8_encode($iLM_PARAM_ArchiveContent)."<br/>".utf8_encode(utf8_encode($iLM_PARAM_ArchiveContent))."<br/>";
  1362. //D $fp = fopen("teste1.txt","w");
  1363. //D fwrite($fp,$stringAux);
  1364. } else {
  1365. // Trigger module viewed event.
  1366. $event = \mod_iassign\event\submission_updated::create(array(
  1367. 'objectid' => $this->iassign->id,
  1368. 'context' => $this->context
  1369. ));
  1370. $event->add_record_snapshot('course', $this->course);
  1371. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1372. }
  1373. } else {
  1374. if ($return_get_answer == 1) {
  1375. $newentry = new stdClass();
  1376. $newentry->id = $iassign_submission->id;
  1377. $newentry->iassign_statementid = $iassign_submission->iassign_statementid;
  1378. $newentry->userid = $iassign_submission->userid;
  1379. $newentry->timecreated = $iassign_submission->timecreated;
  1380. $newentry->timemodified = $timenow;
  1381. $newentry->answer = $iLM_PARAM_ArchiveContent;
  1382. $newentry->grade = round($grade_student, 2);
  1383. $newentry->status = $status;
  1384. $newentry->experiment = $iassign_submission->experiment + 1;
  1385. if (!$DB->update_record("iassign_submission", $newentry))
  1386. print_error('error_update', 'iassign');
  1387. else {
  1388. $event = \mod_iassign\event\submission_updated::create(array(
  1389. 'objectid' => $this->iassign->id,
  1390. 'context' => $this->context
  1391. ));
  1392. $event->add_record_snapshot('course', $this->course);
  1393. $event->trigger();
  1394. $this->update_grade_student($newentry->userid, $newentry->iassign_statementid, $this->iassign->id);
  1395. print $OUTPUT->box_start();
  1396. print "<p>" . get_string('iassign_update', 'iassign') . "</p>";
  1397. print $OUTPUT->box_end();
  1398. }
  1399. } elseif ($return_get_answer == 2) {
  1400. print $OUTPUT->box_start();
  1401. print "<p>" . get_string('iassign_cancel', 'iassign') . "</p>";
  1402. print $OUTPUT->box_end();
  1403. } else {
  1404. print $OUTPUT->box_start();
  1405. print "
  1406. <script type='text/javascript'>
  1407. //<![CDATA[
  1408. function overwrite () {
  1409. document.formEnvio.return_get_answer.value = 1;
  1410. document.formEnvio.submit();
  1411. }
  1412. function nooverwrite () {
  1413. document.formEnvio.return_get_answer.value = 2;
  1414. document.formEnvio.submit();
  1415. }
  1416. //]]>
  1417. </script>";
  1418. $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;
  1419. $get_answer_overwrite = $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  1420. print "<form name='formEnvio' method='post' action='$get_answer_overwrite' enctype='multipart/form-data'>";
  1421. print "<p>" . get_string('last_iassign_correct', 'iassign') . "</p>";
  1422. print "<p>" . get_string('update_iassign', 'iassign') . "</p>";
  1423. print "<input type='hidden' name='iLM_PARAM_ArchiveContent' value='$iLM_PARAM_ArchiveContent'/>
  1424. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value='$iLM_PARAM_ActivityEvaluation'/>
  1425. <input type='hidden' name='MA_POST_Info' value='$MA_POST_Info'/>
  1426. <input type='hidden' name='MA_POST_SystemData' value='$MA_POST_SystemData'/>
  1427. <input type='hidden' name='return_get_answer'/> ";
  1428. print "<input type=button value='" . get_string('yes', 'iassign') . "' onClick = 'overwrite()'
  1429. title='" . get_string('message_update_iassign', 'iassign') . "'/>&nbsp;&nbsp;";
  1430. print "<input type=button value='" . get_string('no', 'iassign') . "' onClick = 'nooverwrite()'
  1431. title='" . get_string('message_no_update_iassign', 'iassign') . "'/>";
  1432. print " </form>";
  1433. print $OUTPUT->box_end();
  1434. }
  1435. }
  1436. } // if ($this->write_solution == 1)
  1437. print $OUTPUT->footer();
  1438. die();
  1439. } // function get_answer()
  1440. /// Export in file the answer of student.
  1441. function export_file_answer () {
  1442. global $DB;
  1443. $iassign_submission_id = optional_param('iassign_submission_id', NULL, PARAM_INT);
  1444. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $iassign_submission_id));
  1445. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid));
  1446. $name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1447. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1448. $extensions = explode(",", $iassign_ilm->extension);
  1449. $iassign_user = $DB->get_record("user", array("id" => $iassign_submission->userid));
  1450. $username = iassign_utils::format_filename($iassign_user->firstname . ' ' . $iassign_user->lastname);
  1451. $name_answer = $username . '-' . $name . '-' . userdate($iassign_submission->timemodified, '%Y%m%d-%H%M') . '.' . $extensions[0];
  1452. header("Pragma: public");
  1453. header("Expires: 0");
  1454. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  1455. header("Cache-Control: private", false);
  1456. header("Content-Type: document/unknown");
  1457. header("Content-Disposition: attachment; filename=\"" . $name_answer . "\";");
  1458. set_time_limit(0);
  1459. print($iassign_submission->answer);
  1460. exit;
  1461. } // function export_file_answer()
  1462. /// Prepare data to static exportation (with course name, iAsssing block name, and exercices names
  1463. // @calledby $this->export_package_answer()
  1464. //TODO Precisa terminar! //TODO_HTML
  1465. function htmlcode_2_export ($course_fullname, $course_id, $iassign_block_id, $iassign_block_name, $array_iassign_name, $array_iassign_id, $userid, $username) {
  1466. $str_html = "<html dir='ltr' lang='pt-br' xml:lang='pt-br'>
  1467. <head>
  1468. <title>" . get_string('pluginname', 'iassign') . "</title>\n"; // 'iAssign: interactive Learning Activities'
  1469. $str_html .= " </head>
  1470. <body>\n";
  1471. $tam = sizeof($array_iassign_name);
  1472. for ($ii=0; $ii<$tam; $ii++) {
  1473. //TODO_HTML completar construir HTML com titulo do exercicio e talvez legar com HTML para abri-lo com o iMA
  1474. }
  1475. $str_html .= "
  1476. </body>\n</html>";
  1477. return $str_html;
  1478. }
  1479. /// Export an package (zip) with all answer of students
  1480. // @calledby $this->action()
  1481. function export_package_answer () {
  1482. global $DB, $CFG, $OUTPUT;
  1483. $iassign_id = optional_param('iassign_id', NULL, PARAM_INT); // ID of iAssign block of activities
  1484. $iassign = $DB->get_record("iassign", array("id" => $iassign_id)); // all data from this block of iAssign activities (table '*_iassign')
  1485. $iassign_block_name = iassign_utils::format_filename($iassign->name);
  1486. //TODO_HTML $this->course: [fullname] => Curso teste [shortname] => cursoteste1 [idnumber]
  1487. //TODO_HTML //echo "<br/>" . $iassign->name . ": <br/>";
  1488. $userid = optional_param('userid', NULL, PARAM_INT);
  1489. $iassign_user = $DB->get_record("user", array("id" => $userid));
  1490. $username = iassign_utils::format_filename($iassign_user->firstname . '_' . $iassign_user->lastname); // user information
  1491. //TODO_HTML echo "username=$username<br/>"; exit;
  1492. $current_date = date('Y_m_d_H');
  1493. $diretorio = $CFG->dataroot . DIRECTORY_SEPARATOR . 'temp' . DIRECTORY_SEPARATOR . 'files' . DIRECTORY_SEPARATOR; // /var/<moodledata>/temp/files/
  1494. // If temporary directory under Moodle data does not exists => create it
  1495. if (!is_dir($diretorio)) {
  1496. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  1497. // created directory with permissions to be seen by everyone
  1498. }
  1499. $zip_filename = $diretorio . 'package_iassign_' . $username . '-' . $iassign_block_name . '_' . $current_date . '.zip';
  1500. if (!is_writable($diretorio)) { // send a highlighted message!
  1501. print_error('error_answer_export_dir', 'iassign'); // Error: the target directory has no permission! Please, send this message to the Moodle admin!
  1502. exit; // just in case
  1503. }
  1504. //MOOC 2014: $zip_filename = $CFG->dataroot . '/temp/ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  1505. $zip = new zip_archive(); // create ZIP
  1506. $zip->open($zip_filename); // open ZIP using the temporary file/directory
  1507. $iassign_statements = $DB->get_records("iassign_statement", array("iassignid" => $iassign_id));
  1508. //TODO $vet_exerc_title = array(); //TODO to be used with 'htmlcode_2_export(...)' - missing: build the HTML and directories linking files
  1509. $vet_student_filename = array();
  1510. $vet_student_content = array();
  1511. foreach ($iassign_statements as $iassign_statement) {
  1512. $activity_name = iassign_utils::format_filename(strip_tags($iassign_statement->name));
  1513. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement->iassign_ilmid));
  1514. //TODO_HTML $vet_exerc_title[] = $iassign_statement->name;
  1515. $extensions = explode(",", $iassign_ilm->extension);
  1516. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $iassign_statement->id, "userid" => $userid));
  1517. if ($iassign_submission) {
  1518. $timemodified = '-' . userdate($iassign_submission->timemodified, '%Y_%m_%d_%H_%M');
  1519. $student_content = $iassign_submission->answer;
  1520. $student_filename = iassign_utils::format_filename($activity_name) . $timemodified . '.' . $extensions[0];
  1521. $resp = $zip->add_file_from_string($student_filename, $student_content); // add file to ZIP
  1522. //$resp = $zip->add_file_from_string($path_dir . $one_file, $destination . $ds . $one_file); //2 Esta versao funciona!
  1523. if ($resp) {
  1524. $vet_student_filename[] = $student_filename;
  1525. $vet_student_content[] = $student_content;
  1526. }
  1527. else { // send a highlighted message!
  1528. print_error('error_answer_export_file', 'iassign'); // Error: fail to insert content to the file
  1529. exit; // just in case
  1530. }
  1531. }
  1532. }
  1533. $zip->close(); // close the ZIP file
  1534. if (count($vet_student_filename)>0) {
  1535. $vet_result = iassign_utils::register_temporary_file($zip_filename, $vet_student_filename, $vet_student_content);
  1536. $result_tf = $vet_result[0];
  1537. $filenameZip = $vet_result[1]->filename;
  1538. }
  1539. iassign_utils::download_file($zip_filename); // download the ZIP file
  1540. exit;
  1541. } // function export_package_answer()
  1542. /// Editing status of interactive activities
  1543. function edit_status () {
  1544. global $USER, $DB, $OUTPUT;
  1545. $newentry = new stdClass();
  1546. $newentry->id = $this->iassign_submission_current;
  1547. $newentry->status = optional_param('return_status', 0, PARAM_INT);
  1548. $iassign_submission = $DB->get_record('iassign_submission', array('id' => $this->iassign_submission_current));
  1549. if ($iassign_submission->status != 0 && $newentry->status == 0)
  1550. $newentry->status = $iassign_submission->status;
  1551. $newentry->teacher = $USER->id;
  1552. if (!$DB->update_record('iassign_submission', $newentry))
  1553. print_error('error_update', 'iassign');
  1554. else {
  1555. // Trigger module viewed event.
  1556. $event = \mod_iassign\event\submission_updated::create(array(
  1557. 'objectid' => $this->iassign->id,
  1558. 'context' => $this->context
  1559. ));
  1560. $event->add_record_snapshot('course', $this->course);
  1561. $event->trigger();
  1562. $this->action = 'viewsubmission';
  1563. $this->view_iassign_current();
  1564. } // if (!$DB->update_record('iassign_submission', $newentry))
  1565. } // function edit_status()
  1566. /// Editing grade of interactive activities
  1567. function edit_grade () {
  1568. global $USER, $DB, $OUTPUT;
  1569. $newgrade = optional_param('return_grade', 0, PARAM_INT);
  1570. if ($newgrade && $newgrade >= 0) {
  1571. $newentry = new stdClass();
  1572. $newentry->id = $this->iassign_submission_current;
  1573. $newentry->grade = optional_param('return_grade', 0, PARAM_INT);
  1574. $newentry->teacher = $USER->id;
  1575. if (!$DB->update_record('iassign_submission', $newentry))
  1576. print_error('error_update', 'iassign');
  1577. else {
  1578. // Trigger module viewed event.
  1579. $event = \mod_iassign\event\submission_updated::create(array(
  1580. 'objectid' => $this->iassign->id,
  1581. 'context' => $this->context
  1582. ));
  1583. $event->add_record_snapshot('course', $this->course);
  1584. $event->trigger();
  1585. }
  1586. } // if ($newgrade >= 0)
  1587. $this->action = 'viewsubmission';
  1588. $this->view_iassign_current();
  1589. }
  1590. /// Add or Edit interactive activities
  1591. // @calledby $this->action()
  1592. function add_edit_iassign () {
  1593. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1594. require_once('iassign_form.php');
  1595. $id = $this->cm->id;
  1596. $iassignid = $this->iassign->id;
  1597. $param = new stdClass();
  1598. $param->action = $this->action; // oculto
  1599. $param->id = $id; // oculto
  1600. $COURSE->cm = $id;
  1601. $COURSE->iassignid = $iassignid;
  1602. $COURSE->iassign_file_id = NULL;
  1603. $context = context_module::instance($this->cm->id);
  1604. $contextuser = context_user::instance($USER->id);
  1605. $component = 'mod_iassign';
  1606. $filearea = 'exercise';
  1607. if (!empty($this->iassign_current))
  1608. $COURSE->iassign_id = $this->iassign_current;
  1609. else
  1610. $COURSE->iassign_id = 0;
  1611. $total_of_activities = 0; // get the total number of activities in this iAssign block
  1612. if ($this->action == 'add') {
  1613. $iassign_data = $DB->get_record("iassign", array('id' => $iassignid));
  1614. $params = array('iassignid' => $iassignid);
  1615. $query_str = "SELECT s.id, s.name, s.dependency FROM {iassign_statement} s WHERE s.iassignid = :iassignid ORDER BY s.position ASC";
  1616. $iassign_statement = $DB->get_records_sql($query_str, $params); //
  1617. $total_of_activities = count($iassign_statement);
  1618. $param->iassignid = $iassignid;
  1619. $param->name = "";
  1620. $param->oldname = "";
  1621. $param->type_iassign = 3;
  1622. $param->proposition = "";
  1623. $author = $DB->get_record("user", array("id" => $USER->id));
  1624. $param->author_name = $author->firstname . '&nbsp;' . $author->lastname;
  1625. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1626. $param->author = $param->author_name;
  1627. $param->author_modified = $param->author_modified_name;
  1628. $COURSE->iassign_list = array();
  1629. $param->iassign_list = array();
  1630. if ($iassign_statement) {
  1631. foreach ($iassign_statement as $iassign) {
  1632. $iassignid = $iassign->id;
  1633. $param->iassign_list[$iassignid] = 0;
  1634. $COURSE->iassign_list[$iassignid] = new stdClass();
  1635. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1636. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1637. $COURSE->iassign_list[$iassignid]->enable = 1;
  1638. } // foreach ($iassign_statement as $iassign)
  1639. }
  1640. $param->iassign_ilmid = 0;
  1641. //echo "locallib.php: add_edit_iassign(): add<br/>";
  1642. $param->file = 0;
  1643. $param->fileold = 0;
  1644. $param->filename = "";
  1645. $param->grade = $iassign_data->grade;
  1646. $param->timemodified = time();
  1647. $param->timecreated = time();
  1648. $param->timeavailable = $iassign_data->timeavailable;
  1649. $param->timedue = $iassign_data->timedue;
  1650. $param->preventlate = $iassign_data->preventlate;
  1651. $param->test = $iassign_data->test;
  1652. $param->special_param1 = 0;
  1653. $param->visible = 1;
  1654. $param->max_experiment = $iassign_data->max_experiment;
  1655. $param->dependency = 0;
  1656. $param->automatic_evaluate = 1;
  1657. $param->show_answer = 1;
  1658. } // if ($this->action == 'add')
  1659. elseif ($this->action == 'edit') {
  1660. $COURSE->iassign_list = array();
  1661. $this_activity = $this->activity->get_activity();
  1662. if ($this_activity != null) {
  1663. //2019 $iassign_statement_current = $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1664. $iassign_statement_current = $this_activity; // $DB->get_record("iassign_statement", array("id" => $this_activity->id));
  1665. $param->iassign_id = $iassign_statement_current->id; // oculto
  1666. $param->iassignid = $iassign_statement_current->iassignid; // oculto
  1667. $param->name = $iassign_statement_current->name;
  1668. $param->oldname = $iassign_statement_current->name;
  1669. $param->type_iassign = $iassign_statement_current->type_iassign;
  1670. $param->store_all_submissions = $iassign_statement_current->store_all_submissions;
  1671. //2019: Moodle 3 uses proposition in 'textarea' as "('text' => <text>, 'format' => '')
  1672. //2019 $param->proposition = $iassign_statement_current->proposition;
  1673. $param->proposition = array('text' => $iassign_statement_current->proposition, ''); //'format' => $instance->introformat
  1674. $param->author_name = $iassign_statement_current->author_name; // oculto
  1675. $param->author = $iassign_statement_current->author_name;
  1676. $author = $DB->get_record("user", array('id' => $USER->id));
  1677. $param->author_modified_name = $author->firstname . '&nbsp;' . $author->lastname;
  1678. $param->author_modified = $param->author_modified_name;
  1679. $dependency = explode(';', $iassign_statement_current->dependency);
  1680. $param->iassign_list = array();
  1681. $str_query = "SELECT * FROM {iassign_statement} s WHERE s.iassignid = '$iassignid' AND s.id!='$iassign_statement_current->id' AND s.dependency!=0";
  1682. $iassign_statement_dependency = $DB->get_records_sql($str_query);
  1683. $array_dependency = array();
  1684. $subdependency = "";
  1685. $sub_subdependency = "";
  1686. // dependent on this exercise
  1687. if ($iassign_statement_dependency) {
  1688. $subdependency .= $this->search_dependency($iassign_statement_current->id, $iassign_statement_dependency);
  1689. // to whom this exercise depends
  1690. foreach ($inter as $tmp)
  1691. $sub_subdependency .= $this->search_sub_dependency($tmp);
  1692. $list_dependency = $subdependency . $sub_subdependency;
  1693. $array_dependency = explode(";", $list_dependency);
  1694. }
  1695. // Get all activity with the same iLM - iassignid
  1696. $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";
  1697. $all_others_iassign_statement = $DB->get_records_sql($str_query);
  1698. $total_of_activities = count($all_others_iassign_statement) + 1;
  1699. $inter = array();
  1700. if ($all_others_iassign_statement) {
  1701. foreach ($all_others_iassign_statement as $iassign)
  1702. if (in_array($iassign->id, $dependency))
  1703. $inter[] = $iassign->id;
  1704. }
  1705. if ($all_others_iassign_statement) {
  1706. foreach ($all_others_iassign_statement as $iassign) {
  1707. $iassignid = $iassign->id;
  1708. $COURSE->iassign_list[$iassignid] = new stdClass();
  1709. $COURSE->iassign_list[$iassignid]->name = $iassign->name;
  1710. $COURSE->iassign_list[$iassignid]->id = $iassignid;
  1711. if (in_array($iassignid, $dependency))
  1712. $param->iassign_list[$iassignid] = 1;
  1713. else
  1714. $param->iassign_list[$iassignid] = 0;
  1715. if (in_array($iassignid, $array_dependency))
  1716. $COURSE->iassign_list[$iassignid]->enable = 0;
  1717. else
  1718. $COURSE->iassign_list[$iassignid]->enable = 1;
  1719. } // foreach ($all_others_iassign_statement as $iassign)
  1720. }
  1721. $param->iassign_ilmid = $iassign_statement_current->iassign_ilmid;
  1722. $param->fileold = 0;
  1723. $param->file = 0; //TODO Criar campo 'iassign_statement.filesid' para registar 'files.id' - abaixo faz '$file->get_id();'
  1724. $param->filename = '';
  1725. $param->grade = $iassign_statement_current->grade;
  1726. $param->timecreated = $iassign_statement_current->timecreated; // oculto
  1727. $param->timeavailable = $iassign_statement_current->timeavailable;
  1728. $param->timedue = $iassign_statement_current->timedue;
  1729. $param->preventlate = $iassign_statement_current->preventlate;
  1730. $param->test = $iassign_statement_current->test;
  1731. $param->special_param1 = $iassign_statement_current->special_param1;
  1732. $param->position = $iassign_statement_current->position; // oculto
  1733. $param->visible = $iassign_statement_current->visible;
  1734. $param->max_experiment = $iassign_statement_current->max_experiment;
  1735. $param->automatic_evaluate = $iassign_statement_current->automatic_evaluate;
  1736. $param->show_answer = $iassign_statement_current->show_answer;
  1737. $fs = get_file_storage(); // Get reference to all files in Moodle data
  1738. $files = $fs->get_area_files($context->id, $component, $filearea, $iassign_statement_current->file);
  1739. if ($files) {
  1740. foreach ($files as $file) {
  1741. if ($file->get_filename() != '.') {
  1742. $param->filename = $file->get_filename();
  1743. $param->file = $file->get_id();
  1744. $param->fileold = $file->get_id();
  1745. $COURSE->iassign_file_id = $file->get_id();
  1746. }
  1747. }
  1748. }
  1749. //TODO //MOOC2014 -- inicio
  1750. //D $iassign_ilm_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $iassign_statement_current->id));
  1751. //D if ($iassign_ilm_configs) {
  1752. //D foreach ($iassign_ilm_configs as $iassign_ilm_config)
  1753. //D $param->{'param_'.$iassign_ilm_config->iassign_ilm_configid} = $iassign_ilm_config->param_value;
  1754. //D } //MOOC2014 -- fim
  1755. } // if ($this_activity != null)
  1756. } // elseif ($this->action == 'edit')
  1757. // Get all iActivity in the iAssign block with id = $this->iassign->id
  1758. // It could be used to define dependency of the current activity (considering those list $iassign_list)
  1759. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array($this->iassign->id), 'position ASC');
  1760. //D echo "locallib.php: add_edit_iassign(): this->iassign->id=" . $this->iassign->id . "<br/>";
  1761. //D foreach ($iassign_list as $item) echo " - id=" . $item->id . ", name=" . $item->name . ", iassignid=" . $item->iassignid . ", type_iassign=" . $item->type_iassign . "<br/>";
  1762. // if ($iassign_list) { $end_list = array_pop($iassign_list); $param->position = $end_list->position + 1; } else $param->position = 1;
  1763. $param->position = $total_of_activities;
  1764. $mform = new mod_iassign_form(null, null, null, null, array('id'=>'mform1'));
  1765. $mform->set_data($param);
  1766. if ($mform->is_cancelled()) {
  1767. $this->return_home_course('iassign_cancel');
  1768. exit;
  1769. }
  1770. else { // if ($mform->is_cancelled())
  1771. $result = $mform->get_data();
  1772. // echo "locallib.php: add_edit_iassign(): result="; print_r($result); echo "<br/>";
  1773. if ($result) {
  1774. $result->context = $context;
  1775. if ($result->type_iassign == 1 || $result->type_iassign == 2)
  1776. $result->grade = 0;
  1777. if ($result->type_iassign == 1) {
  1778. $result->automatic_evaluate = 0;
  1779. $result->show_answer = 0;
  1780. }
  1781. elseif ($result->automatic_evaluate == 0)
  1782. $result->show_answer = 0;
  1783. // $_POST['iassign_list']
  1784. $result->iassign_list = optional_param_array('iassign_list', array(), PARAM_RAW);
  1785. if ($result->iassign_list) {
  1786. foreach ($result->iassign_list as $key => $value)
  1787. $result->dependency .= $key . ';';
  1788. }
  1789. else
  1790. $result->dependency = 0;
  1791. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  1792. //TODO Then get it directly from the form data $_POST!
  1793. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here 'function new_iassign($param)'
  1794. if (!isset($result->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  1795. $result->iassign_ilmid = $_POST['iassign_ilmid'];
  1796. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $result->iassign_ilmid));
  1797. if ($this->action == 'add') {
  1798. $iassign_statement_name = $DB->get_records('iassign_statement', array('iassignid' => $result->iassignid, 'name' => $result->name));
  1799. if ($iassign_statement_name) {
  1800. $this->return_home_course('error_iassign_name');
  1801. die();
  1802. }
  1803. // Really insert the new iActivity in table '*_iassign_statement'
  1804. $iassignid = $this->activity->new_iassign($result); // class activity : function new_iassign($param)
  1805. $this->activity->add_calendar($iassignid); ///line 3584 of /mod/iassign/locallib.php: call to calendar_event::create()
  1806. // Trigger module viewed event.
  1807. $event = \mod_iassign\event\iassign_created::create(array(
  1808. 'objectid' => $iassignid,
  1809. 'context' => $context
  1810. ));
  1811. $event->add_record_snapshot('course', $this->course);
  1812. $event->trigger();
  1813. $this->return_home_course('iassign_add');
  1814. } // if ($this->action == 'add')
  1815. elseif ($this->action == 'edit') {
  1816. $iassignid = $this->activity->update_iassign($result);
  1817. $this->activity->update_calendar($iassignid, $result->oldname);
  1818. // Trigger module viewed event.
  1819. $event = \mod_iassign\event\iassign_updated::create(array(
  1820. 'objectid' => $iassignid,
  1821. 'context' => $context
  1822. ));
  1823. $event->add_record_snapshot('course', $this->course);
  1824. $event->trigger();
  1825. $this->return_home_course('iassign_update');
  1826. } // elseif ($this->action == 'edit')
  1827. die();
  1828. } // if ($result)
  1829. } // else if ($mform->is_cancelled())
  1830. print $OUTPUT->header();
  1831. $mform->display();
  1832. print $OUTPUT->footer();
  1833. die();
  1834. } // function add_edit_iassign()
  1835. /// Search for dependencies
  1836. function search_dependency ($search_iassing_id, $iassign_statement) {
  1837. global $DB, $OUTPUT;
  1838. $dependency = "";
  1839. if ($iassign_statement)
  1840. foreach ($iassign_statement as $iassign) {
  1841. $inter_dependency = explode(';', $iassign->dependency);
  1842. if (in_array($search_iassing_id, $inter_dependency)) {
  1843. $dependency .= $iassign->id . ";";
  1844. $dependency .= $this->search_dependency($iassign->id, $iassign_statement);
  1845. } // if (in_array($search_iassing_id, $inter_dependency))
  1846. } // foreach ($iassign_statement as $iassign)
  1847. return $dependency;
  1848. }
  1849. /// Search for "sub"dependency
  1850. function search_sub_dependency ($search_iassing_id) {
  1851. global $DB, $OUTPUT;
  1852. $iassign_statement = $DB->get_record("iassign_statement", array("id" => $search_iassing_id));
  1853. $dependency = "";
  1854. if ($iassign_statement) {
  1855. $inter_dependency = explode(';', $iassign_statement->dependency);
  1856. foreach ($inter_dependency as $tmp) {
  1857. if ($tmp != 0)
  1858. $dependency .= $tmp . ";";
  1859. $dependency .= $this->search_sub_dependency($tmp);
  1860. } // foreach ($inter_dependency as $tmp)
  1861. } // if ($iassign_statement)
  1862. return $dependency;
  1863. }
  1864. // Warning message
  1865. static function warning_message_iassign ($strcode) {
  1866. return "<div class='warning' style='display:inline; font-weight: bold; color:#a00'>" . get_string($strcode, 'iassign') . "</div>\n";
  1867. }
  1868. /// Update grade of iAssign
  1869. // Called always any iAssign activity is created
  1870. // @see /mod/iassign/view.php: call to iassign->iassign(): starting point
  1871. static function update_grade_iassign ($iassignid) {
  1872. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  1873. require_once($CFG->libdir . '/gradelib.php');
  1874. //D $sum_grade = $DB->get_records_sql ( "SELECT SUM(grade) as total
  1875. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1876. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1877. // Each iAssign item is associated with one item on the "gradebook"
  1878. // Sum all '*_iassign_statement' associated with one item in '*_grade_items': iassignid AND type_iassign=3
  1879. //$sum_grade = 0;
  1880. //$grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1881. //foreach($grade as $tmp) {
  1882. // $sum_grade += $tmp->grade;
  1883. // }
  1884. //1 Solution 1
  1885. //1 $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3)); //1
  1886. //1 $sum_grade = 0; //1
  1887. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; } //1
  1888. //2 Solution 2
  1889. $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
  1890. //2 foreach ($array_sum_grade as $array_item) { $sum_grade = $array_item->total; break; } // nao necessario, basta 'key(...)' abaixo
  1891. if (key($array_sum_grade))
  1892. $sum_grade = key($array_sum_grade); //2
  1893. else
  1894. $sum_grade = 0; //2
  1895. $grade_iassign = $DB->get_record("iassign", array("id" => $iassignid));
  1896. $grades = NULL;
  1897. $params = array('itemname' => $grade_iassign->name);
  1898. $params['iteminstance'] = $iassignid;
  1899. $params['gradetype'] = GRADE_TYPE_VALUE;
  1900. //2016 if ($sum_grade != 0) {
  1901. $params['grademax'] = $sum_grade;
  1902. $params['rawgrademax'] = $sum_grade;
  1903. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1904. $params['grademin'] = 0;
  1905. // @calls /lib/gradelib.php: call to grade_item->insert()
  1906. //TODO: is there any error here in Moodle version 3.0?
  1907. //TODO: Incorrect property 'grademax' found when inserting grade object
  1908. //TODO: line 899 of /mod/iassign/locallib.php: call to grade_update()
  1909. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1910. }
  1911. /// Update grade of student
  1912. function update_grade_student ($userid, $iassign_statementid, $iassignid) {
  1913. global $CFG, $DB, $OUTPUT;
  1914. require_once($CFG->libdir . '/gradelib.php');
  1915. $grade_iassign = $DB->get_record('iassign', array('id' => $iassignid));
  1916. // Review all the student submission for this iAssign activity
  1917. $grade_iassign_statements = $DB->get_records('iassign_statement', array('iassignid' => $iassignid));
  1918. $total_grade = 0;
  1919. foreach ($grade_iassign_statements as $grade_iassign_statement) {
  1920. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $grade_iassign_statement->id, 'userid' => $userid));
  1921. if ($iassign_submission)
  1922. $total_grade += $iassign_submission->grade;
  1923. } // foreach ($grade_iassign_statements as $grade_iassign_statement)
  1924. //D $sum_grade = $DB->get_records_sql("SELECT SUM(grade) as total
  1925. //D FROM {$CFG->prefix}iassign_statement s WHERE s.iassignid = '$iassignid' AND s.type_iassign=3" );
  1926. //TODO: REVIEW: wich one is more efficienty, '$DB->get_records' geting objects or '$DB->get_records' with 'foreach'?
  1927. //1 $sum_grade = 0; $grade = $DB->get_records('iassign_statement', array('iassignid' => $iassignid, 'type_iassign' => 3));
  1928. //1 foreach ($grade as $tmp) { $sum_grade += $tmp->grade; }
  1929. $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
  1930. if (key($array_sum_grade))
  1931. $sum_grade = key($array_sum_grade); //2
  1932. else
  1933. $sum_grade = 0; //2
  1934. $grades['userid'] = $userid;
  1935. $grades['rawgrade'] = $total_grade; // sum of all submissions for this iAssign activity
  1936. $params = array('itemname' => $grade_iassign->name);
  1937. $params['iteminstance'] = $iassignid;
  1938. $params['gradetype'] = GRADE_TYPE_VALUE;
  1939. //2016 if ($sum_grade != 0) { // depois eliminar comentario
  1940. $params['grademax'] = $sum_grade;
  1941. $params['rawgrademax'] = $sum_grade;
  1942. //2016 } else { $params['grademax'] = 0; $params['rawgrademax'] = 0; }
  1943. grade_update('mod/iassign', $grade_iassign->course, 'mod', 'iassign', $iassignid, 0, $grades, $params);
  1944. }
  1945. /// Display caption of icons
  1946. function view_legend_icons () {
  1947. global $USER, $CFG, $DB, $OUTPUT;
  1948. $id = $this->cm->id;
  1949. if ($this->action == 'print')
  1950. print '<table border=1 width=100%><tr>';
  1951. else
  1952. print '<table width=100%><tr>';
  1953. print '<td >';
  1954. if ($this->action != 'print')
  1955. print $OUTPUT->help_icon('legend', 'iassign');
  1956. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  1957. // $imagetext = '');
  1958. print '<strong>' . get_string('legend', 'iassign') . '</strong>';
  1959. print '&nbsp;' . iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign');
  1960. print '&nbsp;' . iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign');
  1961. print '&nbsp;' . iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign');
  1962. print '&nbsp;' . iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign');
  1963. print '&nbsp;' . iassign_icons::insert('comment_unread') . '&nbsp;' . get_string('comment_unread', 'iassign');
  1964. if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report') {
  1965. print '&nbsp;' . iassign_icons::insert('comment_read') . '&nbsp;' . get_string('comment_read', 'iassign');
  1966. print '</td>' . "\n";
  1967. if ($this->action != 'print') {
  1968. $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>";
  1969. $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>";
  1970. $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>";
  1971. $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>";
  1972. $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>";
  1973. print '<td width=10% align="right">' . $link_stats . '</td>' . "\n";
  1974. print '<td width=10% align="right">' . $link_export . '</td>' . "\n";
  1975. print '<td width=15% align="right">' . $link_auto_evaluate . '</td>' . "\n";
  1976. print '<td width=16% align="right">' . $link_all_submissions_manager . '</td>' . "\n";
  1977. print '<td width=15% align="right">' . $link_print . '</td>' . "\n";
  1978. } // if ($this->action != 'print')
  1979. print '</tr></table>' . "\n";
  1980. } // if (has_capability('mod/iassign:viewreport', $this->context, $USER->id) && $this->action == 'report')
  1981. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) {
  1982. $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>";
  1983. print '<td width=15% align="right">' . $link_stats . '</td>' . "\n";
  1984. print '</tr></table>' . "\n";
  1985. } // elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  1986. else
  1987. print '</td></tr></table>' . "\n";
  1988. } // function view_legend_icons()
  1989. /// Display activity current
  1990. // @calledby view() -> action() : when student do/redo activity and teacher see student answer
  1991. function view_iassign_current () {
  1992. global $USER, $CFG, $COURSE, $DB, $OUTPUT, $PAGE;
  1993. $id = $this->cm->id;
  1994. $iassignid = $this->iassign->id;
  1995. $only_one_send_button = 0; // to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  1996. $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
  1997. // 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 ...
  1998. $iassign_statement_activity_item = $this->activity->get_activity(); // search data of current activity: the teacher activity model
  1999. if (!$iassign_statement_activity_item) {
  2000. print $OUTPUT->header();
  2001. \core\notification::error(get_string('activity_not_found', 'iassign'));
  2002. print $OUTPUT->footer();
  2003. exit;
  2004. }
  2005. $ilm = new ilm($iassign_statement_activity_item->iassign_ilmid);
  2006. $ilm_name = '';
  2007. if ($ilm->ilm)
  2008. $ilm_name = strtolower($ilm->ilm->name); // class ilm has a unique property ('ilm'), get the iLM name
  2009. // 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
  2010. $allow_resubmission = (substr($ilm_name, 0, 5) != "igeom" ? 1 : 0);
  2011. // log record
  2012. $info = $iassign->name . ":" . $iassign_statement_activity_item->name;
  2013. //Trigger module viewed event.
  2014. $event = \mod_iassign\event\submission_viewed::create(array(
  2015. 'objectid' => $iassign->id,
  2016. 'context' => $this->context,
  2017. 'other' => $info
  2018. ));
  2019. $event->add_record_snapshot('course', $this->course);
  2020. $event->trigger();
  2021. // Search of iLM data used in the current activity
  2022. $iassign_ilm = $DB->get_record("iassign_ilm", array("id" => $iassign_statement_activity_item->iassign_ilmid));
  2023. // Add actual activity to navbar:
  2024. $actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  2025. $PAGE->navbar->add($iassign_statement_activity_item->name, $actual_link);
  2026. print $OUTPUT->header();
  2027. if ($this->action == 'viewsubmission') {
  2028. if (!empty($this->iassign_submission_current) || $this->iassign_submission_current != 0)
  2029. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); // data about activity current
  2030. else
  2031. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2032. } else {
  2033. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $this->userid_iassign)); // data about student solution
  2034. }
  2035. if ($iassign_submission)
  2036. $this->update_comment($iassign_submission->id);
  2037. $file = $iassign_statement_activity_item->file;
  2038. // 1 when open previous file; 2 when the activity is redone!; 3 when the teacher enter in the activity
  2039. // 1 => locallib.php: view_iassign_current(): action=view will set write_solution=0!!!!!
  2040. // 2 => locallib.php: view_iassign_current(): action=repeat will set write_solution=0!!!!!
  2041. // 3 => locallib.php: view_iassign_current(): action=viewsubmission will set write_solution=0!!!!!
  2042. $this->bottonPost = 0; // hide submit button
  2043. //xxx $this->write_solution = 0; // disable recording solution (however, iVProg allow the learner to edit previou solution)
  2044. $this->view_iassign = false; // disable visualization of activity
  2045. $repeat = "";
  2046. $last_iassign = "";
  2047. $student_answer = "";
  2048. $comment = "";
  2049. // *** Teacher access (view learner's submission)
  2050. if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2051. //TODO leo Verificar se o correto eh '$this->context' ou '$USER->context' como deixei
  2052. // It is not 'viewsubmission' and it is teacher or 'non editing teacher'?
  2053. // ---> access teacher for test
  2054. if ($iassign_statement_activity_item->type_iassign != 1) // type_iassign=1 => activity of type "example" - not submit button for submission
  2055. $this->bottonPost = 1;
  2056. print $OUTPUT->box('<p><strong>' . get_string('area_specific_teacher', 'iassign') . '</strong></p>');
  2057. $this->activity->view_dates();
  2058. $USER->iassignEdit = $this->bottonPost;
  2059. $this->activity->show_info_iassign();
  2060. if ($iassign_submission) {
  2061. //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;
  2062. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2063. } else {
  2064. //xxx $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2065. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&userid_iassign=" . $USER->id;
  2066. }
  2067. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2068. //if ($ilm->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id))
  2069. // Prepare tags to present the iLM
  2070. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true));
  2071. } // if (($this->action != 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2072. // *** (end) Teacher access (view the activity)
  2073. // *** Teacher access (view learner's submission to the activity)
  2074. elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id)) {
  2075. // It is teacher or 'nonediting teacher' that can evaluate
  2076. // ----> area teacher evaluate
  2077. $row = optional_param('row', 0, PARAM_INT);
  2078. $column = optional_param('column', 0, PARAM_INT);
  2079. $link_next = iassign_icons::insert('right_disable');
  2080. $link_previous = iassign_icons::insert('left_disable');
  2081. $link_up = iassign_icons::insert('up_disable');
  2082. $link_down = iassign_icons::insert('down_disable');
  2083. // next_activity
  2084. if ($USER->matrix_iassign[$row][$column]->iassign_next != - 1) {
  2085. $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);
  2086. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_activity')) . "</a>";
  2087. }
  2088. // previous_activity
  2089. if ($USER->matrix_iassign[$row][$column]->iassign_previous != - 1) {
  2090. $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);
  2091. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_activity')) . "</a>";
  2092. }
  2093. // previous_student
  2094. if ($USER->matrix_iassign[$row][$column]->user_next != - 1) {
  2095. $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);
  2096. $link_down = "<a href='" . $url_down . "'>" . (iassign_icons::insert('previous_student')) . "</a>";
  2097. }
  2098. // next_student
  2099. if ($USER->matrix_iassign[$row][$column]->user_previous != - 1) {
  2100. $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);
  2101. $link_up = "<a href='" . $url_up . "'>" . (iassign_icons::insert('next_student')) . "</a>";
  2102. }
  2103. if ($iassign_submission) {
  2104. $student_answer = $iassign_submission->answer;
  2105. }
  2106. $last_iassign = get_string('last_iassign', 'iassign');
  2107. $user_data = $DB->get_record("user", array('id' => $this->userid_iassign));
  2108. // Messages related to due date (and user role)
  2109. $this->activity->view_dates();
  2110. print $OUTPUT->box_start();
  2111. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2112. print '<td width=80%><font color="blue"><strong>' . get_string('area_available', 'iassign') . '</strong></font><br>' . "\n";
  2113. print $OUTPUT->user_picture($user_data);
  2114. print '&nbsp;' . $user_data->firstname . '&nbsp;' . $user_data->lastname;
  2115. print '</td>' . "\n";
  2116. print '<td width=20% align=right>' . "\n";
  2117. print '<table width=50 cellpadding="0">';
  2118. print '<tr><td colspan=2 align=center>' . $link_up . '</td></tr>' . "\n";
  2119. print '<tr><td align=center>' . $link_previous . '</td>' . "\n";
  2120. print '<td align=center>' . $link_next . '</td></tr>' . "\n";
  2121. print '<td colspan=2 align=center>' . $link_down . '</td></tr>' . "\n";
  2122. print '</table>' . "\n";
  2123. print '</td></tr></table>' . "\n";
  2124. print $OUTPUT->box_end();
  2125. print $OUTPUT->box_start();
  2126. print '<table width=100% border=0 valign="top"><tr>' . "\n";
  2127. print '<td width=60% valign="top">' . "\n";
  2128. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2129. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2130. if ($iassign_statement_activity_item->automatic_evaluate == 1)
  2131. $resp = get_string('yes');
  2132. else
  2133. $resp = get_string('no');
  2134. print '<p>' . get_string('automatic_evaluate', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2135. if ($iassign_statement_activity_item->show_answer == 1)
  2136. $resp = get_string('yes');
  2137. else
  2138. $resp = get_string('no');
  2139. print '<p>' . get_string('show_answer', 'iassign') . '&nbsp;' . $resp . '</p>' . "\n";
  2140. print '</td>';
  2141. if ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2142. print '<td width=40% valign="top" align="left">';
  2143. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2144. // check status of solution sent by the student
  2145. if ($iassign_submission) {
  2146. switch ($iassign_submission->status) {
  2147. case 3 :
  2148. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2149. break;
  2150. case 2 :
  2151. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2152. break;
  2153. case 1 :
  2154. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2155. break;
  2156. default :
  2157. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2158. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2159. } // switch ($iassign_submission->status)
  2160. }
  2161. else { // if ($iassign_submission)
  2162. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2163. $last_iassign = get_string('no_iLM_PARAM_ArchiveContent', 'iassign');
  2164. }
  2165. // update_status
  2166. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2167. $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);
  2168. print " <script type='text/javascript'>
  2169. //<![CDATA[
  2170. function overwriteStatus (newstatus) {
  2171. if (confirm('" . get_string('confirm_change_situation', 'iassign') . "')) {
  2172. document.formEditStatus.return_status.value=newstatus;
  2173. document.formEditStatus.submit();
  2174. }
  2175. else
  2176. document.formEditStatus.return_status.value=-1;
  2177. }
  2178. //]]>
  2179. </script>";
  2180. print "<form name='formEditStatus' method='post' action='$edit_status' enctype='multipart/form-data'>\n";
  2181. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>\n";
  2182. 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";
  2183. print " <input type='hidden' name='return_status'>\n";
  2184. print "</form>\n";
  2185. print '<p><strong>' . get_string('grade_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->grade . "</p>\n";
  2186. print '<p><strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $iassign_statement_activity_item->grade . "</p>\n";
  2187. $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);
  2188. print "
  2189. <script type='text/javascript'>
  2190. //<![CDATA[
  2191. function overwriteGrade (newgrade,maxgrade) {
  2192. if (newgrade<0 || newgrade>maxgrade) {
  2193. alert('" . get_string('erro_grade', 'iassign') . " '+maxgrade)
  2194. document.formEditGrade.return_grade.value=-1;
  2195. document.formEditGrade.submit();
  2196. }
  2197. else {
  2198. document.formEditGrade.return_grade.value=newgrade;
  2199. document.formEditGrade.submit();
  2200. }
  2201. }
  2202. //]]>
  2203. </script>";
  2204. print "<form name='formEditGrade' method='post' action='$edit_grade' enctype='multipart/form-data'>\n";
  2205. print ' <font color="blue"><strong>' . get_string('changeto', 'iassign') . "</strong></font>" . "\n";
  2206. print " <input type='text' name='grade' size='6'>";
  2207. print " <input type='hidden' name='return_grade'> ";
  2208. 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";
  2209. print "</form>";
  2210. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_answer&iassign_submission_id=" . $iassign_submission->id . "&id=" . $id;
  2211. print '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment . ' <a href="' . $url_answer . '">' . iassign_icons::insert('download_assign') . '</a></p>';
  2212. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>';
  2213. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2214. if ($teacher)
  2215. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n";
  2216. } // if ($iassign_submission->experiment > 0)
  2217. print '</td>';
  2218. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2219. print '</tr></table>';
  2220. print $OUTPUT->box_end();
  2221. $USER->iassignEdit = $this->bottonPost;
  2222. if ($iassign_submission && $allow_resubmission) {
  2223. // Put the iLM to
  2224. print $OUTPUT->box_start();
  2225. print '<p><strong>' . $last_iassign . '</strong></p>';
  2226. //d if ($ilm->confirms_jar ( $iassign_statement_activity_item->file, $iassign_ilm->file_jar, $this->cm->id )) {
  2227. $enderecoPOST = "";
  2228. // Prepare tags to present the iLM
  2229. print $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, false);
  2230. //d } // if ($this->confirms_jar($iassign_statement_activity_item->file, $iassign_ilm->file_jar))
  2231. print $OUTPUT->box_end();
  2232. } else { // if ($iassign_submission && $allow_resubmission) - techer view student answer
  2233. // ATTENTION: exception used by iGeom (exercise with "script")
  2234. $loadTeacherActivity = false; // use 'true' whenever 'special_param1 == 1'
  2235. if (substr($ilm_name, 0, 5)=="igeom") {
  2236. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2237. $loadTeacherActivity = true;
  2238. }
  2239. print $OUTPUT->box('<p><strong>' . $last_iassign . '</strong></p>' . "\n");
  2240. if (!isset($enderecoPOST)) $enderecoPOST = "";
  2241. // Prepare tags to present the iLM
  2242. print $OUTPUT->box($ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity));
  2243. }
  2244. //2020 Eliminei daqui o codigo para colocar o quadro com area para enivar e ler comentarios
  2245. //2020 Estava subordinado ao: elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2246. //2020 e com isso NAO permitia aluno ter o quadro para envio!
  2247. //2020 Foi para final dessa funcao 'view_iassign_current()'
  2248. } // elseif (($this->action == 'viewsubmission') && has_capability('mod/iassign:evaluateiassign', $USER->context, $USER->id))
  2249. // *** (end) Teacher access (view learner's submission to the activity)
  2250. // *** Student access (view the activity)
  2251. elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id)) {
  2252. // It could be the learner (he could send or resend the activity)
  2253. // ---> access student
  2254. $time_now = time();
  2255. if ($iassign_statement_activity_item->type_iassign == 1) { // type_iassign=1 => activity of type "exemple" - no submit button
  2256. // activity of type example - not submit button for submission
  2257. $this->view_iassign = true;
  2258. //TODO rever esta condicao para iMA que nao fazem autoavaliacao
  2259. } elseif ($iassign_statement_activity_item->type_iassign == 2 && $iassign_ilm->evaluate == 1) {
  2260. // activity of type test - iLM automatic evaluator - submit button for submission
  2261. if ($iassign_statement_activity_item->timeavailable < $time_now && $iassign_statement_activity_item->timedue > $time_now) { // activity within of deadline
  2262. $this->bottonPost = 1;
  2263. $this->view_iassign = true;
  2264. } else
  2265. $this->view_iassign = false;
  2266. } elseif ($iassign_statement_activity_item->type_iassign == 3) { // type_iassign=3 => activity of type "exercise" - submit button and automatic evaluation
  2267. // activity of type exercise (learner can send his answer, if yet open...)
  2268. $this->view_iassign = true;
  2269. if ($iassign_statement_activity_item->timeavailable > $time_now) // due date expired
  2270. $this->view_iassign = false;
  2271. elseif ($iassign_statement_activity_item->timedue > $time_now || $iassign_statement_activity_item->preventlate == 1) { // activity within due date
  2272. $this->bottonPost = 1; // allow the submit button
  2273. // Look at table 'iassign_submission' ('iassign_submission.experiment' is the number of submissions)
  2274. $repeat_title = ' title="' . get_string('repeat_alt', 'iassign') . '" '; // 'Use this button to redo the activity'
  2275. if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission)) {
  2276. if (!$iassign_submission) {
  2277. $str_iassign_submission_id = '';
  2278. $str_iassign_submission_answer = '';
  2279. }
  2280. else {
  2281. $str_iassign_submission_id = $iassign_submission->id;
  2282. $str_iassign_submission_answer = $iassign_submission->answer;
  2283. }
  2284. if ($this->action != 'repeat') {
  2285. $repeat = "<a href='view.php?action=repeat&id="
  2286. . $id . "&userid_iassign=" . $USER->id . "&iassign_current="
  2287. . $this->activity->get_activity()->id . "&iassign_submission_current="
  2288. . $str_iassign_submission_id . "'" . $repeat_title . ">"
  2289. . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2290. }
  2291. $this->bottonPost = 1;
  2292. $this->write_solution = 1; // can register his submission
  2293. $student_answer = $str_iassign_submission_answer;
  2294. }
  2295. else { // if (!$iassign_submission || $this->action == 'repeat' || ($iassign_submission && $allow_resubmission))
  2296. // In 'class ilm : view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view)'
  2297. $last_iassign = get_string('last_iassign', 'iassign');
  2298. if ($iassign_submission) {
  2299. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2300. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2301. $student_answer = $iassign_submission->answer;
  2302. } else {
  2303. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2304. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2305. }
  2306. }
  2307. } elseif ($iassign_statement_activity_item->test == 1) { // allowed to test after expired due date
  2308. if ($this->action == 'repeat' || ($iassign_submission && $iassign_submission->experiment < 1)) {
  2309. $this->bottonPost = 1;
  2310. $this->write_solution = 0; // if iVProg it is valid to the learner to edit previous solution
  2311. } else {
  2312. $last_iassign = get_string('last_iassign', 'iassign');
  2313. if ($iassign_submission) {
  2314. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2315. "&iassign_submission_current=" . $iassign_submission->id . "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2316. $student_answer = $iassign_submission->answer;
  2317. } else {
  2318. // Symbol of "redo activity"
  2319. $repeat = "<a href='view.php?action=repeat&id=" . $id . "&userid_iassign=$USER->id&iassign_current=" . $this->activity->get_activity()->id .
  2320. "'" . $repeat_title . ">" . iassign_icons::insert('repeat') . '&nbsp;' . get_string('repeat', 'iassign') . "</a>\n";
  2321. }
  2322. }
  2323. } // elseif ($iassign_statement_activity_item->test == 1)
  2324. elseif ($iassign_statement_activity_item->test == 0)
  2325. $this->view_iassign = false;
  2326. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  2327. if ($iassign_submission)
  2328. $param_aux = "action=get_answer&iassign_submission_current=" . $iassign_submission->id . "&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id .
  2329. "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2330. else
  2331. $param_aux = "action=get_answer&id=" . $id . "&iassign_current=" . $this->activity->get_activity()->id . "&write_solution=" . $this->write_solution . "&userid_iassign=" . $USER->id;
  2332. $enderecoPOST = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . $param_aux;
  2333. $this->activity->view_dates();
  2334. if ($this->view_iassign) { // Box 5 to 'proposition' - open
  2335. print $OUTPUT->box_start();
  2336. print '<table width=100% border=0 valign="top">' . "\n";
  2337. print '<tr><td width=60% valign="top">' . "\n";
  2338. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2339. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2340. $flag_dependency = true;
  2341. if ($iassign_statement_activity_item->type_iassign == 3) {
  2342. if ($iassign_statement_activity_item->dependency == 0) {
  2343. print '<strong>' . get_string('independent_activity', 'iassign') . '</strong>' . "\n";
  2344. } else {
  2345. $dependencys = explode(';', $iassign_statement_activity_item->dependency);
  2346. print '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>' . "\n";
  2347. foreach ($dependencys as $dependency) {
  2348. if ($dependency) {
  2349. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  2350. $dependencysubmissions = $DB->get_record("iassign_submission", array("iassign_statementid" => $dependencyiassign->id, 'userid' => $USER->id));
  2351. if ($dependencysubmissions) {
  2352. if ($dependencysubmissions->status == 3)
  2353. $icon = iassign_icons::insert('correct');
  2354. elseif ($dependencysubmissions->status == 2) {
  2355. $icon = iassign_icons::insert('incorrect');
  2356. $flag_dependency = false;
  2357. } elseif ($dependencysubmissions->status == 1) {
  2358. $icon = iassign_icons::insert('post');
  2359. $flag_dependency = false;
  2360. } elseif ($dependencysubmissions->status == 0) {
  2361. $icon = iassign_icons::insert('not_post');
  2362. $flag_dependency = false;
  2363. }
  2364. } else {
  2365. $icon = iassign_icons::insert('not_post');
  2366. $flag_dependency = false;
  2367. } // if ($dependencysubmissions)
  2368. print '<p>&nbsp;' . $icon . $dependencyiassign->name . '</p>' . "\n";
  2369. } // if ($dependency)
  2370. } // foreach ($dependencys as $dependency)
  2371. } // if ($iassign_statement_activity_item->dependency == 0)
  2372. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2373. if ($flag_dependency == false) {
  2374. print '<strong>' . get_string('message_dependency', 'iassign') . '</strong>' . "\n";
  2375. $this->view_iassign = false;
  2376. print '</tr></table>' . "\n";
  2377. }
  2378. else {
  2379. $this->view_iassign = true;
  2380. print '</td>' . "\n";
  2381. } // if ($flag_dependency == false)
  2382. if ($this->view_iassign) { // it is already inside 'if ($this->view_iassign)' but the dependency check could had change its value (above)
  2383. if ($iassign_statement_activity_item->type_iassign == 3) { // activity is present only if exercise
  2384. // receiver=1 - message to teacher
  2385. // receiver=2 - message to student
  2386. if ($iassign_submission) {
  2387. $verify_message = $DB->get_record('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id, 'return_status' => 0, 'receiver' => 2));
  2388. if ($verify_message)
  2389. $comment = iassign_icons::insert('comment_unread');
  2390. }
  2391. print '<td width=40% valign="top" align="left">';
  2392. print '<strong>' . get_string('status', 'iassign') . '</strong>' . "\n";
  2393. if ($iassign_statement_activity_item->show_answer == 1) {
  2394. // check status of solution sent by the student
  2395. if ($iassign_submission) {
  2396. switch ($iassign_submission->status) {
  2397. case 3 :
  2398. print iassign_icons::insert('correct') . '&nbsp;' . get_string('correct', 'iassign') . '&nbsp;' . $comment;
  2399. break;
  2400. case 2 :
  2401. print iassign_icons::insert('incorrect') . '&nbsp;' . get_string('incorrect', 'iassign') . '&nbsp;' . $comment;
  2402. break;
  2403. case 1 :
  2404. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2405. break;
  2406. default :
  2407. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2408. $repeat = "";
  2409. $last_iassign = "";
  2410. } // switch ($iassign_submission->status)
  2411. } else {
  2412. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2413. $repeat = "";
  2414. $last_iassign = "";
  2415. }
  2416. if ($iassign_submission && $iassign_submission->experiment > 0) {
  2417. print '<p><strong>' . get_string('grade_student', 'iassign') . ':</strong>&nbsp;' . $iassign_submission->grade;
  2418. print '&nbsp;&nbsp;(' . get_string('grade_iassign', 'iassign') . ':&nbsp;' . $iassign_statement_activity_item->grade . ')</p>' . "\n";
  2419. print '<p><strong>' . get_string('experiment_student', 'iassign') . '</strong>&nbsp;' . $iassign_submission->experiment;
  2420. if ($iassign_statement_activity_item->max_experiment == 0)
  2421. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . get_string('ilimit', 'iassign') . ')</p>' . "\n";
  2422. else {
  2423. print '&nbsp;&nbsp(' . get_string('experiment_iassign', 'iassign') . '&nbsp;' . $iassign_statement_activity_item->max_experiment . ')</p>' . "\n";
  2424. if ($iassign_submission->experiment >= $iassign_statement_activity_item->max_experiment) {
  2425. $repeat = "";
  2426. $last_iassign .= "&nbsp;<font color=red>" . get_string('attempts_exhausted', 'iassign') . '</font>' . "\n";
  2427. $this->bottonPost = 0;
  2428. $this->write_solution = 0;
  2429. }
  2430. } // else if ($iassign_statement_activity_item->max_experiment == 0)
  2431. print '<p><strong>' . get_string('timemodified', 'iassign') . '</strong>&nbsp;' . userdate($iassign_submission->timemodified) . '</p>' . "\n";
  2432. $teacher = $DB->get_record("user", array('id' => $iassign_submission->teacher));
  2433. if ($teacher)
  2434. print '<p><strong>' . get_string('last_modification', 'iassign') . '</strong>&nbsp;' . $teacher->firstname . '</p>' . "\n"; // "
  2435. } // if ($iassign_submission && $iassign_submission->experiment > 0)
  2436. } // if ($iassign_statement_activity_item->show_answer==1)
  2437. else {
  2438. if (!isset($iassign_submission) || $iassign_submission->status == 0) {
  2439. print iassign_icons::insert('not_post') . '&nbsp;' . get_string('not_post', 'iassign') . '&nbsp;' . $comment;
  2440. $repeat = "";
  2441. $last_iassign = "";
  2442. } elseif ($iassign_submission->status == 1) {
  2443. print iassign_icons::insert('post') . '&nbsp;' . get_string('post', 'iassign') . '&nbsp;' . $comment;
  2444. }
  2445. }
  2446. print '</td>';
  2447. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2448. print '</tr></table>' . "\n";
  2449. // Presents the iLM
  2450. print '<table width=100% border=0 valign="top">' . "\n";
  2451. print '<td width=80% align="left">';
  2452. 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\".
  2453. print '<td width=20% align="rigth">';
  2454. //D $ilm_name = strtolower($this->ilm->name); //if (substr($ilm_name, 0, 5) == "igeom") ; // is iGeom exercise
  2455. print $repeat; // symbol of "redo activity"
  2456. print '</td></tr></table>' . "\n";
  2457. //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)'
  2458. $output = '';
  2459. if (!$iassign_ilm) {
  2460. $iassign_ilm = new stdClass();
  2461. $iassign_ilm->file_jar = "";
  2462. }
  2463. $output .= $OUTPUT->box_start();
  2464. $USER->iassignEdit = $this->bottonPost;
  2465. // ---
  2466. // Presents the iLM
  2467. // Prepare tags to present the iLM
  2468. if (!$iassign_submission || $this->action == 'repeat') { // or $iassign_submission->answer==0
  2469. $student_answer = ""; //?
  2470. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM and true => see the teacher file
  2471. } elseif ($iassign_submission && $iassign_submission->answer == '0') {
  2472. $student_answer = "";
  2473. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true); // presents iLM
  2474. } else {
  2475. // When student is redoing his activity
  2476. // ATTENTION: exception used by iGeom (exercise with "script")
  2477. $loadTeacherActivity = false; // trocar para 'true' se 'special_param1 == 1'
  2478. if (substr($ilm_name, 0, 5)=="igeom") {
  2479. if ($iassign_statement_activity_item->special_param1 == 1) // if 1 => use the teacher activity with some complement from the student (in iGeom = GEO + SCR)
  2480. $loadTeacherActivity = true;
  2481. }
  2482. $output .= $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $loadTeacherActivity); // presents iLM
  2483. }
  2484. //1 Desse modo entre area para comentario, mas nao seu botao separado - deixar para o final com botao!
  2485. //1 if ($iassign_statement_activity_item->type_iassign == 3) {
  2486. //1 $history_comment = '';
  2487. //1 if ($iassign_submission) {
  2488. //1 $history_comment = $this->search_comment_submission($iassign_submission->id);
  2489. //1 }
  2490. //1 if (!empty($history_comment)) {
  2491. //1 $output .= "\n <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>\n" .
  2492. //1 " <tr><th>" . get_string('history_comments', 'iassign') . "</th></tr>\n"; //
  2493. //1 $output .= $history_comment;
  2494. //1 $output .= "</table>\n";
  2495. //1 }
  2496. //1 $output .= "</form></center>\n";
  2497. //1 $only_one_send_button = 1; // avoid put comment frame again (bellow)
  2498. //1 }
  2499. $output .= $OUTPUT->box_end();
  2500. print $output;
  2501. } // if ($this->view_iassign)
  2502. print $OUTPUT->box_end(); // Box 5 to 'proposition' - close
  2503. } // if ($this->view_iassign)
  2504. } // elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2505. else
  2506. if (isguestuser()) { // else of elseif (has_capability('mod/iassign:submitiassign', $USER->context, $USER->id))
  2507. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  2508. print '<table width=100% border=0 valign="top">' . "\n";
  2509. print '<tr><td width=60% valign="top">' . "\n";
  2510. print '<strong>' . get_string('proposition', 'iassign') . '</strong>' . "\n";
  2511. print '<p>' . $iassign_statement_activity_item->proposition . '</p>' . "\n";
  2512. print '</tr></table>' . "\n";
  2513. $student_answer = "";
  2514. $enderecoPOST = "";
  2515. // Prepare tags to present the iLM
  2516. $output = $ilm->view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, true);
  2517. print $output;
  2518. }
  2519. //2020 Quadro com area para enivar e ler comentarios veio para este ponto para permitir todos o terem
  2520. // $only_one_send_button is to avoid to put 2 copies of comments (area to send and see comments between teacher and student)
  2521. 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
  2522. // Put a block with area to sent/answer comments
  2523. $output = '';
  2524. $history_comment = '';
  2525. $row = optional_param('row', 0, PARAM_INT);
  2526. $column = optional_param('column', 0, PARAM_INT);
  2527. if ($iassign_submission) {
  2528. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2529. "&iassign_submission_current=" . $iassign_submission->id . "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2530. $history_comment = $this->search_comment_submission($iassign_submission->id);
  2531. }
  2532. else {
  2533. $enderecoPOSTcomment = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=newcomment&iassign_current=" . $this->activity->get_activity()->id .
  2534. "&userid_iassign=" . $this->userid_iassign . "&row=" . ($row) . "&column=" . ($column);
  2535. }
  2536. $output .= $OUTPUT->box_start();
  2537. //if (!empty($history_comment)) {
  2538. $output .= " <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'> \n";
  2539. $output .= " <tr><th><i style='font-size: 20px' class='icon fa fa-comments-o'></i>" . get_string('history_comments', 'iassign') . "</th></tr>";
  2540. $output .= "</table>";
  2541. print " <script type='text/javascript'>
  2542. //<![CDATA[
  2543. function submit_comment(url) {
  2544. if (document.formEnvioComment.submission_comment.value.length < 1) return;
  2545. var formData = new FormData();
  2546. formData.append('submission_comment', document.formEnvioComment.submission_comment.value);
  2547. var request = new XMLHttpRequest();
  2548. request.open('POST', url);
  2549. document.getElementById('comments_history').innerHTML = '';
  2550. request.onload = function (e) {
  2551. if (request.readyState === 4) {
  2552. if (request.status === 200) {
  2553. document.getElementById('comments_history').innerHTML = request.responseText;
  2554. document.getElementById('check-message-success').style.visibility = 'visible';
  2555. setTimeout(function(){
  2556. document.getElementById('check-message-success').style.visibility = 'hidden';
  2557. }, 3000);
  2558. }
  2559. }
  2560. };
  2561. document.formEnvioComment.submission_comment.value = '';
  2562. request.send(formData);
  2563. }
  2564. //]]>
  2565. </script>";
  2566. $output .= "<center><form name='formEnvioComment' id='formEnvioComment1' enctype='multipart/form-data'>\n";
  2567. $output .= "<br><p><textarea class='form-control w-50' rows='2' cols='60' name='submission_comment'></textarea></p>\n";
  2568. $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";
  2569. $output .= "</form> </center>\n";
  2570. $output .= "<table id='comments_history' class='generaltable boxaligncenter' cellpadding='5' width='100%'>".$history_comment."</table>";
  2571. // }
  2572. $output .= $OUTPUT->box_end();
  2573. print $output;
  2574. } // if ($iassign_statement_activity_item->type_iassign == 3)
  2575. // final block 'studant'
  2576. print $OUTPUT->footer();
  2577. die();
  2578. } // function view_iassign_current()
  2579. /// Export the data from performance report into CSV file format
  2580. function export_csv () {
  2581. global $USER, $CFG, $DB, $OUTPUT;
  2582. $str = "";
  2583. $fields = "student_id, student_name";
  2584. // Finding all iassign activities for the iassign:
  2585. $id = $this->cm->id;
  2586. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2587. $c = 1;
  2588. foreach ($iassign_list as $iassign) {
  2589. $fields .= ", activity_id_$c, activity_name_$c, total_submissions_activity_$c, grade_activity_$c"
  2590. . ", status_activity_$c, ilm_id_activity_$c, ilm_name_activity_$c";
  2591. $c ++;
  2592. }
  2593. // Finding enrolled students:
  2594. $params = array('shortname' => 'student');
  2595. $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {role} s WHERE s.shortname = :shortname", $params);
  2596. $context = context_course::instance($this->course->id);
  2597. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2598. $students = $DB->get_records_sql(
  2599. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2600. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2601. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2602. foreach ($students as $student) {
  2603. $str .= $student->userid . ',';
  2604. $str .= '"' . $student->firstname . ' ' . $student->lastname . '"';
  2605. foreach ($iassign_list as $iassign) {
  2606. $str .= ',' . $iassign->id . ',';
  2607. $str .= '"' . $iassign->name . '",';
  2608. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign->id, 'userid' => $student->userid));
  2609. if ($student_submissions) {
  2610. $str .= $student_submissions->experiment . ',';
  2611. $str .= $student_submissions->grade . ',';
  2612. switch ($student_submissions->status) {
  2613. case 3:
  2614. $str .= '"correct",';
  2615. break;
  2616. case 2:
  2617. $str .= '"incorrect",';
  2618. break;
  2619. case 1:
  2620. $str .= '"post",';
  2621. break;
  2622. case 0:
  2623. $str .= '"not_post",';
  2624. break;
  2625. }
  2626. } else {
  2627. $str .= ',,"not_post",';
  2628. }
  2629. $str .= $iassign->iassign_ilmid . ',';
  2630. $ilm_activity = $DB->get_record("iassign_ilm", array('id' => $iassign->iassign_ilmid));
  2631. $str .= '"' . $ilm_activity->name . '"';
  2632. }
  2633. $str .= "\n";
  2634. }
  2635. $str = $fields . "\n" . $str;
  2636. header("Content-type: text/csv");
  2637. header("Content-disposition: attachment; filename=report.csv");
  2638. header("Pragma: no-cache");
  2639. header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
  2640. header('Content-Length: ' . strlen($str));
  2641. header('Connection: close');
  2642. print $str;
  2643. flush();
  2644. } // function export_csv()
  2645. /// Display report of performance
  2646. function report () {
  2647. global $USER, $CFG, $DB, $OUTPUT;
  2648. $id = $this->cm->id;
  2649. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2650. if ($this->action != 'print') {
  2651. $title = get_string('report', 'iassign');
  2652. print $OUTPUT->header();
  2653. } // if ($this->action != 'print')
  2654. print $OUTPUT->box_start();
  2655. $this->view_legend_icons();
  2656. print '<p>' . get_string('ps_experiment', 'iassign') . '</p>';
  2657. print '<p>' . get_string('ps_comment', 'iassign') . '</p>';
  2658. print $OUTPUT->box_end();
  2659. if ($this->action == 'print')
  2660. print '<table border=1 width="100%">' . "\n";
  2661. else
  2662. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2663. print '<tr><th colspan=2 class="header c1">' . iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  2664. // $num = array();
  2665. $i = 1;
  2666. $num = array();
  2667. foreach ($iassign_list as $iassign) {
  2668. $test_exercise = "";
  2669. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2670. if (($iassign_submission) && $iassign->type_iassign < 3) {
  2671. $test_exercise = "&nbsp;<b>(" . get_string('iassign_exercise', 'iassign') . ")</b>";
  2672. } // if (($iassign_submission) && $iassign->type_iassign < 3)
  2673. if ($iassign->type_iassign == 3 || ($iassign_submission)) {
  2674. $num[$i] = new stdClass();
  2675. $num[$i]->name = $iassign->name;
  2676. $num[$i]->id = $i;
  2677. $num[$i]->iassignid = $iassign->id;
  2678. print ' <tr >' . "\n";
  2679. print " <td class=\"cell c1 numviews\" width=5% align='center'><strong>" . $num[$i]->id . "</strong></td>\n";
  2680. print "<td class=\"cell c0 actvity\">";
  2681. print '&nbsp;' . $num[$i]->name . '&nbsp;' . $test_exercise . "</td>";
  2682. print ' </tr>' . "\n";
  2683. $i ++;
  2684. } // if ($iassign->type_iassign == 3 || ($iassign_submission))
  2685. } // foreach ($iassign_list as $iassign)
  2686. print "</table>";
  2687. print "<p></p>";
  2688. if ($this->action == 'print')
  2689. print '<table border=1 width="100%">' . "\n";
  2690. else
  2691. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2692. $context = context_course::instance($this->course->id);
  2693. if ($i > 1) {
  2694. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2695. $params = array('shortname' => 'student');
  2696. $role = $DB->get_record_sql(
  2697. "SELECT s.id, s.shortname FROM {role} s " .
  2698. " WHERE s.shortname = :shortname", $params);
  2699. // $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");
  2700. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2701. $students = $DB->get_records_sql(
  2702. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2703. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2704. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2705. print '<tr><th class="header c1">' . get_string('students', 'iassign') . '</th>' . "\n";
  2706. for ($j = 1; $j < $i; $j ++) {
  2707. $sum_iassign_correct[$j] = 0;
  2708. print '<th class="header c1" scope="col">' . $num[$j]->id . '</th>' . "\n"; // <th class="header c1" scope="col">
  2709. }
  2710. print '<th class="header c1" width=5%> ' . get_string('functions', 'iassign') . '</th>';
  2711. $sum_iassign = $j - 1;
  2712. print '</tr>' . "\n";
  2713. $total = 0;
  2714. $sum_student = 0;
  2715. $comment = iassign_icons::insert('comment_read');
  2716. $sum_comment = 0;
  2717. $sum_correct_iassign = array();
  2718. $sum_correct_student = array();
  2719. $USER->matrix_iassign = array();
  2720. if ($students) {
  2721. $w = 0;
  2722. foreach ($students as $tmp) {
  2723. $users_array[$w] = $tmp;
  2724. $w ++;
  2725. }
  2726. for ($x = 0; $x < $w; $x ++) {
  2727. print '<tr>' . "\n";
  2728. $sum_student ++;
  2729. $name = $users_array[$x]->firstname . '&nbsp;' . $users_array[$x]->lastname;
  2730. print ' <td >' . $name . '</td>' . "\n";
  2731. $total_student = 0;
  2732. $tentativas = 0;
  2733. for ($j = 1; $j < $i; $j ++) {
  2734. $sum_comment = 0;
  2735. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users_array[$x]->userid)); // data about student solution
  2736. print ' <td valign="bottom" align="center">' . "\n";
  2737. if ($student_submissions) {
  2738. $last_solution_submission = " title=\"" . userdate($student_submissions->timemodified) . "\" "; // timemodified: time of the last student solution
  2739. $tentativas = $student_submissions->experiment;
  2740. // $student_submissions_comment = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment WHERE iassign_submissionid = '$student_submissions->id'");
  2741. $params = array('iassign_submissionid' => $student_submissions->id);
  2742. $student_submissions_comment = $DB->get_record_sql(
  2743. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2744. "WHERE iassign_submissionid = :iassign_submissionid", $params);
  2745. if ($student_submissions_comment)
  2746. foreach ($student_submissions_comment as $tmp)
  2747. $sum_comment = $tmp;
  2748. // informations to previous activities
  2749. if ($j - 1 < 1 || $j == $i)
  2750. $iassign_previous = "-1";
  2751. else
  2752. $iassign_previous = $num[$j - 1]->iassignid;
  2753. if ($x - 1 < 0 || $x == $w)
  2754. $user_previous = "-1";
  2755. else
  2756. $user_previous = $users_array[$x - 1]->userid;
  2757. // next
  2758. if ($i - 1 > $j)
  2759. $iassign_next = $num[$j + 1]->iassignid;
  2760. else
  2761. $iassign_next = "-1";
  2762. if ($w - 1 > $x)
  2763. $user_next = $users_array[$x + 1]->userid;
  2764. else
  2765. $user_next = "-1";
  2766. $position = "&row= $x&column=$j";
  2767. $url = "" . $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&iassign_submission_current=" . $student_submissions->id .
  2768. "&userid_iassign=" . $users_array[$x]->userid . "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2769. $url .= $position;
  2770. // receiver=1 - message to teacher
  2771. // receiver=2 - message to student
  2772. // $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment " .
  2773. // "WHERE iassign_submissionid = '$student_submissions->id' AND return_status='0' AND receiver='1'");
  2774. $params = array('iassign_submissionid' => $student_submissions->id, 'return_status' => '0', 'receiver' => '1');
  2775. $verify_message = $DB->get_record_sql(
  2776. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  2777. "WHERE iassign_submissionid = :iassign_submissionid " .
  2778. " AND return_status= :return_status " .
  2779. " AND receiver= :receiver", $params);
  2780. if ($verify_message)
  2781. foreach ($verify_message as $tmp)
  2782. $sum_verify_message = $tmp;
  2783. if ($sum_verify_message > 0)
  2784. $comment = iassign_icons::insert('comment_unread');
  2785. else
  2786. $comment = iassign_icons::insert('comment_read');
  2787. if ($student_submissions->status == 3) {
  2788. $sum_iassign_correct[$j] ++;
  2789. $total_student ++;
  2790. $feedback = iassign_icons::insert('correct');
  2791. }
  2792. elseif ($student_submissions->status == 2) {
  2793. $feedback = iassign_icons::insert('incorrect');
  2794. }
  2795. elseif ($student_submissions->status == 1) {
  2796. $feedback = iassign_icons::insert('post');
  2797. }
  2798. elseif ($student_submissions->status == 0) {
  2799. $feedback = iassign_icons::insert('not_post');
  2800. }
  2801. if ($this->action != 'print') {
  2802. print '<table><tr>';
  2803. if ($tentativas > 0)
  2804. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> &nbsp;(' . $tentativas . ')</td>' . "\n";
  2805. else
  2806. print '<td> <a href="' . $url . '" ' . $last_solution_submission . '>' . $feedback . '</a> </td>' . "\n";
  2807. print '<td> &nbsp; </td>';
  2808. print '</tr>' . "\n";
  2809. if ($sum_comment > 0 && $sum_verify_message > 0)
  2810. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_verify_message . '/' . $sum_comment . ') </td></tr>' . "\n";
  2811. else if ($sum_comment > 0)
  2812. print '<tr><td colspan="2"> <a href="' . $url . '"> ' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td></tr>' . "\n";
  2813. print '</table>' . "\n";
  2814. }
  2815. if ($this->action == 'print')
  2816. print $feedback . '&nbsp;(' . $tentativas . ')<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2817. } // if ($student_submissions)
  2818. else { // if ($student_submissions)
  2819. // informations to browse previous activities
  2820. if ($j - 1 < 1 || $j == $i)
  2821. $iassign_previous = "-1";
  2822. else
  2823. $iassign_previous = $num[$j - 1]->iassignid;
  2824. if ($x - 1 < 0 || $x == $w)
  2825. $user_previous = "-1";
  2826. else
  2827. $user_previous = $users_array[$x - 1]->userid;
  2828. // next
  2829. if ($i - 1 > $j)
  2830. $iassign_next = $num[$j + 1]->iassignid;
  2831. else
  2832. $iassign_next = "-1";
  2833. if ($w - 1 > $x)
  2834. $user_next = $users_array[$x + 1]->userid;
  2835. else
  2836. $user_next = "-1";
  2837. $position = "&row= $x&column=$j";
  2838. $url = $CFG->wwwroot . "/mod/iassign/view.php?action=viewsubmission&id=" . $id . "&userid_iassign=" . $users_array[$x]->userid .
  2839. "&iassign_current=" . $num[$j]->iassignid . "&view_iassign=" . $this->view_iassign;
  2840. $url .= $position;
  2841. $feedback = iassign_icons::insert('not_post');
  2842. if ($this->action == 'print')
  2843. print $feedback . '&nbsp;(0)<br>' . $comment . '&nbsp;(' . $sum_comment . ')&nbsp;' . "\n";
  2844. else {
  2845. print '<table><tr>';
  2846. print '<td> <a href="' . $url . '">' . $feedback . '</a> </td>' . "\n";
  2847. print '<td> &nbsp; </td>';
  2848. print '</tr><tr>' . "\n";
  2849. print '<td> &nbsp;</td>';
  2850. if ($sum_comment > 0)
  2851. print '<td> <a href="' . $url . '">' . $comment . '</a> &nbsp;(' . $sum_comment . ') </td>' . "\n";
  2852. else
  2853. print '<td> &nbsp;</td>';
  2854. print '</tr></table>';
  2855. }
  2856. } // else if ($student_submissions)
  2857. $USER->matrix_iassign[$x][$j] = new stdClass();
  2858. $USER->matrix_iassign[$x][$j]->iassign_previous = $iassign_previous;
  2859. $USER->matrix_iassign[$x][$j]->user_previous = $user_previous;
  2860. $USER->matrix_iassign[$x][$j]->iassign_next = $iassign_next;
  2861. $USER->matrix_iassign[$x][$j]->user_next = $user_next;
  2862. if ($student_submissions)
  2863. $USER->matrix_iassign[$x][$j]->iassign_submission_current = $student_submissions->id;
  2864. else
  2865. $USER->matrix_iassign[$x][$j]->iassign_submission_current = 0;
  2866. print '</td>' . "\n";
  2867. } // for ($j=1; $j<$i; $j++)
  2868. $total = $total + $total_student;
  2869. $porcentagem = ($total_student / ($j - 1)) * 100;
  2870. if ($tentativas != 0 && $tentativas != null) {
  2871. $url_answer = "" . $CFG->wwwroot . "/mod/iassign/view.php?" . "action=download_all_answer&iassign_id=" . $this->iassign->id . "&userid=" . $users_array[$x]->userid . "&id=" . $id;
  2872. print ' <td align="center"><a href="' . $url_answer . '">' . iassign_icons::insert('download_all_assign') . '</a></td>' . "\n";
  2873. }
  2874. else {
  2875. print ' <td align="center">' . iassign_icons::insert('download_all_assign_disabled') . '</td>' . "\n";
  2876. }
  2877. print '</tr>' . "\n";
  2878. $sum_correct_student[$sum_student] = new stdClass();
  2879. $sum_correct_student[$sum_student]->name = $name;
  2880. $sum_correct_student[$sum_student]->sum = $total_student;
  2881. } // for ($x = 0; $x < $w; $x ++)
  2882. for ($i = 1; $i < $j; $i ++) {
  2883. if (is_null($sum_iassign_correct[$i]))
  2884. $sum_iassign_correct[$i] = 0;
  2885. $sum_correct_iassign[$i] = new stdClass();
  2886. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2887. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2888. }
  2889. // print '</tr></table>' . "\n";
  2890. }
  2891. } // if ($i>1)
  2892. else {
  2893. print_string('no_activity', 'iassign');
  2894. }
  2895. print "</table>\n";
  2896. if ($this->action != 'print')
  2897. print $OUTPUT->footer();
  2898. die();
  2899. } // function report()
  2900. /// Display graphics of performance
  2901. function stats () {
  2902. global $USER, $CFG, $DB, $OUTPUT;
  2903. $id = $this->cm->id;
  2904. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), "position ASC");
  2905. if ($this->action != 'printstats')
  2906. $title = get_string('graphic', 'iassign');
  2907. $num = array();
  2908. $sum_correct_iassign = array();
  2909. $sum_correct_student = array();
  2910. $sum_student = 0;
  2911. $i = 1;
  2912. foreach ($iassign_list as $iassign) {
  2913. $iassign_submission = $DB->get_records("iassign_submission", array("iassign_statementid" => $iassign->id));
  2914. if ($iassign->type_iassign == 3) { // || ($iassign_submission)
  2915. $sum_iassign_correct[$i] = 0;
  2916. $num[$i] = new stdClass();
  2917. $num[$i]->name = $iassign->name;
  2918. $num[$i]->id = $i;
  2919. $num[$i]->iassignid = $iassign->id;
  2920. $i ++;
  2921. } // if ($iassign->type_iassign == 3)
  2922. } // foreach ($iassign_list as $iassign)
  2923. $sum_iassign = $i - 1;
  2924. $context = context_course::instance($this->course->id);
  2925. if ($i > 1) {
  2926. // $role = $DB->get_record_sql("SELECT s.id, s.shortname FROM {$CFG->prefix}role s WHERE s.shortname = 'student'");
  2927. $params = array('shortname' => 'student');
  2928. $role = $DB->get_record_sql(
  2929. "SELECT s.id, s.shortname FROM {role} s " .
  2930. " WHERE s.shortname = :shortname", $params);
  2931. // $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");
  2932. $params = array('contextid' => $context->id, 'roleid' => $role->id);
  2933. $students = $DB->get_records_sql(
  2934. "SELECT s.userid, a.firstname, a.lastname FROM {role_assignments} s, {user} a " .
  2935. " WHERE s.contextid = :contextid AND s.userid = a.id AND s.roleid = :roleid " .
  2936. " ORDER BY a.firstname ASC,a.lastname ASC", $params);
  2937. $total = 0;
  2938. $sum_student = 0;
  2939. $j = 0;
  2940. $sum_correct_iassign = array();
  2941. $sum_correct_student = array();
  2942. $sum_experiment = array();
  2943. if ($students) {
  2944. foreach ($students as $users) {
  2945. $sum_student ++;
  2946. $name = $users->firstname . '&nbsp;' . $users->lastname;
  2947. // rows
  2948. $total_student = 0;
  2949. for ($j = 1; $j < $i; $j ++) {
  2950. $total_experiment = 0;
  2951. $student_submissions = $DB->get_record("iassign_submission", array('iassign_statementid' => $num[$j]->iassignid, 'userid' => $users->userid)); // data about student solution
  2952. if ($student_submissions) {
  2953. if ($student_submissions->status == 3) {
  2954. $sum_iassign_correct[$j] ++;
  2955. $total_student ++;
  2956. } // if ($student_submissions->status == 3)
  2957. $total_experiment += $student_submissions->experiment;
  2958. }
  2959. $sum_experiment[$j] = $total_experiment;
  2960. } // for ($j=1; $j<$i; $j++)
  2961. $total = $total + $total_student;
  2962. $sum_correct_student[$sum_student] = new stdClass();
  2963. $sum_correct_student[$sum_student]->name = $name;
  2964. $sum_correct_student[$sum_student]->sum = $total_student;
  2965. } // foreach ($students as $users)
  2966. }
  2967. for ($i = 1; $i < $j; $i ++) {
  2968. if (is_null($sum_iassign_correct[$i]))
  2969. $sum_iassign_correct[$i] = 0;
  2970. $sum_correct_iassign[$i] = new stdClass();
  2971. $sum_correct_iassign[$i]->sum = $sum_iassign_correct[$i];
  2972. $sum_correct_iassign[$i]->name = $num[$i]->name;
  2973. $sum_correct_iassign[$i]->experiment = $sum_experiment[$i];
  2974. } // for ($i = 1; $i < $j; $i++)
  2975. } // if ($i > 1)
  2976. if ($this->action != 'printstats') {
  2977. $title = get_string('graphic', 'iassign');
  2978. print $OUTPUT->header();
  2979. $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>";
  2980. $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>";
  2981. print '<table width=100%><tr>';
  2982. print '<td align="right">' . $link_print_stats . '</td>' . "\n";
  2983. print '<td width=15% align="right">' . $link_report . '</td>';
  2984. print '</td></tr></table>' . "\n";
  2985. print "<br><br>";
  2986. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  2987. print '<tr><th colspan=5 class="header c1">' . get_string('distribution_activity', 'iassign') . '</th></tr>' . "\n";
  2988. print '<tr><td class=\'cell c0 actvity\' width=35%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  2989. print '<td class=\'cell c0 actvity\' width=35%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  2990. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('proportion_correct', 'iassign') . '</strong>' . "\n";
  2991. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_experiment', 'iassign') . '</strong></td>' . "\n";
  2992. print '<td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('avg_experiment', 'iassign') . '</strong></td>' . "\n";
  2993. print '</tr>' . "\n";
  2994. $sum_correct = 0;
  2995. if ($sum_correct_iassign) {
  2996. foreach ($sum_correct_iassign as $iassign) {
  2997. if (is_null($iassign->experiment))
  2998. $iassign->experiment = 0;
  2999. $bar = "";
  3000. $sum = $iassign->sum;
  3001. $percent = ($sum / $sum_student) * 100;
  3002. $text = number_format($percent, 1) . '%';
  3003. $sum_correct += $sum;
  3004. if ($sum > 0) {
  3005. for ($i = 1; $i < $percent * 2; $i ++)
  3006. $bar .= iassign_icons::insert('hbar_blue');
  3007. $bar .= iassign_icons::insert('hbar_blue_r');
  3008. } // if ($sum > 0)
  3009. print '<tr ><td class=\'cell c0 actvity\'width=35%>' . $iassign->name . '</td>' . "\n";
  3010. print ' <td class=\'cell c0 actvity\' width=35%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3011. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_student . '</td>' . "\n";
  3012. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . $iassign->experiment . '</td>' . "\n";
  3013. print ' <td class=\'cell c0 actvity\' width=10% align="right">' . number_format($iassign->experiment / $sum_iassign, 1) . '</td>' . "\n";
  3014. print '</tr>' . "\n";
  3015. } // foreach ($sum_correct_iassign as $iassign)
  3016. }
  3017. print "</table>";
  3018. print "<br><br>";
  3019. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3020. print '<tr><th colspan=3 class="header c1">' . get_string('distribution_student', 'iassign') . '</th></tr>' . "\n";
  3021. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3022. print ' <td class=\'cell c0 actvity\' width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3023. print ' <td class=\'cell c0 actvity\' width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3024. print '</tr>' . "\n";
  3025. $sum_correct = 0;
  3026. foreach ($sum_correct_student as $student) {
  3027. $bar = "";
  3028. $sum = $student->sum;
  3029. $percent = ($sum / $sum_iassign) * 100;
  3030. $text = number_format($percent, 1) . '%';
  3031. $sum_correct += $sum;
  3032. if ($sum > 0) {
  3033. for ($i = 1; $i < $percent * 2; $i ++)
  3034. $bar .= iassign_icons::insert('hbar_blue');
  3035. $bar .= iassign_icons::insert('hbar_blue_r');
  3036. } // if ($sum > 0)
  3037. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $student->name . '</td>' . "\n";
  3038. print '<td class=\'cell c0 actvity\' width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3039. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3040. print '</tr>' . "\n";
  3041. } // foreach ($sum_correct_student as $student)
  3042. print "</table>\n";
  3043. print "<br><br>\n";
  3044. $var = 0;
  3045. $cv = 0;
  3046. $dv = 0;
  3047. $avg = 0;
  3048. if ($sum_correct_student) {
  3049. $avg = $sum_correct / $sum_student;
  3050. if ($avg > 0) {
  3051. foreach ($sum_correct_student as $student)
  3052. $var += pow($student->sum - $avg, 2);
  3053. $var = $var / $sum_student;
  3054. $dv = sqrt($var);
  3055. $cv = ($dv / $avg) * 100;
  3056. }
  3057. }
  3058. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3059. print '<tr><th colspan=5 class="header c1">' . get_string('statistics', 'iassign') . '</th></tr>' . "\n";
  3060. print '<tr><td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3061. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3062. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3063. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3064. print ' <td class=\'cell c0 actvity\' width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3065. print '<tr><td class=\'cell c0 actvity\' width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3066. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . $sum_student . '</td>' . "\n";
  3067. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3068. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3069. print ' <td class=\'cell c0 actvity\' width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3070. print "</table>\n";
  3071. print $OUTPUT->footer();
  3072. } else {
  3073. print "<STYLE TYPE='text/css'>
  3074. <!--
  3075. .boldtable {
  3076. font-family:sans-serif;
  3077. font-size:10pt;
  3078. }
  3079. -->
  3080. </STYLE>\n";
  3081. print '<table border=1 width=100%>' . "\n";
  3082. print '<tr><td colspan=3 align="center"><strong>' . get_string('distribution_activity', 'iassign') . '</strong></td></tr>' . "\n";
  3083. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3084. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3085. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3086. print '</tr>' . "\n";
  3087. $sum_correct = 0;
  3088. foreach ($sum_correct_iassign as $iassign) {
  3089. $bar = "";
  3090. $sum = $iassign->sum;
  3091. $percent = ($sum / $sum_student) * 100;
  3092. $text = number_format($percent, 1) . '%';
  3093. $sum_correct += $sum;
  3094. if ($sum > 0) {
  3095. for ($i = 1; $i < $percent * 2; $i ++)
  3096. $bar .= iassign_icons::insert('hbar_blue');
  3097. $bar .= iassign_icons::insert('hbar_blue_r');
  3098. } // if ($sum > 0)
  3099. print '<tr><td width=50%>' . $iassign->name . '</td>' . "\n";
  3100. print '<td width=40%>' . $bar . '&nbsp;' . $text . '</td>';
  3101. print '<td width=10% align="right">' . $sum . '/' . $sum_student . '</td>';
  3102. print '</tr>' . "\n";
  3103. } // foreach ($sum_correct_iassign as $iassign)
  3104. print "</table>";
  3105. print "<br><br>";
  3106. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3107. print '<tr><td colspan=3 align="center" ><strong>' . get_string('distribution_student', 'iassign') . '</strong></td></tr>' . "\n";
  3108. print '<tr><td width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3109. print '<td width=40%><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>';
  3110. print '<td width=10% align="right"><strong>' . get_string('sum_correct', 'iassign') . '</strong></td>';
  3111. print '</tr>' . "\n";
  3112. $sum_correct = 0;
  3113. foreach ($sum_correct_student as $student) {
  3114. $bar = "";
  3115. $sum = $student->sum;
  3116. $percent = ($sum / $sum_iassign) * 100;
  3117. $text = number_format($percent, 1) . '%';
  3118. $sum_correct += $sum;
  3119. if ($sum > 0) {
  3120. for ($i = 1; $i < $percent * 2; $i ++)
  3121. $bar .= iassign_icons::insert('hbar_blue');
  3122. $bar .= iassign_icons::insert('hbar_blue_r');
  3123. } // if ($sum > 0)
  3124. print "<tr><td width=50%>" . $student->name . "</td>\n";
  3125. print ' <td width=40%>' . $bar . '&nbsp;' . $text . '</td>' . "\n";
  3126. print ' <td width=10% align="right">' . $sum . '/' . $sum_iassign . '</td>' . "\n";
  3127. print '</tr>' . "\n";
  3128. } // foreach ($sum_correct_student as $student)
  3129. print "</table>\n";
  3130. print "<br/><br/>\n";
  3131. $var = 0;
  3132. $cv = 0;
  3133. $dv = 0;
  3134. $avg = 0;
  3135. if ($sum_correct_student) {
  3136. $avg = $sum_correct / $sum_student;
  3137. if ($avg > 0) {
  3138. foreach ($sum_correct_student as $student)
  3139. $var += pow($student->sum - $avg, 2);
  3140. $var = $var / $sum_student;
  3141. $dv = sqrt($var);
  3142. $cv = ($dv / $avg) * 100;
  3143. }
  3144. }
  3145. print '<table border=1 class="boldtable" width=100%>' . "\n";
  3146. print '<tr><td colspan=5 align="center"><strong>' . get_string('statistics', 'iassign') . '</strong></th></tr>' . "\n";
  3147. print '<tr><td width=20% align="center"><strong>' . get_string('sum_activity', 'iassign') . '</strong></td>' . "\n";
  3148. print '<td width=20% align="center"><strong>' . get_string('sum_student', 'iassign') . '</strong></td>' . "\n";
  3149. print '<td width=20% align="center"><strong>' . get_string('mean_score', 'iassign') . '</strong></td>' . "\n";
  3150. print '<td width=20% align="center"><strong>' . get_string('standard_deviation', 'iassign') . '</strong></td>' . "\n";
  3151. print '<td width=20% align="center"><strong>' . get_string('coefficient_variation', 'iassign') . '</strong></td></tr>' . "\n";
  3152. print '<tr><td width=20% align="center">' . $sum_iassign . '</td>' . "\n";
  3153. print '<td width=20% align="center">' . $sum_student . '</td>' . "\n";
  3154. print '<td width=20% align="center">' . number_format($avg, 1) . '</td>' . "\n";
  3155. print '<td width=20% align="center">' . number_format($dv, 1) . '</td>' . "\n";
  3156. print '<td width=20% align="center">' . number_format($cv, 1) . '%</td></tr>' . "\n";
  3157. print "</table>\n";
  3158. } // if ($this->action != 'printstats')
  3159. die();
  3160. }
  3161. /// Display graphics of performance for students
  3162. function stats_students () {
  3163. global $USER, $CFG, $DB, $OUTPUT;
  3164. $id = $this->cm->id;
  3165. $iassign_statement_list = $DB->get_records_sql("SELECT * FROM {iassign_statement} s " .
  3166. " WHERE s.iassignid = '{$this->iassign->id}' AND s.type_iassign=3 ORDER BY s.position");
  3167. $title = get_string('results', 'iassign');
  3168. $sum_correct = 0;
  3169. $sum_incorrect = 0;
  3170. $sum_post = 0;
  3171. $sum_nopost = 0;
  3172. $sum_iassign = count($iassign_statement_list);
  3173. $bar_nopost = "";
  3174. $bar_correct = "";
  3175. $bar_incorrect = "";
  3176. $bar_post = "";
  3177. $text_nopost = "";
  3178. $text_correct = "";
  3179. $text_incorrect = "";
  3180. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3181. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id)); // data about student solution
  3182. if ($iassign_submission) {
  3183. if ($iassign_submission->status == 3)
  3184. $sum_correct ++;
  3185. elseif ($iassign_submission->status == 2)
  3186. $sum_incorrect ++;
  3187. elseif ($iassign_submission->status == 1)
  3188. $sum_post ++;
  3189. elseif ($iassign_submission->status == 0 || !$iassign_submission)
  3190. $sum_nopost ++;
  3191. } // if ($iassign_submission)
  3192. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3193. if ($sum_iassign > 0) {
  3194. $percent_correct = ($sum_correct / $sum_iassign) * 100;
  3195. $text_correct = number_format($percent_correct, 1) . '%';
  3196. }
  3197. if ($sum_correct > 0) {
  3198. for ($i = 1; $i < $percent_correct * 2; $i ++)
  3199. $bar_correct .= iassign_icons::insert('hbar_green');
  3200. $bar_correct .= iassign_icons::insert('hbar_green_r');
  3201. } // if ($sum_correct > 0)
  3202. if ($sum_iassign > 0) {
  3203. $percent_incorrect = ($sum_incorrect / $sum_iassign) * 100;
  3204. $text_incorrect = number_format($percent_incorrect, 1) . '%';
  3205. }
  3206. if ($sum_incorrect > 0) {
  3207. for ($i = 1; $i < $percent_incorrect * 2; $i ++)
  3208. $bar_incorrect .= iassign_icons::insert('hbar_red');
  3209. $bar_incorrect .= iassign_icons::insert('hbar_red_r');
  3210. } // if ($sum_incorrect > 0)
  3211. if ($sum_iassign > 0) {
  3212. $percent_post = ($sum_post / $sum_iassign) * 100;
  3213. $text_post = number_format($percent_post, 1) . '%';
  3214. }
  3215. if ($sum_post > 0) {
  3216. for ($i = 1; $i < $percent_post * 2; $i ++)
  3217. $bar_post .= iassign_icons::insert('hbar_blue');
  3218. $bar_post .= iassign_icons::insert('hbar_blue_r');
  3219. } // if ($sum_post > 0)
  3220. if ($sum_iassign > 0) {
  3221. $percent_nopost = ($sum_nopost / $sum_iassign) * 100;
  3222. $text_nopost = number_format($percent_nopost, 1) . '%';
  3223. }
  3224. if ($sum_nopost > 0) {
  3225. for ($i = 1; $i < $percent_nopost * 2; $i ++)
  3226. $bar_nopost .= iassign_icons::insert('hbar_orange');
  3227. $bar_nopost .= iassign_icons::insert('hbar_orange_r');
  3228. } // if ($sum_nopost > 0)
  3229. print $OUTPUT->header();
  3230. $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3231. print '<table width=100%><tr>';
  3232. print '<td align="right">' . $link_return . '</td>' . "\n";
  3233. print '</td></tr></table>' . "\n";
  3234. print "<br/><br/>\n";
  3235. print '<table id="outlinetable" class="generaltable box aligncenter" cellpadding="5" width="100%">' . "\n";
  3236. print '<tr><th colspan=3 class="header c1">' . "\n";
  3237. // helpbutton('legend', get_string('legend', 'iassign'), 'iassign', $image = true, $linktext = false, $text = '', $return = false,
  3238. // $imagetext = '');
  3239. print iassign_utils::remove_code_message($this->iassign->name) . '</th></tr>' . "\n";
  3240. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('correct', 'iassign') . '</td>' . "\n";
  3241. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_correct . '&nbsp;' . $text_correct . '</td>';
  3242. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_correct . '/' . $sum_iassign . '</td>';
  3243. print '</tr>' . "\n";
  3244. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('incorrect', 'iassign') . '</td>' . "\n";
  3245. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_incorrect . '&nbsp;' . $text_incorrect . '</td>';
  3246. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_incorrect . '/' . $sum_iassign . '</td>';
  3247. print '</tr>' . "\n";
  3248. if ($sum_post) {
  3249. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('post', 'iassign') . '</td>' . "\n";
  3250. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_post . '&nbsp;' . $text_post . '</td>';
  3251. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_post . '/' . $sum_iassign . '</td>';
  3252. print '</tr>' . "\n";
  3253. } // if ($sum_post)
  3254. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . get_string('not_post', 'iassign') . '</td>' . "\n";
  3255. print '<td class=\'cell c0 actvity\' width=40%>' . $bar_nopost . '&nbsp;' . $text_nopost . '</td>';
  3256. print '<td class=\'cell c0 actvity\' width=10% align="right">' . $sum_nopost . '/' . $sum_iassign . '</td>';
  3257. print '</tr>' . "\n";
  3258. print "</table>";
  3259. print "<br><br>";
  3260. print '<table id="outlinetable" class="generaltable boxaligncenter" cellpadding="5" width="100%">' . "\n";
  3261. print '<tr><th colspan=3 class="header c1">' . get_string('grades', 'iassign') . '</th></tr>' . "\n";
  3262. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . iassign_utils::remove_code_message($this->iassign->name) . '</strong></td>' . "\n";
  3263. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_student', 'iassign') . '</strong></td>' . "\n";
  3264. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . get_string('grade_iassign', 'iassign') . '</strong></tr>' . "\n";
  3265. $sum_grade = 0;
  3266. $sum_grade_student = 0;
  3267. $avg = 0;
  3268. foreach ($iassign_statement_list as $iassign_statement_activity_item) {
  3269. $iassign_submission = $DB->get_record("iassign_submission", array('iassign_statementid' => $iassign_statement_activity_item->id, 'userid' => $USER->id));
  3270. if (!$iassign_submission) {
  3271. $iassign_submission = new stdClass();
  3272. $iassign_submission->grade = 0;
  3273. }
  3274. print '<tr ><td class=\'cell c0 actvity\'width=50%>' . $iassign_statement_activity_item->name . '</td>' . "\n";
  3275. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_submission->grade . '</td>';
  3276. print '<td class=\'cell c0 actvity\' width=25% align=right>' . $iassign_statement_activity_item->grade . '</td>';
  3277. print '</tr>' . "\n";
  3278. $sum_grade += $iassign_statement_activity_item->grade;
  3279. $sum_grade_student += $iassign_submission->grade;
  3280. } // foreach ($iassign_statement_list as $iassign_statement_activity_item)
  3281. if ($sum_grade > 0)
  3282. $avg = $sum_grade_student / $sum_grade * 100;
  3283. print '<tr><td class=\'cell c0 actvity\' width=50%><strong>' . get_string('total', 'iassign') . '</strong></td>' . "\n";
  3284. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade_student . '</strong></td>' . "\n";
  3285. print '<td class=\'cell c0 actvity\' width=25% align=right><strong>' . $sum_grade . '</strong></tr>' . "\n";
  3286. print '<tr><td class=\'cell c0 actvity\' width=25% align=left><strong>' . get_string('percentage_correct', 'iassign') . '</strong></td>' . "\n";
  3287. print '<td colspan=2 class=\'cell c0 actvity\' align=right><strong>' . number_format($avg, 1) . '%</strong></tr>' . "\n";
  3288. print "</table>";
  3289. print $OUTPUT->footer();
  3290. die();
  3291. } // function stats_students()
  3292. /// Display page of iAssign's activity
  3293. function view_iassigns () {
  3294. global $USER, $CFG, $COURSE, $DB, $OUTPUT;
  3295. $id = $this->cm->id;
  3296. $iassign_list = $DB->get_records_list('iassign_statement', 'iassignid', array('iassignid' => $this->iassign->id), 'position ASC');
  3297. $notice = optional_param('notice', '', PARAM_TEXT);
  3298. if (strpos($notice, 'error'))
  3299. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifyproblem'));
  3300. else if ($notice != '')
  3301. print($OUTPUT->notification(get_string($notice, 'iassign'), 'notifysuccess'));
  3302. print $OUTPUT->box_start();
  3303. print '<table width=100% border=0><tr>' . "\n";
  3304. $url_help = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'list', 'ilm_id' => 1));
  3305. $action_help = new popup_action('click', $url_help, 'iplookup', array('title' => get_string('help_ilm', 'iassign'), 'width' => 1200, 'height' => 700));
  3306. $link_help = $OUTPUT->action_link($url_help, iassign_icons::insert('help_ilm') . get_string('help_ilm', 'iassign'), $action_help);
  3307. $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>";
  3308. $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>";
  3309. // TODO: esta consulta esta sendo feita novamente na linha +/- 2258
  3310. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3311. // could be "has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)"
  3312. // Has capability to see "report": teacher or up
  3313. print '<td width=10% align="left">' . "\n";
  3314. print $link_help;
  3315. print '</td>' . "\n";
  3316. print '<td width=10% align="left">' . "\n";
  3317. print $link_report;
  3318. print '</td>' . "\n";
  3319. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3320. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3321. print '<td width=15% align="left">' . "\n";
  3322. print $link_add;
  3323. print "</td>\n";
  3324. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3325. //print '</tr></table>' . "\n";
  3326. print '<div style="float: right;">';
  3327. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3328. if ($iassign_list) {
  3329. print '<td align="right">' . "\n";
  3330. // $USER->iassignEdit == 0 view 'Turn editing off'
  3331. // $USER->iassignEdit == 1 view 'Turn editing on'
  3332. if (!isset($USER->iassignEdit))
  3333. $USER->iassignEdit = 0;
  3334. if ($USER->iassignEdit == 0) {
  3335. $bottonEdit_message = get_string('turneditingon', 'iassign');
  3336. $botton = 1;
  3337. } // if ($USER->iassignEdit == 0)
  3338. elseif ($USER->iassignEdit == 1) {
  3339. $bottonEdit_message = get_string('turneditingoff', 'iassign');
  3340. $botton = 0;
  3341. } // elseif ($USER->iassignEdit == 1)
  3342. $editPost = "" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&botton=" . $botton;
  3343. print "\n<form name='formEditPost' id='formEditPost' method='post' action='$editPost' enctype='multipart/form-data'>\n";
  3344. print " <input type=submit value='$bottonEdit_message'/>\n";
  3345. print "</form>\n";
  3346. print "</td>\n";
  3347. } // if ($iassign_list)
  3348. }
  3349. print '</tr></table>' . "\n";
  3350. // if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3351. // $this->view_legend_icons();
  3352. print $OUTPUT->box_end();
  3353. $iassign_array_exercise = array();
  3354. $i_exercise = 0;
  3355. $iassign_array_test = array();
  3356. $i_test = 0;
  3357. $iassign_array_example = array();
  3358. $i_example = 0;
  3359. $iassign_array_general = array();
  3360. $i_general = 0;
  3361. if ($iassign_list) {
  3362. if ($this->iassign->activity_group == 0) {
  3363. foreach ($iassign_list as $iassign) {
  3364. $iassign_array_general[$i_general] = $iassign;
  3365. $i_general ++;
  3366. }
  3367. } // if ($this->iassign->activity_group == 0)
  3368. else {
  3369. foreach ($iassign_list as $iassign) {
  3370. if ($iassign->type_iassign == 3) {
  3371. $iassign_array_exercise[$i_exercise] = $iassign;
  3372. $i_exercise ++;
  3373. } // if ($iassign->type_iassign == 3)
  3374. if ($iassign->type_iassign == 2) {
  3375. $iassign_array_test[$i_test] = $iassign;
  3376. $i_test ++;
  3377. } // if ($iassign->type_iassign == 2)
  3378. if ($iassign->type_iassign == 1) {
  3379. $iassign_array_example[$i_example] = $iassign;
  3380. $i_example ++;
  3381. } // if ($iassign->type_iassign == 1)
  3382. }
  3383. }
  3384. if ($iassign_array_exercise) {
  3385. $title = get_string('exercise', 'iassign').(count($iassign_array_exercise)>1?'s':'');
  3386. $this->show_iassign($title, $iassign_array_exercise, $i_exercise);
  3387. }
  3388. if ($iassign_array_test) {
  3389. $title = get_string('test', 'iassign').(count($iassign_array_test)>1?'s':'');
  3390. $this->show_iassign($title, $iassign_array_test, $i_test);
  3391. }
  3392. if ($iassign_array_example) {
  3393. $title = get_string('example', 'iassign').(count($iassign_array_example)>1?'s':'');;
  3394. $this->show_iassign($title, $iassign_array_example, $i_example);
  3395. }
  3396. if ($iassign_array_general) {
  3397. $title = "";
  3398. $this->show_iassign($title, $iassign_array_general, $i_general);
  3399. }
  3400. } else { // if ($iassign_list)
  3401. print $OUTPUT->notification(get_string('no_activity', 'iassign'), 'notifysuccess');
  3402. }
  3403. if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id))) {
  3404. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3405. print $OUTPUT->box_start();
  3406. print '<table width=100% border=0><tr>' . "\n";
  3407. print '<td width=10% align="left">' . "\n";
  3408. print $link_report;
  3409. print '</td>' . "\n";
  3410. print '</tr></table>' . "\n";
  3411. print $OUTPUT->box_end();
  3412. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3413. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id)) {
  3414. print $OUTPUT->box_start();
  3415. print '<table width=100% border=0><tr>' . "\n";
  3416. print '<td align="left">' . "\n";
  3417. print $link_add;
  3418. print '</td>' . "\n";
  3419. print '</tr></table>' . "\n";
  3420. print $OUTPUT->box_end();
  3421. } // if (has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3422. } // if (count($iassign_list) > 5 && !(has_capability('mod/iassign:submitiassign', $this->context, $USER->id)))
  3423. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id))
  3424. $this->view_legend_icons();
  3425. } // function view_iassigns()
  3426. /// Display all iAssigns
  3427. function show_iassign ($title, $iassign_array, $i) {
  3428. global $USER, $CFG, $DB, $OUTPUT, $PAGE;
  3429. $id = $this->cm->id;
  3430. print $OUTPUT->box_start();
  3431. print " <script type='text/javascript'>
  3432. //<![CDATA[
  3433. function validate_move () {
  3434. var radios = document.getElementsByName('iassign_destiny');
  3435. var formValid = false;
  3436. //alert('aqui validate_move()');
  3437. var i = 0;
  3438. while (!formValid && i < radios.length) {
  3439. if (radios[i].checked) formValid = true;
  3440. i++;
  3441. }
  3442. if (!formValid) {
  3443. document.getElementById('move_dest').classList.add('alert-danger');
  3444. }
  3445. return formValid;
  3446. }
  3447. var modal;
  3448. function load_move(id_ias) {
  3449. document.form_move_activity.iassign_current.value = id_ias;
  3450. modal.style.display = 'block';
  3451. var radios = document.getElementsByName('iassign_destiny');
  3452. var i = 0;
  3453. while (i < radios.length) {
  3454. radios[i].checked = false;
  3455. i++;
  3456. }
  3457. document.getElementById('move_dest').classList.remove('alert-danger');
  3458. }
  3459. function load_modal_elements() {
  3460. modal = document.getElementById('myModal');
  3461. var span = document.getElementById('close_modal');
  3462. span.onclick = function() {
  3463. modal.style.display = 'none';
  3464. }
  3465. window.onclick = function(event) {
  3466. if (event.target == modal) {
  3467. modal.style.display = 'none';
  3468. }
  3469. }
  3470. }
  3471. window.onload = load_modal_elements;
  3472. //]]>
  3473. </script>\n";
  3474. print " <div id='myModal' class='modal'>\n <div class='modal-content'>\n <span id='close_modal'>&times;</span>\n" .
  3475. " <div id='modal_title' class='moodle-dialogue-hd yui3-widget-hd'>" . get_string('move_activity', 'iassign') . "</div>\n" .
  3476. " <div style='padding: 10px; padding-left: 20px;' id='move_dest'>" . get_string('move_destination', 'iassign') . ":\n <div style='margin: 5px;'>";
  3477. $ccm = get_coursemodule_from_id('iassign', optional_param('id', 0, PARAM_INT));
  3478. $radio_buttons = " <form name='form_move_activity'><input type='hidden' name='action' value='move_activity' />
  3479. <input type='hidden' name='id' value='" . optional_param('id', NULL, PARAM_TEXT) . "' />
  3480. <input type='hidden' name='iassign_current' value='' />";
  3481. $course_sections = get_fast_modinfo($PAGE->course->id)->get_section_info_all();
  3482. $section = $course_sections[0];
  3483. $ids_sections = array_keys($section->__get('modinfo')->get_sections());
  3484. for ($k = 0; $k < count($ids_sections); $k++) {
  3485. $radio_buttons .= get_section_name($PAGE->course->id, $ids_sections[$k]). "<ul style='list-style-type: none'>";
  3486. for($j = 0; $j < count($section->__get('modinfo')->get_sections()[$ids_sections[$k]]); $j++) {
  3487. $c_cm = get_coursemodule_from_id('iassign', $section->__get('modinfo')->get_sections()[$ids_sections[$k]][$j]);
  3488. if ($c_cm) {
  3489. if ($ccm->instance == $c_cm->instance) {
  3490. $radio_buttons .= " <li><input type='radio' disabled='disabled' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3491. <label for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3492. }
  3493. else {
  3494. $radio_buttons .= " <li><input type='radio' id='radio_" . $c_cm->instance . "' name='iassign_destiny' value='" . $c_cm->instance . "'>
  3495. <label class='input_move' for='radio_" . $c_cm->instance . "'>" . $c_cm->name . "</label></li>\n";
  3496. }
  3497. }
  3498. }
  3499. $radio_buttons .= "</ul>";
  3500. }
  3501. print $radio_buttons . " <center><input type='submit' value='OK' onClick='return validate_move();' />\n &nbsp;
  3502. <input type='button' value='" . get_string('cancel', 'iassign') . "' onClick='modal.style.display = \'none\';' /></center>
  3503. </form>
  3504. </div></div> </div></div>\n";
  3505. print " <style>.modal {
  3506. display: none;
  3507. position: fixed;
  3508. z-index: 1;
  3509. left: 0;
  3510. top: 0;
  3511. width: 100%;
  3512. height: 100%;
  3513. overflow: scroll;
  3514. background-color: rgb(0,0,0);
  3515. background-color: rgba(0,0,0,0.4);
  3516. }
  3517. .modal-content {
  3518. background-color: #fefefe;
  3519. margin: 15% auto;
  3520. padding: 10px 10px;
  3521. border: 1px solid #888;
  3522. width: 50%;
  3523. }
  3524. #close_modal {
  3525. color: #aaa;
  3526. float: right;
  3527. font-size: 28px;
  3528. font-weight: bold;
  3529. margin-top: -15px;
  3530. margin-right: -3px;
  3531. }
  3532. #close_modal:hover,
  3533. #close_modal:focus {
  3534. color: black;
  3535. text-decoration: none;
  3536. cursor: pointer;
  3537. }
  3538. #modal_title {
  3539. min-height: 3rem;
  3540. color: initial;
  3541. background: initial;
  3542. font-size: 1.5rem;
  3543. line-height: 1.5;
  3544. padding: 15px;
  3545. border-bottom: 1px solid #e5e5e5;
  3546. }
  3547. .input_move {
  3548. width: 90%;
  3549. padding: 2px;
  3550. }
  3551. .input_move:hover {
  3552. background: #eff0ef;
  3553. }
  3554. </style>";
  3555. if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id)) {
  3556. print "<p><font color='#0000aa'><strong>" . $title . "</strong></font></p>";
  3557. for ($j = 0; $j < $i; $j ++) {
  3558. $iassign_current = $iassign_array[$j]->id;
  3559. // receiver=1 - message to teacher
  3560. // receiver=2 - message to student
  3561. $sum_comment = 0;
  3562. $iassign_submissions = $DB->get_records('iassign_submission', array('iassign_statementid' => $iassign_current));
  3563. foreach ($iassign_submissions as $iassign_submission) {
  3564. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '1');
  3565. $verify_message = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3566. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3567. if ($verify_message)
  3568. foreach ($verify_message as $tmp)
  3569. $sum_comment += $tmp;
  3570. } // foreach ($iassign_submissions as $iassign_submission)
  3571. if ($sum_comment == 0)
  3572. $comment_unread = "";
  3573. else {
  3574. $comment_unread_message = get_string('comment_unread', 'iassign');
  3575. if ($sum_comment == 1)
  3576. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3577. $comment_unread = "&nbsp;<a href='" . $CFG->wwwroot . "/mod/iassign/view.php?id=" . $id . "&action=report&iassignid=" . $this->iassign->id . "'><font color='red'>" .
  3578. iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font></a>";
  3579. }
  3580. if ($j == $i - 1)
  3581. $iassign_down = $iassign_array[$j]->id;
  3582. else
  3583. $iassign_down = $iassign_array[$j + 1]->id;
  3584. if ($j > 0)
  3585. $iassign_up = $iassign_array[$j - 1]->id;
  3586. else
  3587. $iassign_up = $iassign_array[$j]->id;
  3588. if ($iassign_array[$j]->visible == 0)
  3589. $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>";
  3590. else
  3591. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3592. $links .= $comment_unread;
  3593. if (has_capability('mod/iassign:editiassign', $this->context, $USER->id) && $USER->iassignEdit == 1) {
  3594. //D echo "id=$id, iassign_current=$iassign_current, iassign_up=$iassign_up, iassign_down=$iassign_down<br/>";
  3595. $str_aux = "&id=$id&iassign_current=$iassign_current&iassign_up=$iassign_up&iassign_down=$iassign_down";
  3596. $link_up = "&nbsp;<a href='view.php?action=up$str_aux'>" . iassign_icons::insert('move_up_iassign') . "</a>";
  3597. if ($j==0) // first activity
  3598. $link_down = "&nbsp;<a href='view.php?action=firstdown$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3599. else
  3600. $link_down = "&nbsp;<a href='view.php?action=down$str_aux'>" . iassign_icons::insert('move_down_iassign') . "</a>";
  3601. $link_delete = "&nbsp;<a href='view.php?action=delete$str_aux'>" . iassign_icons::insert('delete_iassign') . "</a>";
  3602. $link_visible_hide = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('hide_iassign') . "</a>";
  3603. $link_visible_show = "&nbsp;<a href='view.php?action=visible$str_aux'>" . iassign_icons::insert('show_iassign') . "</a>";
  3604. $link_edit = "&nbsp;<a href='view.php?action=edit$str_aux'>" . iassign_icons::insert('edit_iassign') . "</a>";
  3605. $link_duplicate_activity = "&nbsp;<a href='view.php?action=duplicate_activity$str_aux' >" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  3606. $link_move_activity = "&nbsp;<a href='#' onclick='load_move($iassign_current); return false;' >" . iassign_icons::insert('move_activity') . "</a>\n";
  3607. if (count($iassign_array) > 1) {
  3608. if ($j == 0)
  3609. $links .= $link_down;
  3610. elseif ($j == $i - 1)
  3611. $links .= $link_up;
  3612. else
  3613. $links .= $link_up . $link_down;
  3614. } // if (count($iassign_array) > 1)
  3615. $links .= $link_edit . $link_delete;
  3616. if ($iassign_array[$j]->visible == 0)
  3617. $links .= $link_visible_show;
  3618. else
  3619. $links .= $link_visible_hide;
  3620. $links .= $link_duplicate_activity . $link_move_activity;
  3621. } // if ($USER->iassignEdit == 1 && has_capability('mod/iassign:editiassign', $this->context, $USER->id))
  3622. print '<p>' . $links . '</p>' . "\n";
  3623. }
  3624. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id))
  3625. elseif (has_capability('mod/iassign:submitiassign', $this->context, $USER->id)) { // student
  3626. print '<table width=100% ><tr>' . "\n";
  3627. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3628. print '</tr></table>' . "\n";
  3629. for ($j = 0; $j < $i; $j ++) {
  3630. $icon_status = "";
  3631. $icon_comment = "";
  3632. if ($iassign_array[$j]->visible == 1) {
  3633. $iassign_current = $iassign_array[$j]->id;
  3634. $iassign_submission = $DB->get_record('iassign_submission', array('iassign_statementid' => $iassign_current, 'userid' => $USER->id));
  3635. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3636. $icon_status = "";
  3637. $icon_comment = "";
  3638. if ($iassign_submission) {
  3639. // receiver=1 - message to teacher
  3640. // receiver=2 - message to student
  3641. // $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");
  3642. $params = array('iassign_submissionid' => $iassign_submission->id, 'return_status' => '0', 'receiver' => '2');
  3643. $verify_message = $DB->get_record_sql(
  3644. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3645. " WHERE iassign_submissionid = :iassign_submissionid AND return_status= :return_status AND receiver= :receiver", $params);
  3646. if ($verify_message)
  3647. foreach ($verify_message as $tmp)
  3648. $sum_comment = $tmp;
  3649. if ($sum_comment > 0) {
  3650. $comment_unread_message = get_string('comment_unread', 'iassign');
  3651. if ($sum_comment == 1)
  3652. $comment_unread_message = get_string('comment_unread_one', 'iassign');
  3653. $icon_comment = "&nbsp;<font color='red'>" . iassign_icons::insert('comment_unread') . "&nbsp;($sum_comment&nbsp;" . $comment_unread_message . ")</font>";
  3654. }
  3655. // $icon_comment = iassign_icons::insert('comment_unread');
  3656. if ($iassign_array[$j]->type_iassign == 3) {
  3657. if ($iassign_array[$j]->show_answer == 1) {
  3658. if ($iassign_submission->status == 3)
  3659. $icon_status = iassign_icons::insert('correct');
  3660. elseif ($iassign_submission->status == 2)
  3661. $icon_status = iassign_icons::insert('incorrect');
  3662. elseif ($iassign_submission->status == 1)
  3663. $icon_status = iassign_icons::insert('post');
  3664. elseif ($iassign_submission->status == 0)
  3665. $icon_status = iassign_icons::insert('not_post');
  3666. } // if ($iassign_array[$j]->show_answer==1)
  3667. else {
  3668. if ($iassign_submission->status == 0)
  3669. $icon_status = iassign_icons::insert('not_post');
  3670. else
  3671. $icon_status = iassign_icons::insert('post');
  3672. }
  3673. } // if ($iassign_array[$j]->type_iassign == 3)
  3674. } // if ($iassign_submission)
  3675. elseif ($iassign_array[$j]->type_iassign == 3) {
  3676. $icon_status = iassign_icons::insert('not_post');
  3677. } // if ($iassign_array[$j]->type_iassign == 3)
  3678. print '<p>' . $icon_status . '&nbsp;' . $links . '&nbsp;' . $icon_comment . '</p>' . "\n";
  3679. } // if ($iassign_array[$j]->visible == 1)
  3680. } // for ($j = 0; $j < $i; $j++)
  3681. } else if (isguestuser()) {
  3682. print($OUTPUT->notification(get_string('no_permission_iassign', 'iassign'), 'notifyproblem'));
  3683. print '<table width=100% ><tr>' . "\n";
  3684. print "<td width=70% align='left'><font color='#0000aa'><strong>" . $title . "</strong></font></td>" . "\n";
  3685. print '</tr></table>' . "\n";
  3686. for ($j = 0; $j < $i; $j ++) {
  3687. $icon_status = "";
  3688. $icon_comment = "";
  3689. if ($iassign_array[$j]->visible == 1) {
  3690. $iassign_current = $iassign_array[$j]->id;
  3691. $links = "&nbsp;<a href='view.php?id=$id&userid_iassign=$USER->id&action=view&iassign_current=$iassign_current'>" . $iassign_array[$j]->name . "</a>";
  3692. print '<p>' . $links . '</p>' . "\n";
  3693. } // if ($iassign_array[$j]->visible == 1)
  3694. }
  3695. }
  3696. print $OUTPUT->box_end();
  3697. } // function show_iassign($title, $iassign_array, $i)
  3698. /// Show message of return
  3699. function return_home_course ($message) {
  3700. //D global $DB, $OUTPUT;
  3701. //D $link_return = "&nbsp;<a href='" . $this->return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  3702. //D echo $OUTPUT->box_start();
  3703. //D echo '<table width=100% border=0 valign="top">' . "\n";
  3704. //D echo '<tr><td align="left"><strong>' . "\n";
  3705. //D print_string($message, 'iassign');
  3706. //D echo '</strong></td>' . "\n";
  3707. //D echo '<td width=20% align="right">' . "\n";
  3708. //D echo $link_return;
  3709. //D echo '</td></tr></table>' . "\n";
  3710. //D echo $OUTPUT->box_end();
  3711. //D // echo $OUTPUT->footer();
  3712. redirect(new moodle_url($this->return . '&notice=' . $message));
  3713. exit;
  3714. }
  3715. /// Search comment of activity
  3716. function search_comment_submission ($iassign_submissionid) {
  3717. global $USER, $DB, $OUTPUT, $COURSE;
  3718. // $context = context_course::instance($COURSE->id);
  3719. $colorEdit1 = "#b7ceee"; // "#dce7ec"
  3720. $colorEdit2 = "#d2e5fc";
  3721. $has_capability = 0;
  3722. $comments = $DB->get_records_list('iassign_submission_comment', 'iassign_submissionid', array('iassign_submissionid' => $iassign_submissionid), 'timecreated DESC'); // 'ORDER BY "timecreated" ASC'
  3723. $text = "";
  3724. if ($comments) {
  3725. $even = 1;
  3726. foreach ($comments as $tmp) {
  3727. $user_data = $DB->get_record("user", array('id' => $tmp->comment_authorid));
  3728. // if (has_capability('mod/iassign:editiassign', $context, $tmp->comment_authorid)) {
  3729. // $text .= "<tr><td bgcolor='#fee7ae'><b> $user_data->firstname</b>&nbsp;(" . userdate($tmp->timecreated) . ")</br>\n";
  3730. // $text .= $tmp->comment . "</td></tr>";
  3731. //} else {
  3732. // $text .= "<tr><td bgcolor='#dce7ec'>&raquo;<b>" . $user_data->firstname . "</b>&nbsp;(" . userdate($tmp->timecreated) . "</br>\n";
  3733. $avatar = new user_picture($user_data);
  3734. $avatar->courseid = $COURSE->id;
  3735. $avatar->link = true;
  3736. $user_picture = $OUTPUT->render($avatar);
  3737. $user_picture = str_replace('"35"', '"45"', $user_picture);
  3738. if ($even) {
  3739. $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";
  3740. $even = 0;
  3741. } else {
  3742. $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";
  3743. $even = 1;
  3744. }
  3745. $text .= "<div style='padding-left: 0rem; padding-top: .2rem;'>" . $tmp->comment . "</div></td></tr>\n";
  3746. } // foreach ($comments as $tmp)
  3747. }
  3748. return $text;
  3749. }
  3750. /// Update comment of activity
  3751. function update_comment ($iassign_submissionid) {
  3752. global $USER, $DB, $OUTPUT;
  3753. if (!has_capability('mod/iassign:submitiassign', $this->context, $USER->id) || is_siteadmin())
  3754. $receiver = 1; // student message to teacher
  3755. else
  3756. $receiver = 2; // teacher message to student
  3757. $verify_message = $DB->get_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submissionid)); //
  3758. if ($verify_message) {
  3759. foreach ($verify_message as $message) {
  3760. if ($message->receiver == $receiver) {
  3761. $newentry = new stdClass();
  3762. $newentry->id = $message->id;
  3763. $newentry->return_status = 1;
  3764. if (!$DB->update_record('iassign_submission_comment', $newentry)) {
  3765. print_error('error_update', 'iassign');
  3766. } // if (!$DB->update_record('iassign_submission_comment', $newentry))
  3767. } // if ($message->receiver == $receiver)
  3768. // Trigger module viewed event.
  3769. $event = \mod_iassign\event\submission_comment_updated::create(array(
  3770. 'objectid' => $this->iassign->id,
  3771. 'context' => $this->context
  3772. ));
  3773. $event->add_record_snapshot('course', $this->course);
  3774. $event->trigger();
  3775. } // foreach ($verify_message as $message)
  3776. }
  3777. }
  3778. /// Record comment of activity
  3779. function write_comment_submission () {
  3780. global $USER, $CFG, $DB;
  3781. $id = $this->cm->id;
  3782. $submission_comment = optional_param('submission_comment', NULL, PARAM_TEXT);
  3783. $row = optional_param('row', 0, PARAM_INT);
  3784. $column = optional_param('column', 0, PARAM_INT);
  3785. $sum_comment = 0;
  3786. $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);
  3787. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('return_home') . get_string('return', 'iassign') . "</a>";
  3788. $str1 = trim($submission_comment);
  3789. $str2 = trim(get_string('box_comment_message', 'iassign'));
  3790. if (!empty($submission_comment) && (strcmp($str1, $str2) != 0)) { // there is comment and it is different from "previous"
  3791. //D $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current)); //MOOC 2016
  3792. if (has_capability('mod/iassign:submitiassign', $this->context, $USER->id) && !is_siteadmin()) { //MOOC '&& !is_siteadmin()'
  3793. $receiver = 1; // student message to teacher
  3794. $this->action = 'view';
  3795. //D $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassign_submission->iassign_statementid)); //MOOC 2016
  3796. //D $tousers = get_users_by_capability($this->context, 'mod/iassign:evaluateiassign'); //MOOC 2016
  3797. } else {
  3798. $receiver = 2; // teacher message to student
  3799. $this->action = 'viewsubmission';
  3800. //D $tousers = array(); //MOOC 2016
  3801. //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
  3802. }
  3803. //MOOC 2016: foi p/ 15 linhas acima:
  3804. $iassign_submission = $DB->get_record("iassign_submission", array("id" => $this->iassign_submission_current));
  3805. // verificar se existe uma submissão para o exercício e aluno informados
  3806. if (!$iassign_submission) {
  3807. $iassign_submission = $DB->get_record("iassign_submission", array("iassign_statementid" => $this->activity->get_activity()->id, "userid" => $USER->id));
  3808. }
  3809. if (!$iassign_submission) {
  3810. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $this->activity->get_activity()->id));
  3811. $id_submission = $this->new_submission($iassign_statement_activity_item->id, $this->userid_iassign, $receiver);
  3812. $this->iassign_submission_current = $id_submission;
  3813. } else {
  3814. $id_submission = $iassign_submission->id;
  3815. } // if (!$iassign_submission)
  3816. // $comments = $DB->get_record_sql("SELECT COUNT(iassign_submissionid) FROM {$CFG->prefix}ia_assign_submissions_comment
  3817. // WHERE iassign_submissionid = '$id_submission' and comment='$submission_comment' and comment_authorid='$USER->id'"); //
  3818. // Attention: this Moodle function 'get_record_sql' makes a replace in ':comment'
  3819. $params = array("iassign_submissionid" => $id_submission, "comment" => $submission_comment, "comment_authorid" => $USER->id);
  3820. $comments = $DB->get_record_sql(
  3821. "SELECT COUNT(iassign_submissionid) FROM {iassign_submission_comment} " .
  3822. " WHERE iassign_submissionid = :iassign_submissionid AND comment= :comment AND comment_authorid= :comment_authorid", $params);
  3823. if ($comments)
  3824. foreach ($comments as $tmp)
  3825. $sum_comment = $tmp;
  3826. if ($sum_comment == 0) {
  3827. $newentry = new stdClass();
  3828. $newentry->iassign_submissionid = $id_submission;
  3829. $newentry->comment_authorid = $USER->id;
  3830. $newentry->timecreated = time();
  3831. $newentry->comment = $submission_comment;
  3832. $newentry->receiver = $receiver;
  3833. $ia_assign_submissions_comment_id = $DB->insert_record('iassign_submission_comment', $newentry);
  3834. //T foreach ($tousers as $touser) { //TODO Para registrar mensagem na area do Moodle - tem que ativar '$tousers[] = $DB->get_record(...);' acima
  3835. //T $eventdata = new stdClass();
  3836. //T $eventdata->component = 'mod_iassign'; //your component name
  3837. //T $eventdata->name = 'comment'; //this is the message name from messages.php
  3838. //T $eventdata->userfrom = $USER;
  3839. //T $eventdata->userto = $touser;
  3840. //T $eventdata->subject = "Teste de Subject";
  3841. //T $eventdata->fullmessage = "Teste de Mensagem...";
  3842. //T $eventdata->fullmessageformat = FORMAT_PLAIN;
  3843. //T $eventdata->fullmessagehtml = "<b>Teste de Mensagem...</b>";
  3844. //T $eventdata->smallmessage = "Teste de Mensagem";
  3845. //T $eventdata->notification = 1; //this is only set to 0 for personal messages between users
  3846. //T // alteracao tulio faria
  3847. //T //message_send($eventdata);
  3848. //T } //MOOC 2016 - TODO NAO finalizado, iniciado pelo Tulio
  3849. // Trigger module viewed event.
  3850. $event = \mod_iassign\event\submission_comment_created::create(array(
  3851. 'objectid' => $this->iassign->id,
  3852. 'context' => $this->context
  3853. ));
  3854. $event->add_record_snapshot('course', $this->course);
  3855. $event->trigger();
  3856. }
  3857. } // if (!empty($submission_comment) && (strcmp($str1, $str2) != 0))
  3858. // if ($this->action=='viewsubmission') {
  3859. // echo $OUTPUT->header();
  3860. // $this->return_last('confirm_add_comment', $link_return);
  3861. // die;
  3862. // }
  3863. return true;
  3864. } // function write_comment_submission()
  3865. /// Writes a new submission
  3866. // The first student answer is under 'function get_answer()'
  3867. function new_submission ($iassignid, $id_user, $receiver) {
  3868. global $USER, $DB, $OUTPUT;
  3869. $newentry = new stdClass();
  3870. $newentry->iassign_statementid = $iassignid;
  3871. $newentry->userid = $id_user;
  3872. $newentry->timecreated = time();
  3873. $newentry->timemodified = time();
  3874. $newentry->answer = 0; // student only submit message
  3875. if ($receiver == 2) // teacher message to student (write id teacher)
  3876. $newentry->teacher = $USER->id;
  3877. if (!$newentry->id = $DB->insert_record("iassign_submission", $newentry))
  3878. return_home_course('error_insert_submissions');
  3879. else {
  3880. // Trigger module view event
  3881. $event = \mod_iassign\event\submission_created::create(array(
  3882. 'objectid' => $this->iassign->id,
  3883. 'context' => $this->context
  3884. ));
  3885. $event->add_record_snapshot('course', $this->course);
  3886. $event->trigger();
  3887. }
  3888. return $newentry->id;
  3889. }
  3890. /// Return to a specific address of page
  3891. function return_last ($message, $link_return) {
  3892. global $DB, $OUTPUT;
  3893. print $OUTPUT->box_start();
  3894. print '<table width=100% border=0 valign="top">' . "\n";
  3895. print '<tr><td align="left"><strong>' . "\n";
  3896. print_string($message, 'iassign');
  3897. print '</strong></td>' . "\n";
  3898. print '<td width=20% align="right">' . "\n";
  3899. print $link_return;
  3900. print '</td></tr></table>' . "\n";
  3901. print $OUTPUT->box_end();
  3902. print $OUTPUT->footer();
  3903. die();
  3904. } // function return_last($message, $link_return)
  3905. } // class iassign
  3906. /// Class for manage activities
  3907. class activity {
  3908. var $activity;
  3909. /// Constructor of class.
  3910. // @param int $id Id of activity
  3911. // 3.1 update PHP 7.0 compatibility for all moodle versions
  3912. //D public function activity($id) { self::__construct($id); }
  3913. function __construct ($id) {
  3914. global $DB;
  3915. $this->activity = $DB->get_record("iassign_statement", array("id" => $id));
  3916. if (empty($this->activity))
  3917. $this->activity = null;
  3918. }
  3919. /// Get an activity
  3920. // @return NULL
  3921. function get_activity () {
  3922. if ($this->activity != null)
  3923. return $this->activity;
  3924. else
  3925. return null;
  3926. }
  3927. /// Delete interactive activities
  3928. function delete ($return) {
  3929. global $USER, $CFG, $DB, $OUTPUT;
  3930. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3931. $output = $OUTPUT->header();
  3932. $output .= $OUTPUT->box_start();
  3933. $output .= "<p>" . get_string('delete_activity', 'iassign') . "&nbsp;<strong>" . $this->activity->name . "</strong></p>";
  3934. if ($iassign_submission_currents) {
  3935. $output .= "<p>" . get_string('number_submissions', 'iassign') . "&nbsp;<strong>" . count($iassign_submission_currents) . "</strong></p>";
  3936. if (!has_capability('mod/iassign:deleteiassignnotnull', $USER->context, $USER->id)) {
  3937. $output .= $OUTPUT->heading(get_string('delete_activity_permission_adm', 'iassign'));
  3938. $output .= $OUTPUT->single_button($return, get_string('return', 'iassign'), 'get');
  3939. $output .= $OUTPUT->box_end();
  3940. $output .= $OUTPUT->footer();
  3941. print $output;
  3942. die();
  3943. } // if (!has_capability('mod/iassign:deleteiassignnotnull', $this->context, $USER->id))
  3944. } // if ($iassign_submission_currents)
  3945. else
  3946. $output .= "<p>" . get_string('not_submissions_activity', 'iassign') . "</p>";
  3947. $output .= '<table width=50% border=0>';
  3948. $output .= '<tr valign="top"><td>';
  3949. $output .= "<p>" . get_string('what_do', 'iassign') . "</p>";
  3950. $output .= '</td><td>';
  3951. $bottonDelete_yes = get_string('delete_iassign', 'iassign');
  3952. $deleteiassignyes = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteyes&iassign_current=" . $this->activity->id;
  3953. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignyes' enctype='multipart/form-data'>";
  3954. $output .= " <input type=submit value='$bottonDelete_yes'/>\n";
  3955. $output .= "</form>\n";
  3956. $output .= '</td><td>';
  3957. $bottonDelete_no = get_string('delete_cancel', 'iassign');
  3958. $deleteiassignno = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm . "&action=deleteno&iassign_current=" . $this->activity->id;
  3959. $output .= "<form name='formDelete' id='formDelete' method='post' action='$deleteiassignno' enctype='multipart/form-data'>\n";
  3960. $output .= " <p><input type=submit value='$bottonDelete_no'/></p>\n";
  3961. $output .= "</form>\n";
  3962. $output .= '</td></tr></table>' . "\n";
  3963. $output .= $OUTPUT->box_end();
  3964. $output .= $OUTPUT->footer();
  3965. print $output;
  3966. } // function delete($return)
  3967. /// Function for confirm the delete of activity
  3968. // @param String $return Url of return
  3969. // @param Object $iassign Object content an activity
  3970. function deleteyes ($return, $iassign) {
  3971. global $USER, $CFG, $DB, $OUTPUT, $COURSE;
  3972. $msg = '';
  3973. if (!empty($this->activity->id)) {
  3974. $iassign_submission_currents = $DB->get_records("iassign_submission", array("iassign_statementid" => $this->activity->id));
  3975. if ($iassign_submission_currents) {
  3976. if (has_capability('mod/iassign:deleteassignnull', $USER->context, $USER->id)) {
  3977. foreach ($iassign_submission_currents as $iassign_submission)
  3978. $DB->delete_records('iassign_submission_comment', array('iassign_submissionid' => $iassign_submission->id));
  3979. $delete_iassign_submission_currents = $DB->delete_records("iassign_submission ", array("iassign_statementid" => $this->activity->id));
  3980. } // if ($iassign_submission_currents)
  3981. }
  3982. //$delete_iassign_statement_config = $DB->delete_records('iassign_statement_config', array('iassign_statementid' => $this->activity->id)); //MOOC 2016
  3983. // Remove all files associated to this activity:
  3984. $fs = get_file_storage();
  3985. $fs->delete_area_files($iassign->context->id, 'mod_iassign', 'exercise', $this->activity->id);
  3986. $this->delete_calendar($this->activity->id);
  3987. $delete_iassign_current = $DB->delete_records('iassign_statement', array('id' => $this->activity->id));
  3988. iassign::update_grade_iassign($this->activity->iassignid);
  3989. if ($delete_iassign_current) {
  3990. $iassign->return_home_course('confirm_delete_iassign');
  3991. //$msg = get_string ( 'confirm_delete_iassign', 'iassign' );
  3992. } else {
  3993. $iassign->return_home_course('error_confirm_delete_iassign');
  3994. //$msg = get_string ( 'error_confirm_delete_iassign', 'iassign' );
  3995. }
  3996. // if (($this->action == 'deleteyes') && (has_capability('mod/iassign:deleteassignnull', $this->context, $USER->id)))
  3997. }
  3998. }
  3999. /// Changes position of activities (between those inside a group of interactive activities)
  4000. // @param $move_action = must be "up" or "down"
  4001. // @param $target = if 'down' => is 'iassign_statement.id' of the activity bellow the current one; if 'up' => is activity above the current one
  4002. function move_iassign ($move_action, $target, $return) {
  4003. global $DB, $OUTPUT;
  4004. //D echo "mover: this->id=" . $this->activity->id . ", target = $target<br/>";
  4005. $initial_position_source = $this->activity->position; // the position of the "source activity" (that one to be moved)
  4006. $iassign_target = $DB->get_record("iassign_statement", array("id" => $target)); // "target activity" = the activity in the position the receive "source activity"
  4007. if ($move_action=="firstdown") {
  4008. $final_position_source = 2;
  4009. $final_position_target = 1;
  4010. }
  4011. else
  4012. if ($move_action=="down") {
  4013. $final_position_target = $this->activity->position;
  4014. $final_position_source = $final_position_target + 1;
  4015. }
  4016. else
  4017. if ($move_action=="up") {
  4018. $final_position_target = $this->activity->position;
  4019. $final_position_source = $final_position_target - 1;
  4020. }
  4021. else { // error:
  4022. print_error('error_update_move_iassign', 'iassign');
  4023. exit;
  4024. }
  4025. $newentry = new stdClass(); // define a new object (activity) to receive only 2 fields: 'id' and 'position'
  4026. $newentry->id = $this->activity->id; // ID of the "source activity"
  4027. $newentry->position = $final_position_source;
  4028. //D echo "mover: id=" . $this->activity->id . ": de " . $this->activity->position . " -> " . $final_position_source . "<br/>";
  4029. //D echo "mover: id=" . $iassign_target->id . ": de " . $iassign_target->position . " -> " . $final_position_target . "<br/>"; exit;
  4030. if (!$DB->update_record('iassign_statement', $newentry)) { // modify 'position' of the activity with 'id'=$target
  4031. print_error('error_update_move_iassign', 'iassign');
  4032. }
  4033. else { // first update performed successfully
  4034. $newentry->id = $iassign_target->id;
  4035. $newentry->position = $final_position_target;
  4036. if (!$DB->update_record('iassign_statement', $newentry))
  4037. print_error('error_update_move_iassign', 'iassign');
  4038. }
  4039. redirect($return);
  4040. }
  4041. /// Enable or disable the display of interactive activities
  4042. function visible_iassign ($return) {
  4043. global $DB;
  4044. $newentry = new stdClass();
  4045. $newentry->id = $this->activity->id;
  4046. $newentry->visible = $this->activity->visible == 0 ? 1 : 0;
  4047. if (!$DB->update_record('iassign_statement', $newentry))
  4048. print_error('error_update_visible_iassign', 'iassign');
  4049. redirect($return);
  4050. }
  4051. /// Add news interactive activities (register in table 'iassign_statement')
  4052. // @calledby this->add_edit_iassign() : $iassignid = $this->activity->new_iassign($result);
  4053. // @see ilm_manager.php: $ilm_manager_instance->ilm_editor_new();
  4054. function new_iassign ($param) {
  4055. global $DB;
  4056. $newentry = new stdClass();
  4057. $newentry->iassignid = $param->iassignid;
  4058. $newentry->name = $param->name;
  4059. $newentry->type_iassign = $param->type_iassign;
  4060. $newentry->store_all_submissions = $param->store_all_submissions;
  4061. // $newentry->proposition = $param->proposition; // 2019/02/13 - With the use of 'editor' in 'mform', field 'proposition' is Array ( [text] => <DESCRIPTION> [format] => 1 )
  4062. $proposition = $param->proposition;
  4063. if (is_array($proposition)) $proposition_text = $proposition['text'];
  4064. else $proposition_text = $proposition;
  4065. $newentry->proposition = $proposition_text; // Notice: Trying to get property of non-object
  4066. //TODO I used in 'iassign_form.php' '<select name='iassign_ilmid'...>' with 'optgroup' by hand! But MoodleForm clear/do not register the 'iassign_ilmid'
  4067. //TODO Then get it directly from the form data $_POST!
  4068. //TODO See: 'iassign_form.php' field 'iassign_ilmid' and here (above) 'function add_edit_iassign()'
  4069. if (!isset($param->iassign_ilmid) && isset($_POST['iassign_ilmid']))
  4070. $param->iassign_ilmid = $_POST['iassign_ilmid'];
  4071. $newentry->author_name = $param->author_name;
  4072. $newentry->author_modified_name = $param->author_modified_name;
  4073. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4074. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4075. //TODO criar o campo 'iassign_statement.filesid' e usar: $newentry->filesid = $param->file; // register 'files.id' here in 'iassign_statement.filesid'
  4076. $newentry->grade = $param->grade;
  4077. $newentry->timemodified = time();
  4078. $newentry->timecreated = time();
  4079. if ($param->type_iassign == 1) {
  4080. $newentry->timedue = 0;
  4081. $newentry->timeavailable = 0;
  4082. } // if ($param->type_iassign == 1)
  4083. else {
  4084. $newentry->timedue = $param->timedue;
  4085. $newentry->timeavailable = $param->timeavailable;
  4086. }
  4087. $newentry->preventlate = $param->preventlate;
  4088. $newentry->test = $param->test;
  4089. $newentry->special_param1 = $param->special_param1;
  4090. $newentry->visible = $param->visible;
  4091. $newentry->position = $param->position;
  4092. $newentry->max_experiment = $param->max_experiment;
  4093. $newentry->dependency = $param->dependency;
  4094. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4095. $newentry->show_answer = $param->show_answer;
  4096. $id = $DB->insert_record("iassign_statement", $newentry);
  4097. if ($id) {
  4098. $component = 'mod_iassign';
  4099. $filearea = 'exercise';
  4100. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4101. $file = $fs->get_file_by_id($param->file);
  4102. $itemid = $file->get_itemid() + $id; //TODO Verificar: melhor deixar "$itemid = $file->get_itemid()" pois assim 'files.itemid' guarda 'iassign_statement.id'???
  4103. // IGOR: itemid do arquivo é o mesmo que o id do statemente registrado acima:
  4104. //$itemid = $id;
  4105. // File already inserted in other context!
  4106. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  4107. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4108. $updateentry = new stdClass();
  4109. $updateentry->id = $id;
  4110. //TODO Implementar campo 'iassign_statement.filesid' e usar: $updateentry->filesid = $param->file; // register in 'iassign_statement' the 'files.id'
  4111. $updateentry->file = $newfile->get_itemid();
  4112. if (!$DB->update_record("iassign_statement", $updateentry))
  4113. print_error('error_add', 'iassign');
  4114. if ($param->type_iassign == 3)
  4115. iassign::update_grade_iassign($param->iassignid);
  4116. //TODO iLM_HTML5 :: //MOOC2014
  4117. //D $iassign_ilm_configs = $DB->get_records('iassign_ilm_config', array('iassign_ilmid' => $param->iassign_ilmid, 'visible' => '1'));
  4118. //D if ($iassign_ilm_configs) {
  4119. //D foreach ($iassign_ilm_configs as $iassign_ilm_config) {
  4120. //D if ($iassign_ilm_config->param_type != 'static') {
  4121. //D $newentry = new stdClass();
  4122. //D $newentry->iassign_statementid = $id;
  4123. //D $newentry->iassign_ilm_configid = $iassign_ilm_config->id;
  4124. //D $newentry->param_name = $iassign_ilm_config->param_name;
  4125. //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});
  4126. //D if (!$DB->insert_record("iassign_statement_config", $newentry))
  4127. //D print_error('error_add_param', 'iassign');
  4128. //D }
  4129. //D }
  4130. //D }
  4131. // log event --------------------------------------------------------------------------------------
  4132. iassign_log::add_log('add_iassign_exercise', 'name: ' . $param->name, $id, $param->iassign_ilmid);
  4133. // log event --------------------------------------------------------------------------------------
  4134. return $id;
  4135. }
  4136. else
  4137. print_error('error_add', 'iassign');
  4138. } // function new_iassign($param)
  4139. /// Add the calendar entries for this iassign
  4140. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4141. // @return bool
  4142. static function add_calendar ($iassignid) {
  4143. global $DB, $CFG;
  4144. require_once($CFG->dirroot . '/calendar/lib.php');
  4145. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4146. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4147. $event = new stdClass();
  4148. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4149. $event->description = $iassign_statement_activity_item->name;
  4150. $event->courseid = $iassign->course;
  4151. $event->groupid = 0;
  4152. $event->userid = 0;
  4153. $event->modulename = 'iassign';
  4154. $event->instance = $iassign->id;
  4155. $event->eventtype = 'due';
  4156. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4157. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4158. calendar_event::create($event);
  4159. }
  4160. /// Update the calendar entries for this iassign
  4161. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4162. // @return bool
  4163. function update_calendar ($iassignid, $olddescription) {
  4164. global $DB, $CFG;
  4165. require_once($CFG->dirroot . '/calendar/lib.php');
  4166. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4167. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4168. $event = new stdClass();
  4169. $event->id = 0;
  4170. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4171. if ($events) {
  4172. foreach ($events as $value) {
  4173. if ($value->description == $olddescription) {
  4174. $event->id = $value->id;
  4175. }
  4176. }
  4177. }
  4178. if ($event->id != 0) {
  4179. $event->name = $iassign->name . '&nbsp;-&nbsp;' . $iassign_statement_activity_item->name;
  4180. $event->description = $iassign_statement_activity_item->name;
  4181. $event->timestart = $iassign_statement_activity_item->timeavailable;
  4182. $event->timeduration = ($iassign_statement_activity_item->timedue - $iassign_statement_activity_item->timeavailable);
  4183. $calendarevent = calendar_event::load($event->id);
  4184. $calendarevent->update($event);
  4185. } else
  4186. $this->add_calendar($iassignid);
  4187. }
  4188. /// Update the calendar entries for this iassign
  4189. // @param int $coursemoduleid - Required to pass this in because it might not exist in the database yet
  4190. // @return bool
  4191. function delete_calendar ($iassignid) {
  4192. global $DB, $CFG;
  4193. require_once($CFG->dirroot . '/calendar/lib.php');
  4194. $iassign_statement_activity_item = $DB->get_record("iassign_statement", array("id" => $iassignid));
  4195. $iassign = $DB->get_record("iassign", array("id" => $iassign_statement_activity_item->iassignid));
  4196. $events = $DB->get_records('event', array('modulename' => 'iassign', 'instance' => $iassign->id));
  4197. if ($events) {
  4198. foreach ($events as $value) {
  4199. if ($value->description == $iassign_statement_activity_item->name) {
  4200. $DB->delete_records('event', array('id' => $value->id));
  4201. }
  4202. }
  4203. }
  4204. }
  4205. /// Update interactive activities
  4206. function update_iassign ($param) {
  4207. global $DB;
  4208. $component = 'mod_iassign';
  4209. $filearea = 'exercise';
  4210. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4211. $file = $fs->get_file_by_id($param->file);
  4212. $fileold = $fs->get_file_by_id($param->fileold);
  4213. if ($param->file != $param->fileold) {
  4214. if ($fileold) {
  4215. $fileoldarea = $fs->get_area_files($fileold->get_contextid(), $fileold->get_component(), $fileold->get_filearea(), $fileold->get_itemid());
  4216. foreach ($fileoldarea as $value) {
  4217. $value->delete();
  4218. }
  4219. }
  4220. if (!$fs->file_exists($param->context->id, $component, $filearea, $file->get_itemid(), $file->get_filepath(), $file->get_filename())) {
  4221. $itemid = $file->get_itemid() + $param->iassign_id;
  4222. $newfile = $fs->create_file_from_storedfile(array('contextid' => $param->context->id, 'component' => $component, 'filearea' => $filearea, 'itemid' => $itemid), $file);
  4223. $param->file = $newfile->get_itemid();
  4224. } else
  4225. $param->file = $file->get_itemid();
  4226. } else {
  4227. $param->file = $file->get_itemid();
  4228. }
  4229. $newentry = new stdClass();
  4230. $newentry->id = $param->iassign_id;
  4231. $newentry->name = $param->name;
  4232. $newentry->type_iassign = $param->type_iassign;
  4233. $newentry->store_all_submissions = $param->store_all_submissions;
  4234. //2019 $newentry->proposition = $param->proposition;
  4235. $proposition = $param->proposition;
  4236. if (is_array($proposition))
  4237. $proposition_text = $proposition['text'];
  4238. else
  4239. $proposition_text = $proposition;
  4240. $newentry->proposition = $proposition_text;
  4241. $newentry->iassign_ilmid = $param->iassign_ilmid;
  4242. $newentry->file = $param->file; // came from a file from 'get_file_storage()' (it is its ID)
  4243. $newentry->grade = $param->grade;
  4244. $newentry->author_modified_name = $param->author_modified_name;
  4245. $newentry->timemodified = time();
  4246. if ($param->type_iassign == 1) {
  4247. $newentry->timedue = 0;
  4248. $newentry->timeavailable = 0;
  4249. } // if ($param->type_iassign == 1)
  4250. else {
  4251. $newentry->timedue = $param->timedue;
  4252. $newentry->timeavailable = $param->timeavailable;
  4253. }
  4254. $newentry->preventlate = $param->preventlate;
  4255. $newentry->test = $param->test;
  4256. $newentry->special_param1 = $param->special_param1;
  4257. $newentry->visible = $param->visible;
  4258. $newentry->max_experiment = $param->max_experiment;
  4259. $newentry->dependency = $param->dependency;
  4260. $newentry->automatic_evaluate = $param->automatic_evaluate;
  4261. $newentry->show_answer = $param->show_answer;
  4262. if (!$DB->update_record("iassign_statement", $newentry))
  4263. print_error('error_update', 'iassign');
  4264. if ($param->type_iassign == 3) {
  4265. iassign::update_grade_iassign($param->iassignid);
  4266. }
  4267. //$id = $newentry->id; // MOOC 2016 --- inicio
  4268. //$iassign_activity_item_configs = $DB->get_records('iassign_statement_config', array('iassign_statementid' => $newentry->id));
  4269. //if ($iassign_activity_item_configs) {
  4270. //foreach ($iassign_activity_item_configs as $iassign_activity_item_config) {
  4271. // $newentry = new stdClass();
  4272. // $newentry->id = $iassign_activity_item_config->id;
  4273. // $newentry->param_value =(is_array($param->{'param_'.$iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4274. // $newentry->param_value =(is_array($param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) ? implode(",",
  4275. // $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid}) : $param->{'param_' . $iassign_activity_item_config->iassign_ilm_configid});
  4276. // if (!$DB->update_record("iassign_statement_config", $newentry))
  4277. // print_error('error_edit_param', 'iassign');
  4278. // }
  4279. // } // MOOC 2016 --- final
  4280. // log event --------------------------------------------------------------------------------------
  4281. iassign_log::add_log('update_iassign_exercise', 'name: ' . $param->name, $param->iassign_id, $param->iassign_ilmid);
  4282. // log event --------------------------------------------------------------------------------------
  4283. return $newentry->id;
  4284. // if ($param->type_iassign==3)
  4285. // $this->update_grade_iassign($param->iassignid);
  4286. } // function update_iassign($param)
  4287. /// Show information of activity
  4288. function show_info_iassign () {
  4289. global $DB, $OUTPUT;
  4290. $output = '<p><strong>' . get_string('proposition', 'iassign') . ':</strong>&nbsp;' . $this->activity->proposition . '</p>' . "\n";
  4291. if ($this->activity->type_iassign == 3) {
  4292. if ($this->activity->dependency == 0) {
  4293. $output .= '<p><strong>' . get_string('independent_activity', 'iassign') . '</strong></p>' . "\n";
  4294. } else {
  4295. $dependencys = explode(';', $this->activity->dependency);
  4296. $output .= '<p><strong>' . get_string('dependency', 'iassign') . '</strong></p>';
  4297. foreach ($dependencys as $dependency) {
  4298. $dependencyiassign = $DB->get_record("iassign_statement", array("id" => $dependency));
  4299. if ($dependencyiassign)
  4300. $output .= '<p>' . $dependencyiassign->name . '</p>' . "\n";
  4301. } // foreach ($dependencys as $dependency)
  4302. } // if ($iassign_statement_activity_item->dependency == 0)
  4303. if ($this->activity->max_experiment == 0)
  4304. $output .= '<p><strong>' . get_string('experiment', 'iassign') . '</strong>&nbsp;' . get_string('ilimit', 'iassign');
  4305. else
  4306. $output .= '<p><strong>' . get_string('experiment_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->max_experiment . "\n";
  4307. $output .= '&nbsp;&nbsp;&nbsp;<strong>' . get_string('grade_iassign', 'iassign') . '</strong>&nbsp;' . $this->activity->grade . '</p>' . "\n";
  4308. } // if ($iassign_statement_activity_item->type_iassign == 3)
  4309. print $OUTPUT->box($output);
  4310. } // function show_info_iassign()
  4311. /// Shows date of opening and closing activities
  4312. function view_dates () {
  4313. global $USER, $CFG, $DB, $OUTPUT;
  4314. $return = $CFG->wwwroot . "/mod/iassign/view.php?id=" . $USER->cm;
  4315. $link_return = "&nbsp;<a href='" . $return . "'>" . iassign_icons::insert('home') . get_string('activities_page', 'iassign') . "</a>";
  4316. $status_iassign = "";
  4317. $status_iassign1 = "";
  4318. $status_iassign2 = "";
  4319. if ($this->activity->type_iassign == 1) // activity of type example
  4320. $type_iassign = get_string('example_iassign', 'iassign');
  4321. elseif ($this->activity->type_iassign == 2) { // activity of type test
  4322. $type_iassign = get_string('test_iassign', 'iassign');
  4323. if ($this->activity->timeavailable > time()) {
  4324. $status_iassign = get_string('previous_timeavailable', 'iassign');
  4325. } elseif ($this->activity->timedue < time()) {
  4326. $status_iassign = get_string('last_timedue', 'iassign');
  4327. }
  4328. } elseif ($this->activity->type_iassign == 3) { // activity of type exercise
  4329. $type_iassign = get_string('exercise_iassign', 'iassign');
  4330. if ($this->activity->timeavailable > time()) {
  4331. $status_iassign = get_string('previous_timeavailable', 'iassign'); // before of deadline
  4332. } elseif ($this->activity->timedue < time()) { // after delivery
  4333. $status_iassign = get_string('last_timedue', 'iassign');
  4334. if ($this->activity->preventlate == 1) // permitted to submit after the deadline
  4335. $status_iassign1 = get_string('duedate_preventlate_enable', 'iassign');
  4336. elseif ($this->activity->preventlate == 0) { // not permitted to submit after the deadline
  4337. $status_iassign1 = get_string('duedate_preventlate_desable', 'iassign');
  4338. if ($this->activity->test == 1) // allowed to test after of deadline
  4339. $status_iassign2 = get_string('test_preventlate', 'iassign');
  4340. elseif ($this->activity->test == 0) { // not allowed to test after of deadline
  4341. $status_iassign2 = get_string('test_preventlate_no', 'iassign');
  4342. } // elseif ($iassign_statement_activity_item->test == 0)
  4343. } // elseif ($iassign_statement_activity_item->preventlate == 0)
  4344. } // elseif ($iassign_statement_activity_item->timedue < time())
  4345. } // elseif ($iassign_statement_activity_item->type_iassign == 3)
  4346. $output = '<table width=100% >' . "\n";
  4347. $output .= '<tr><td colspan=2><h4>' . $this->activity->name . '</h4></td></tr>' . "\n";
  4348. $output .= '<tr>' . "\n";
  4349. // TODO duvida: como permitir ao admin,professor,monitor ver a atividade mesmo apos prazo???
  4350. // Leo testes para passar por cima com 'has_capability('mod/iassign:...', $this->context, $USER->id)
  4351. $output .= '<td width=60%>' . $type_iassign . '</td>' . "\n";
  4352. // leo $output .= '<td width=80%>' . $type_iassign;
  4353. // $output .= $auxStr . " - status_assign=$status_iassign - this->activity->type_iassign=" . $this->activity->type_iassign. "<br/>"; // Period ended.
  4354. // $output .= '</td>' . "\n";
  4355. if (has_capability('mod/iassign:viewiassignall', $USER->context, $USER->id) && ($this->activity->type_iassign == 3)) {
  4356. // Link (with icon) to report survey of this batch of these insteractivy exercises
  4357. $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>";
  4358. $output .= '<td width=40% align="right">' . '&nbsp;' . $link_report . '</td>' . "\n";
  4359. } else {
  4360. $link_next = "";
  4361. $link_previous = "";
  4362. $iassign_previous = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position - 1));
  4363. $iassign_next = $DB->get_record('iassign_statement', array('iassignid' => $this->activity->iassignid, 'position' => $this->activity->position + 1));
  4364. // previous_activity
  4365. if ($iassign_previous) {
  4366. $url_previous = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_previous->id";
  4367. $link_previous = "<a href='" . $url_previous . "'>" . (iassign_icons::insert('previous_student_activity')) . "</a>";
  4368. } // next_activity
  4369. if ($iassign_next) {
  4370. $url_next = "view.php?id=$USER->cm&userid_iassign=$USER->id&action=view&iassign_current=$iassign_next->id";
  4371. $link_next = "<a href='" . $url_next . "'>" . (iassign_icons::insert('next_student_activity')) . "</a>";
  4372. }
  4373. $output .= '<td width=40% align="right">' . $link_previous . '&nbsp;&nbsp;&nbsp;' . $link_return . '&nbsp;&nbsp;&nbsp;' . $link_next . '</td>' . "\n";
  4374. } // if (has_capability('mod/iassign:viewiassignall', $this->context, $USER->id) && ($iassign_statement_activity_item->type_iassign == 3))
  4375. $output .= '</tr></table>' . "\n";
  4376. $output .= '<table width=100% >' . "\n";
  4377. if ($this->activity->type_iassign > 1) {
  4378. if ($this->activity->timeavailable)
  4379. $output .= '<tr><td width=50% align="left"> <strong>' . get_string('availabledate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timeavailable) . '</td>' . "\n";
  4380. if ($this->activity->timedue)
  4381. $output .= '<td width=50% align="left"><strong>' . get_string('duedate', 'iassign') . ':</strong>&nbsp;' . userdate($this->activity->timedue) . '</td>' . "\n";
  4382. } // if ($iassign_statement_activity_item->type_iassign > 1)
  4383. if ($status_iassign != "" && $status_iassign1 != "" && $status_iassign2 != "")
  4384. $output .= '<tr><td><font color="red">' . $status_iassign . '&nbsp;' . $status_iassign1 . '&nbsp;' . $status_iassign2 . '</font></td></tr>' . "\n";
  4385. $output .= '</table>' . "\n";
  4386. print $OUTPUT->box($output);
  4387. } // function view_dates()
  4388. } // class activity
  4389. /// Class to manage Interactive Learning Module (iLM)
  4390. class ilm {
  4391. var $ilm;
  4392. /// Constructor of class
  4393. // @param int $id Id of iLM
  4394. //D 3.1 update PHP 7.0 compatibility for all moodle versions
  4395. //D public function ilm($id) { self::__construct($iassign, $cm, $course); }
  4396. function __construct ($id) {
  4397. global $DB;
  4398. $this->ilm = $DB->get_record("iassign_ilm", array("id" => $id));
  4399. if (empty($this->ilm))
  4400. $this->ilm = null;
  4401. }
  4402. /// Shows activity in iLM ($iassign_statement_activity_item{author_name, iassign_ilmid, file, ...})
  4403. // @calledby view_iassign_current()
  4404. function view_iLM ($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion) {
  4405. global $USER, $CFG, $DB;
  4406. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $iassign_statement_activity_item->iassign_ilmid));
  4407. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4408. $typec = strtolower($iassign_ilm->type);
  4409. require_once 'ilm_handlers/' . $typec . '.php';
  4410. // ilm_handlers/html5.php (or ilm_handlers/java.php)
  4411. $retorno = $typec::show_activity_in_ilm($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion);
  4412. return $retorno;
  4413. } // function view_iLM($iassign_statement_activity_item, $student_answer, $enderecoPOST, $view_teacherfileversion)
  4414. /// Function to give a single access to an iLM content avoi (after used, 'view()', after 'view_iLM(...)', will erase the entry)
  4415. // @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);
  4416. // @param int $iassign_statement_activity_itemid Id of iassign statement
  4417. // @param Object $file File in use in activity
  4418. // @return int Return the id of log
  4419. function write_iLM_security ($iassign_activity_itemid, $content_or_id_from_ilm_security) {
  4420. global $CFG, $USER, $COURSE, $DB, $OUTPUT;
  4421. $newentry = new stdClass();
  4422. $newentry->iassign_statementid = $iassign_activity_itemid;
  4423. $newentry->userid = $USER->id;
  4424. $newentry->file = $content_or_id_from_ilm_security;
  4425. $newentry->timecreated = time();
  4426. $newentry->view = 1;
  4427. $id_iLM_security = $DB->insert_record("iassign_security", $newentry);
  4428. if (!$id_iLM_security) {
  4429. print_error('error_security', 'iassign'); // ./lib/setuplib.php: moodle_exception thrown
  4430. } // from (!$DB->insert_record("iassign_security", $newentry))
  4431. return $id_iLM_security;
  4432. }
  4433. /// Function to avoid that erros in remotion of entries in table 'iassign_security' allow future access to this contents
  4434. // @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);
  4435. // @param int $userid
  4436. // @param int $iassign_activity_itemid Id of iassign statement
  4437. function remove_old_iLM_security_entries ($userid, $iassign_activity_itemid) {
  4438. global $DB;
  4439. // 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")
  4440. $result = $DB->delete_records_select("iassign_security", "userid=" . $userid . " AND iassign_statementid<>" . $iassign_activity_itemid, null);
  4441. }
  4442. } // class ilm
  4443. /// Class to manage settings of iLM.
  4444. class ilm_settings {
  4445. /// Function to prepare tag to load iLM (that is stored in Moodle file system - usually /var/moodledata/filedir/).
  4446. // In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  4447. // @param int $ilm_id Id of iLM
  4448. // @param array $options An array with options for create dynamic tag html APPLET
  4449. // @return string Return with a tag html APPLET created
  4450. static function build_ilm_tags ($ilm_id, $options = array()) {
  4451. global $DB;
  4452. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4453. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4454. $typec = strtolower($iassign_ilm->type);
  4455. require_once 'ilm_handlers/' . $typec . '.php';
  4456. $retorno = $typec::build_ilm_tags($ilm_id, $options); // In 'ilm_handlers/html5.php' or 'ilm_handlers/java.php'
  4457. return $retorno;
  4458. } // static function build_ilm_tags($ilm_id, $options = array())
  4459. /// Function for get modified date of iLM file
  4460. // @param string $file_jar String with Ids of iLM files
  4461. // @return string Return with the filenames and modified date
  4462. static function applet_filetime ($file_jar) {
  4463. $filetime = "";
  4464. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4465. $files_jar = explode(",", $file_jar);
  4466. foreach ($files_jar as $one_file) {
  4467. $file = $fs->get_file_by_id($one_file);
  4468. if ($file)
  4469. $filetime .= "\n" . $file->get_filename() . ' (' . userdate($file->get_timemodified()) . ')' . '</br>';
  4470. }
  4471. return $filetime;
  4472. }
  4473. /// Function for verify an default applet
  4474. // @param String $file_jar String containing an list de ids of applet files
  4475. // @return boolean Return true or fale if applet is default
  4476. static function applet_default ($file_jar) {
  4477. $is_default = true;
  4478. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4479. $files_jar = explode(",", $file_jar);
  4480. foreach ($files_jar as $one_file) {
  4481. $file = $fs->get_file_by_id($one_file);
  4482. if ($file)
  4483. $is_default &= ($file->get_itemid() == 0);
  4484. }
  4485. return $is_default;
  4486. }
  4487. /// Function for get form variables for add, edit, or copy iLM
  4488. // @calledby settings_ilm.php (2 times, initially to fill the form, second to register the iLM)
  4489. // @see settings_form.php
  4490. // @see locallib.php : static function copy_new_version_ilm ($param) : perform the data register (files and database)
  4491. // @param int $ilm_id Id of iLM
  4492. // @param string $action String with the action
  4493. // @return object Return an object with forms variables
  4494. static function add_edit_copy_ilm ($ilm_id, $action) {
  4495. global $USER, $DB, $CFG;
  4496. require_once('settings_form.php'); // put the form
  4497. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4498. $param = new stdClass();
  4499. $param->action = $action;
  4500. $param->ilm_id = $ilm_id;
  4501. $CFG->action_ilm = $action;
  4502. $CFG->ilm_id = $ilm_id;
  4503. if ($action == 'add') {
  4504. $param->title = get_string('add_ilm', 'iassign');
  4505. $param->name = "";
  4506. $param->version = "";
  4507. $param->url = "";
  4508. $param->description = "";
  4509. $param->extension = "";
  4510. $param->author = $USER->id;
  4511. $param->file_jar = "";
  4512. $param->file_jar_static = "";
  4513. $param->file_class = "";
  4514. $param->width = 800;
  4515. $param->height = 600;
  4516. $param->enable = 0; // 0 - hide / 1 - show
  4517. $param->timecreated = time();
  4518. $param->timemodified = time();
  4519. $param->evaluate = 0;
  4520. $param->parent = 0;
  4521. }
  4522. elseif ($action == 'edit') { // static function add_edit_copy_ilm($ilm_id, $action)
  4523. if ($iassign_ilm) {
  4524. $description = json_decode($iassign_ilm->description);
  4525. $param->title = get_string('edit_ilm', 'iassign');
  4526. $param->id = $iassign_ilm->id;
  4527. $param->name_ilm = $iassign_ilm->name;
  4528. $param->name = $iassign_ilm->name;
  4529. $param->version = $iassign_ilm->version;
  4530. $param->ilm_type = $iassign_ilm->type;
  4531. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4532. $param->url = $iassign_ilm->url;
  4533. $param->submissionbehavior = $iassign_ilm->submissionbehavior;
  4534. $param->editingbehavior = $iassign_ilm->editingbehavior;
  4535. // If the iLM does not present curret language => Notice: Undefined property: stdClass::$en_us in...
  4536. if (!isset($description->{current_language()})) {
  4537. if (isset($description->{"en_us"})) $param->description = $description->{"en_us"};
  4538. else
  4539. if (isset($description->{"pt_br"})) $param->description = $description->{"pt_br"};
  4540. else $param->description = ""; //TODO Providenciar uma mensagem!? Pegar alguma lingua existente?
  4541. }
  4542. else
  4543. $param->description = $description->{current_language()};
  4544. $param->description_lang = $iassign_ilm->description;
  4545. $param->extension = $iassign_ilm->extension;
  4546. $param->author = $iassign_ilm->author;
  4547. $param->file_jar = $iassign_ilm->file_jar;
  4548. $param->file_jar_static = ilm_settings::applet_filetime($iassign_ilm->file_jar);
  4549. $param->file_class = $iassign_ilm->file_class;
  4550. $param->width = $iassign_ilm->width;
  4551. $param->height = $iassign_ilm->height;
  4552. $param->enable = $iassign_ilm->enable;
  4553. $param->timecreated = $iassign_ilm->timecreated;
  4554. $param->timemodified = time();
  4555. $param->evaluate = $iassign_ilm->evaluate;
  4556. $param->parent = $iassign_ilm->parent;
  4557. }
  4558. }
  4559. elseif ($action == 'new_version') { // Reaches this point from the form to add new iLM
  4560. // @see ./settings_ilm.php: $param = ilm_settings::add_edit_copy_ilm($ilm_id, $action);
  4561. // $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4562. if (!$iassign_ilm) { // The second turn (form sended) reaches this point - Just in case (if the admin use back and forward in the browser)
  4563. print get_string('empty_file', 'iassign') . "?<br/>\n"; //TODO warning not to use back?
  4564. // echo "Sem dados<br/>"; exit;
  4565. return;
  4566. }
  4567. $description = json_decode($iassign_ilm->description);
  4568. if ($iassign_ilm) {
  4569. if ($iassign_ilm->parent == 0)
  4570. $iassign_ilm->parent = $ilm_id;
  4571. $param->ilm_id = $ilm_id; //2019 after 'settings_ilm.php' it reaches this point again, better to define 'ilm_id'
  4572. $param->title = get_string('new_version_ilm', 'iassign');
  4573. $param->name_ilm = $iassign_ilm->name;
  4574. $param->name = $iassign_ilm->name;
  4575. $param->version = ""; // erase field 'version' - in order to present this field empty on the form (in 'settings_form.php')
  4576. $param->version_last = $iassign_ilm->version; //TODO not yet used!
  4577. $param->version = $iassign_ilm->version; // do not erase field 'version'
  4578. $param->ilm_type = $iassign_ilm->type;
  4579. $param->url = $iassign_ilm->url;
  4580. $param->description = $description->{current_language()};
  4581. $param->description_lang = $iassign_ilm->description; // JSON format: {"en":"Visual Interactive Programming on the Internet HTML5","pt_br":"Programação visual interativa na Internet"}
  4582. //D echo "locallib.php: add_edit_copy_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4583. $param->extension = $iassign_ilm->extension;
  4584. $param->author = $USER->id;
  4585. //D $param->file_jar = ''; // do not erase field 'file_jar'!
  4586. $param->file_jar = $iassign_ilm->file_jar; // do not erase field 'file_jar'!
  4587. $param->file_jar_static = '';
  4588. $param->file_class = $iassign_ilm->file_class;
  4589. $param->width = $iassign_ilm->width;
  4590. $param->height = $iassign_ilm->height;
  4591. $param->enable = 0;
  4592. $param->timecreated = time();
  4593. $param->timemodified = time();
  4594. $param->evaluate = $iassign_ilm->evaluate;
  4595. $param->parent = $iassign_ilm->parent;
  4596. }
  4597. }
  4598. elseif ($action == 'copy') {
  4599. $description = json_decode($iassign_ilm->description);
  4600. if ($iassign_ilm) {
  4601. if ($iassign_ilm->parent == 0)
  4602. $iassign_ilm->parent = $ilm_id;
  4603. $param->title = get_string('copy_ilm', 'iassign');
  4604. $param->id = $iassign_ilm->id;
  4605. $param->name_ilm = $iassign_ilm->name;
  4606. $param->name = $iassign_ilm->name;
  4607. $param->version = "";
  4608. $param->ilm_type = $iassign_ilm->type;
  4609. $param->type = $iassign_ilm->type; // using as 'type' in ilm_handlers/html5.php
  4610. $param->url = $iassign_ilm->url;
  4611. $param->description = $description->{current_language()};
  4612. $param->description_lang = $iassign_ilm->description;
  4613. $param->extension = $iassign_ilm->extension;
  4614. $param->author = $USER->id;
  4615. $param->file_jar = '';
  4616. $param->file_jar_static = '';
  4617. $param->file_class = $iassign_ilm->file_class;
  4618. $param->width = $iassign_ilm->width;
  4619. $param->height = $iassign_ilm->height;
  4620. $param->enable = 0;
  4621. $param->timecreated = time();
  4622. $param->timemodified = time();
  4623. $param->evaluate = $iassign_ilm->evaluate;
  4624. $param->parent = $iassign_ilm->parent;
  4625. }
  4626. }
  4627. return $param;
  4628. } // static function add_edit_copy_ilm($ilm_id, $action)
  4629. /// Function for save iLM file in moodledata
  4630. // @param int $itemid Itemid of file save in draft (upload file)
  4631. // @param int $ilm_id Id of iLM
  4632. // @return string Return an string with ids of iLM files
  4633. static function new_file_ilm ($itemid, $iassign_ilm) {
  4634. global $CFG, $USER, $DB;
  4635. $return = null;
  4636. $file_jar = array();
  4637. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4638. $contextuser = context_user::instance($USER->id);
  4639. $contextsystem = context_system::instance();
  4640. $files_ilm = $fs->get_area_files($contextuser->id, 'user', 'draft', $itemid);
  4641. if ($files_ilm) {
  4642. foreach ($files_ilm as $value) {
  4643. // CHECK IF file is HTML type
  4644. if ($iassign_ilm->type == 1) {
  4645. // Check if the file extension is ZIP
  4646. $ext = pathinfo($value->get_filename(), PATHINFO_EXTENSION);
  4647. // It is ZIP: copy it to the 'ilm_debug' and unpack it on directory 'ilm/'
  4648. if ((strtolower($ext) == 'zip')) {
  4649. // Coping...:
  4650. $destination = 'ilm_debug/' . $value->get_filename();
  4651. $value->copy_content_to($destination);
  4652. // Extracting content...:
  4653. $zip = new ZipArchive();
  4654. $extracted = './ilm';
  4655. $dir = "";
  4656. if ($zip->open($destination) === TRUE) {
  4657. $dir = './ilm/' . trim($zip->getNameIndex(0));
  4658. if (is_dir($dir)) {
  4659. $i = 1;
  4660. $previous = str_replace("/", "", $zip->getNameIndex(0));
  4661. while (file_exists('./ilm/' . $previous . "_" . $i)) {
  4662. $i ++;
  4663. }
  4664. $name = $previous . "_" . $i;
  4665. $dir = './ilm/' . $name . "/";
  4666. $j = 0;
  4667. while ($item_name = $zip->getNameIndex($j)) {
  4668. $zip->renameIndex($j, str_replace($previous, $name, $item_name));
  4669. $j++;
  4670. }
  4671. $zip->close();
  4672. }
  4673. $zip->open($destination);
  4674. $zip->extractTo($extracted);
  4675. $zip->close();
  4676. // After the extraction, remove it from DEBUG
  4677. unlink($destination);
  4678. } else { // Error trying to open destination...
  4679. // After the extraction error, also remove it from DEBUG
  4680. unlink($destination);
  4681. print_error('error_add_ilm_zip', 'iassign');
  4682. }
  4683. return $dir;
  4684. }
  4685. } // if ($iassign_ilm->type == 1)
  4686. if ($value->get_filename() != '.') {
  4687. $file_ilm = array(
  4688. 'userid' => $USER->id,
  4689. 'contextid' => $contextsystem->id,
  4690. 'component' => 'mod_iassign',
  4691. 'filearea' => 'ilm',
  4692. 'itemid' => rand(1, 999999999),
  4693. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($iassign_ilm->name) . '/' . iassign_utils::format_pathname($iassign_ilm->version) . '/',
  4694. 'filename' => $value->get_filename());
  4695. $file_ilm = $fs->create_file_from_storedfile($file_ilm, $value);
  4696. array_push($file_jar, $file_ilm->get_id());
  4697. }
  4698. }
  4699. if (!empty($file_jar)) {
  4700. $return = implode(",", $file_jar);
  4701. $old_file_jar = explode(",", $iassign_ilm->file_jar);
  4702. foreach ($old_file_jar as $value) {
  4703. $file = $fs->get_file_by_id($value);
  4704. if ($file)
  4705. $fs->delete_area_files($contextsystem->id, 'mod_iassign', 'ilm', $file->get_itemid());
  4706. }
  4707. }
  4708. }
  4709. else // if ($files_ilm)
  4710. $return = $iassign_ilm->file_jar;
  4711. $delete_file = $fs->delete_area_files($contextuser->id, 'user', 'draft', $itemid);
  4712. return $return;
  4713. } // static function new_file_ilm($itemid, $iassign_ilm)
  4714. /// Function for save in database an new iLM
  4715. // @param object $param An object with iLM params
  4716. static function new_ilm ($itemid) {
  4717. global $CFG, $USER, $OUTPUT;
  4718. // Verifica se existe algum XML anterior na pasta temp e o exclui
  4719. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  4720. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  4721. }
  4722. $pathtemp = $CFG->dataroot . '/temp/';
  4723. $contextuser = context_user::instance($USER->id);
  4724. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4725. $zip = new zip_packer();
  4726. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4727. foreach ($files as $file) {
  4728. if (!$file->is_directory())
  4729. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4730. }
  4731. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  4732. // Verifica se o pacote possui o XML
  4733. if (!$application_xml) {
  4734. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  4735. return;
  4736. } else {
  4737. $missing = "";
  4738. if (!isset($application_xml->name)) {
  4739. $missing .= "name";
  4740. }
  4741. if (!isset($application_xml->version)) {
  4742. $missing .= ", version";
  4743. }
  4744. if (!isset($application_xml->type)) {
  4745. $missing .= ", type";
  4746. }
  4747. if (!isset($application_xml->extension)) {
  4748. $missing .= ", extension";
  4749. }
  4750. if (!isset($application_xml->file_jar)) {
  4751. $missing .= ", file_jar";
  4752. }
  4753. if (!isset($application_xml->file_class)) {
  4754. $missing .= ", file_class";
  4755. }
  4756. if (!isset($application_xml->width)) {
  4757. $missing .= ", width";
  4758. }
  4759. if (!isset($application_xml->height)) {
  4760. $missing .= ", height";
  4761. }
  4762. if (!isset($application_xml->evaluate)) {
  4763. $missing .= ", evaluate";
  4764. }
  4765. if (strlen($missing) > 2) {
  4766. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  4767. return;
  4768. }
  4769. }
  4770. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4771. $typec = strtolower($application_xml->type);
  4772. require_once 'ilm_handlers/' . $typec . '.php';
  4773. $retorno = $typec::new_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  4774. return $retorno;
  4775. } // static function new_ilm($itemid)
  4776. /// Function for save in database an iLM edit
  4777. // @param object $param An object with iLM params
  4778. static function edit_ilm ($param, $itemid) {
  4779. // Descobrir o tipo de iLM:
  4780. global $DB, $USER, $CFG;
  4781. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->id));
  4782. $pathtemp = $CFG->dataroot . '/temp/';
  4783. $contextuser = context_user::instance($USER->id);
  4784. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4785. $zip = new zip_packer();
  4786. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4787. $files_extract = null;
  4788. foreach ($files as $file) {
  4789. if (!$file->is_directory())
  4790. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4791. }
  4792. // Get the iLM type (HTML5 or Java) to call the correspondent updater
  4793. $typec = strtolower($iassign_t->type);
  4794. require_once 'ilm_handlers/' . $typec . '.php';
  4795. $typec::edit_ilm($param, $itemid, $files_extract, $contextuser); // ilm_handlers/html5.php or ilm_handlers/java.php
  4796. }
  4797. /// Function for register the new iLM (in database and in the directory)
  4798. // @see settings_ilm.php : ilm_settings::copy_new_version_ilm($formdata)
  4799. // @param object $param An object with iLM params
  4800. static function copy_new_version_ilm ($param) {
  4801. global $DB, $CFG, $USER;
  4802. $itemid = $param->file;
  4803. $pathtemp = $CFG->dataroot . '/temp/';
  4804. //D echo "locallib.php: copy_new_version_ilm(...): param->description=" . $param->description . ", param->description_lang=". $param->description_lang . "<br/>";
  4805. //D echo "pathtemp=$pathtemp<br/>";
  4806. $contextuser = context_user::instance($USER->id);
  4807. $fs = get_file_storage(); // Get reference to all files in Moodle data
  4808. $zip = new zip_packer();
  4809. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  4810. $files_extract = null;
  4811. foreach ($files as $file) {
  4812. if (!$file->is_directory())
  4813. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  4814. }
  4815. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4816. $iassign_t = $DB->get_record('iassign_ilm', array('id' => $param->parent));
  4817. $typec = strtolower($iassign_t->type);
  4818. require_once 'ilm_handlers/' . $typec . '.php';
  4819. //D echo "locallib.php: copy_new_version_ilm(...): antes - param->description=" . $param->description . "<br/>";
  4820. $typec::copy_new_version_ilm($param, $files_extract); // ./mod/iassign/ilm_handlers/html5.php: in fact, here the new iLM is inserted
  4821. } // static function copy_new_version_ilm($param)
  4822. //VER::
  4823. //Notice: Undefined variable: output_ilm in ./mod/iassign/locallib.php on line 5054
  4824. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 192
  4825. //Notice: Trying to get property of non-object in ./mod/iassign/locallib.php on line 194
  4826. /// Function for change visibility of iLM
  4827. // @param int $ilm_id Id of iLM
  4828. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  4829. static function visible_ilm ($ilm_id, $status) {
  4830. global $DB;
  4831. if ($status == 0)
  4832. $visible = 1;
  4833. else
  4834. $visible = 0;
  4835. $newentry = new stdClass();
  4836. $newentry->id = $ilm_id;
  4837. $newentry->enable = $visible;
  4838. if (!$DB->update_record("iassign_ilm", $newentry))
  4839. error(get_string('error_edit_ilm', 'iassign'));
  4840. }
  4841. /// Function for confirm change default iLM
  4842. // @param int $ilm_id Id of iLM
  4843. // @param int $ilm_parent Id of parent iLM
  4844. // @return string Return with an string for create default page confirmation
  4845. static function confirm_default_ilm ($ilm_id, $ilm_parent) {
  4846. global $OUTPUT, $DB;
  4847. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4848. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4849. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'default', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4850. $return = $OUTPUT->heading(get_string('confirm_default', 'iassign') . ': ' . $iassign_ilm->name);
  4851. $return .= $OUTPUT->confirm(get_string('confirm_default_ilm', 'iassign') . $OUTPUT->help_icon('confirm_default_ilm', 'iassign'), $optionsyes, $optionsno);
  4852. return $return;
  4853. }
  4854. /// Function for change the default iLM
  4855. // @see settings_ilm.php
  4856. // @param int $ilm_id Id of iLM
  4857. // @return int Return Id of default iLM
  4858. static function default_ilm ($ilm_id) {
  4859. global $DB;
  4860. $iassign_ilm_default = $DB->get_record("iassign_ilm", array('id' => $ilm_id));
  4861. $iassign_ilm = $DB->get_record("iassign_ilm", array('id' => $iassign_ilm_default->parent));
  4862. $DB->delete_records("iassign_ilm", array('id' => $iassign_ilm_default->id));
  4863. $iassign_ilm_default->id = $iassign_ilm->id;
  4864. $iassign_ilm_default->parent = 0;
  4865. $iassign_ilm->parent = $iassign_ilm_default->id;
  4866. $iassign_ilm->id = 0;
  4867. $iassign_ilm_default->enable = 1;
  4868. if (!$DB->update_record("iassign_ilm", $iassign_ilm_default)) {
  4869. print_error('error_edit_ilm', 'iassign');
  4870. }
  4871. $inserted = $DB->insert_record("iassign_ilm", $iassign_ilm);
  4872. if (!$inserted) {
  4873. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In default_ilm(" . $ilm_id . ")<br/>\n";
  4874. print_error($msg_error);
  4875. //xx print_error('error_add_ilm', 'iassign');
  4876. }
  4877. return $iassign_ilm_default->id;
  4878. } // static function default_ilm ($ilm_id)
  4879. /// Function for confirm delete iLM
  4880. // @param int $ilm_id Id of iLM
  4881. // @param int $ilm_parent Id of parent iLM
  4882. // @return string Return with an string for create delete page confirmation
  4883. static function confirm_delete_ilm ($ilm_id, $ilm_parent) {
  4884. global $OUTPUT, $DB;
  4885. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4886. $optionsno = new moodle_url('/admin/settings.php', array('section' => 'modsettingiassign', 'action' => 'config', 'ilm_id' => $ilm_parent));
  4887. $optionsyes = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'delete', 'ilm_id' => $ilm_id, 'ilm_parent' => $ilm_parent));
  4888. return $OUTPUT->confirm(get_string('confirm_delete_ilm', 'iassign', $iassign_ilm->name . ' ' . $iassign_ilm->version), $optionsyes, $optionsno);
  4889. }
  4890. /// Function for delete directory where the iLM is allocated.
  4891. // @param string $dirPath
  4892. // @throws InvalidArgumentException
  4893. public static function delete_dir ($dirPath) {
  4894. if (substr($dirPath, strlen($dirPath) - 1, 1) != '/') {
  4895. $dirPath .= '/';
  4896. }
  4897. $files = glob($dirPath . '*', GLOB_MARK);
  4898. foreach ($files as $file) {
  4899. if (is_dir($file)) {
  4900. ilm_settings::delete_dir($file);
  4901. } else {
  4902. unlink($file);
  4903. }
  4904. }
  4905. rmdir($dirPath);
  4906. }
  4907. /// Function for delete iLM
  4908. // @param int $ilm_id Id of iLM
  4909. // @return int Return Id of parent iLM
  4910. static function delete_ilm ($ilm_id) {
  4911. global $DB;
  4912. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4913. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  4914. $typec = strtolower($iassign_ilm->type);
  4915. require_once 'ilm_handlers/' . $typec . '.php';
  4916. $retorno = $typec::delete_ilm($ilm_id);
  4917. return $retorno;
  4918. }
  4919. /// Function to export iLM package (ZIP file), eventually to install in other Moodle
  4920. // @param int $ilm_id Id of iLM
  4921. static function export_ilm ($ilm_id) {
  4922. global $DB;
  4923. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4924. if (!$iassign_ilm) return; // security debug...
  4925. // Get the iLM type ("HTML5" or "Java") and call the correspondent function in 'ilm_handlers'
  4926. $typec = strtolower($iassign_ilm->type);
  4927. if (!$typec) $typec = "html5"; // security debug...
  4928. require_once 'ilm_handlers/' . $typec . '.php';
  4929. $typec::export_ilm($ilm_id);
  4930. } // static function export_ilm($ilm_id)
  4931. //TODO iLM_HTML5 :: //MOOC 2016
  4932. // Function to export iLM package descriptor for allow online update. //TODO a ser usado onde? como?
  4933. // @param int $ilm_id Id of iLM
  4934. static function export_update_ilm ($ilm_id) {
  4935. global $DB, $CFG;
  4936. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  4937. $xml_filename = $CFG->dataroot . '/temp/ilm-upgrade_' . iassign_utils::format_pathname($iassign_ilm->name) . '.xml';
  4938. $zip_filename = 'ilm-' . iassign_utils::format_pathname($iassign_ilm->name . '-v' . $iassign_ilm->version) . '.ipz';
  4939. $upgrade_descriptor = '<?xml version="1.0" encoding="utf-8"?>' . "\n";
  4940. $upgrade_descriptor .= '<upgrade xmlns="http://line.ime.usp.br/application/1.5">' . "\n";
  4941. $upgrade_descriptor .= ' <version>' . $iassign_ilm->version . '</version>' . "\n";
  4942. $upgrade_descriptor .= ' <file>' . $zip_filename . '</file>' . "\n";
  4943. $upgrade_descriptor .= ' <description>' . iassign_language::json_to_xml($iassign_ilm->description) . "\n " . '</description>' . "\n";
  4944. $upgrade_descriptor .= '</upgrade>' . "\n";
  4945. file_put_contents($xml_filename, $upgrade_descriptor);
  4946. header("Pragma: public");
  4947. header("Expires: 0");
  4948. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  4949. header("Cache-Control: private", false);
  4950. header('Content-Type: application/xml; charset=utf-8');
  4951. header("Content-Disposition: attachment; filename=\"" . basename($xml_filename) . "\";");
  4952. header("Content-Length: " . @filesize($xml_filename));
  4953. set_time_limit(0);
  4954. @readfile("$xml_filename") || die("File not found.");
  4955. unlink($xml_filename);
  4956. exit;
  4957. } // static function export_update_ilm($ilm_id) //MOOC 2016
  4958. /// Function for save iLM from XML descriptor
  4959. // @param array $application_xml Data of XML descriptor
  4960. // @param array $files_extract Filenames of extract files
  4961. // @return array Return an array content id of JAR files
  4962. static function save_ilm_by_xml ($application_xml, $files_extract) {
  4963. global $CFG, $USER;
  4964. // Tratamento diferenciado se for do tipo HTML5:
  4965. $source = "";
  4966. $diretorio = "";
  4967. if (strtolower($application_xml->type) == 'html5') {
  4968. $i = 0;
  4969. foreach ($files_extract as $key => $value) {
  4970. $file = $CFG->dataroot . '/temp/' . $key;
  4971. // Verifica se já existe a pasta no diretório dos iLM:
  4972. if ($i == 0) {
  4973. $source = $file;
  4974. if (file_exists("ilm/" . basename($file))) {
  4975. $j = 1;
  4976. while (file_exists('ilm/' . basename($file) . "_" . $j)) {
  4977. $j ++;
  4978. }
  4979. $diretorio = 'ilm/' . basename($file) . "_" . $j;
  4980. // mkdir($diretorio, 0777, true);
  4981. mkdir($diretorio, 0755, true); // permissions: drwxr-xr-x
  4982. }
  4983. else {
  4984. $diretorio = 'ilm/' . basename($file);
  4985. // mkdir($diretorio, 0777, true);
  4986. mkdir($diretorio, 0755, true);
  4987. }
  4988. break;
  4989. }
  4990. $i ++;
  4991. }
  4992. foreach ($iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($source, RecursiveDirectoryIterator::SKIP_DOTS), RecursiveIteratorIterator::SELF_FIRST) as $item) {
  4993. if ($item->isDir()) {
  4994. mkdir($diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName(), 0755, true);
  4995. }
  4996. else {
  4997. copy($item, $diretorio . DIRECTORY_SEPARATOR . $iterator->getSubPathName());
  4998. }
  4999. }
  5000. ilm_settings::delete_dir($source);
  5001. return "./" . $diretorio;
  5002. }
  5003. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5004. $file_jar = array();
  5005. $files_ilm = explode(",", $application_xml->file_jar);
  5006. $contextsystem = context_system::instance();
  5007. foreach ($files_ilm as $value) {
  5008. $file_ilm = array(
  5009. 'userid' => $USER->id,
  5010. 'contextid' => $contextsystem->id,
  5011. 'component' => 'mod_iassign',
  5012. 'filearea' => 'ilm',
  5013. 'itemid' => rand(1, 999999999),
  5014. 'filepath' => '/iassign/ilm/' . iassign_utils::format_pathname($application_xml->name) . '/' . iassign_utils::format_pathname($application_xml->version) . '/',
  5015. 'filename' => $value);
  5016. $file_ilm = $fs->create_file_from_pathname($file_ilm, $CFG->dataroot . '/temp/' . $value);
  5017. array_push($file_jar, $file_ilm->get_id());
  5018. }
  5019. foreach ($files_extract as $key => $value) {
  5020. $file = $CFG->dataroot . '/temp/' . $key;
  5021. if (file_exists($file))
  5022. unlink($file);
  5023. }
  5024. return $file_jar;
  5025. } // static function save_ilm_by_xml($application_xml, $files_extract)
  5026. /// Function for import the iLM from an package
  5027. // @param int $itemid Itemid of zip file
  5028. static function import_ilm ($itemid) {
  5029. global $CFG, $USER, $OUTPUT;
  5030. // Verifica se existe algum XML anterior na pasta temp e o exclui
  5031. if (file_exists($CFG->dataroot . '/temp/' . 'ilm-application.xml')) {
  5032. unlink($CFG->dataroot . '/temp/' . 'ilm-application.xml');
  5033. }
  5034. $pathtemp = $CFG->dataroot . '/temp/';
  5035. $contextuser = context_user::instance($USER->id);
  5036. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5037. $zip = new zip_packer();
  5038. $files = $fs->get_directory_files($contextuser->id, 'user', 'draft', $itemid, '/');
  5039. foreach ($files as $file) {
  5040. if (!$file->is_directory())
  5041. $files_extract = $zip->extract_to_pathname($file, $pathtemp);
  5042. }
  5043. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5044. // Verifica se o pacote possui o XML
  5045. if (!$application_xml) {
  5046. print($OUTPUT->notification(get_string('error_xml_ilm', 'iassign'), 'notifyproblem'));
  5047. return;
  5048. } else {
  5049. $missing = "";
  5050. if (!isset($application_xml->name)) {
  5051. $missing .= "name";
  5052. }
  5053. if (!isset($application_xml->version)) {
  5054. $missing .= ", version";
  5055. }
  5056. if (!isset($application_xml->type)) {
  5057. $missing .= ", type";
  5058. }
  5059. if (!isset($application_xml->extension)) {
  5060. $missing .= ", extension";
  5061. }
  5062. if (!isset($application_xml->file_jar)) {
  5063. $missing .= ", file_jar";
  5064. }
  5065. if (!isset($application_xml->file_class)) {
  5066. $missing .= ", file_class";
  5067. }
  5068. if (!isset($application_xml->width)) {
  5069. $missing .= ", width";
  5070. }
  5071. if (!isset($application_xml->height)) {
  5072. $missing .= ", height";
  5073. }
  5074. if (!isset($application_xml->evaluate)) {
  5075. $missing .= ", evaluate";
  5076. }
  5077. if (strlen($missing) > 2) {
  5078. print($OUTPUT->notification(get_string('error_xml_missing', 'iassign') . $missing . ".", 'notifyproblem'));
  5079. return;
  5080. }
  5081. }
  5082. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5083. $typec = strtolower($application_xml->type);
  5084. require_once 'ilm_handlers/' . $typec . '.php';
  5085. $typec::import_ilm($itemid, $files_extract, $application_xml, $contextuser, $fs);
  5086. } // static function import_ilm($itemid)
  5087. /// Function for list iLM defaults
  5088. // @return string Return an string with a table of iLM
  5089. static function list_ilm () {
  5090. global $DB, $OUTPUT;
  5091. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1));
  5092. $str = '';
  5093. $str .= '<table id="outlinetable" cellpadding="5" width="100%" >' . "\n";
  5094. $str .= '<tr><td align=right><input type=button value="' . get_string('close', 'iassign') . '" onclick="javascript:window.close ();"></td></tr>';
  5095. if ($iassign_ilm) {
  5096. foreach ($iassign_ilm as $ilm) {
  5097. $url_view = new moodle_url('/mod/iassign/settings_ilm.php', array('action' => 'view', 'ilm_id' => $ilm->id));
  5098. $link_view = $OUTPUT->action_link($url_view, iassign_icons::insert('view_ilm') . ' ' . get_string('read_more', 'iassign'));
  5099. $str .= '<tr><td>';
  5100. $str .= '<table class="generaltable boxaligncenter" width="100%">';
  5101. $str .= '<tr>';
  5102. $str .= '<td class=\'cell c0 actvity\' width=40%><strong>' . get_string('name_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->name . '</td>' . "\n";
  5103. $str .= '<td><strong>' . get_string('version_ilm', 'iassign') . ':</strong>&nbsp;' . $ilm->version . '</td>' . "\n";
  5104. $str .= '<td align=right>' . $link_view . '</td>' . "\n";
  5105. $str .= '</tr>';
  5106. $str .= '<tr><td colspan=3>' . iassign_language::get_description_lang(current_language(), $ilm->description) . '</td></tr>';
  5107. $str .= '<tr><td colspan=3><a href="' . $ilm->url . '">' . $ilm->url . '</a></td></tr>';
  5108. $str .= '</table>';
  5109. $str .= '</td></tr>';
  5110. }
  5111. }
  5112. $str .= '</table>';
  5113. return $str;
  5114. }
  5115. /// Function for download and install an upgrade of an iLM
  5116. // @param int $ilm_id Id of iLM
  5117. static function upgrade_ilm ($ilm_id) {
  5118. global $DB, $CFG, $USER;
  5119. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilm_id));
  5120. $upgrade_file = $iassign_ilm->url . 'ilm-upgrade_' . strtolower($iassign_ilm->name) . '.xml';
  5121. $update_xml = @simplexml_load_file($upgrade_file, null, LIBXML_NOCDATA);
  5122. $result = file_put_contents($CFG->dataroot . '/temp/' . $update_xml->file, fopen($iassign_ilm->url . $update_xml->file, 'r'));
  5123. if (!$result)
  5124. print_error('error_upgrade_ilm', 'iassign');
  5125. else {
  5126. $zip_filename = $CFG->dataroot . '/temp/' . $update_xml->file;
  5127. $extension = explode(".", $zip_filename);
  5128. if ($extension[count($extension) - 1] != 'ipz') {
  5129. print($OUTPUT->notification(get_string('error_upload_ilm', 'iassign'), 'notifyproblem'));
  5130. die;
  5131. }
  5132. $zip = new zip_packer();
  5133. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5134. $contextuser = context_user::instance($USER->id);
  5135. $files_extract = $zip->extract_to_pathname($zip_filename, $CFG->dataroot . '/temp/');
  5136. $application_xml = @simplexml_load_file($CFG->dataroot . '/temp/' . 'ilm-application.xml', null, LIBXML_NOCDATA);
  5137. $description_str = htmlentities(str_replace(array('<description>', '</description>'), array('', ''), $application_xml->description->asXML()));
  5138. $file_jar = self::save_ilm_by_xml($application_xml, $files_extract);
  5139. if (file_exists($zip_filename))
  5140. unlink($zip_filename);
  5141. if (empty($file_jar)) {
  5142. $msg_error = get_string('error_add_ilm', 'iassign') . "<br/>In upgrade_ilm(" . $ilm_id . ")<br/>\n";
  5143. print_error($msg_error);
  5144. //xx print_error('error_add_ilm', 'iassign');
  5145. }
  5146. else {
  5147. $newentry = new stdClass();
  5148. $newentry->name = (String) $application_xml->name;
  5149. $newentry->version = (String) $application_xml->version;
  5150. $newentry->url = (String) $application_xml->url;
  5151. $newentry->description = $description_str;
  5152. $newentry->extension = strtolower((String) $application_xml->extension);
  5153. $newentry->file_jar = implode(",", $file_jar);
  5154. $newentry->file_class = (String) $application_xml->file_class;
  5155. $newentry->width = (String) $application_xml->width;
  5156. $newentry->height = (String) $application_xml->height;
  5157. $newentry->enable = 0;
  5158. $newentry->timemodified = time();
  5159. $newentry->author = $USER->id;
  5160. $newentry->timecreated = time();
  5161. $newentry->evaluate = (String) $application_xml->evaluate;
  5162. $newentry->parent = $ilm_id;
  5163. }
  5164. }
  5165. return $iassign_ilm->id;
  5166. } // static function upgrade_ilm($ilm_id)
  5167. //MOOC2014 -- inicio
  5168. //TODO: REVIEW
  5169. // static function confirm_move_iassign($ilmid, $ilm_parent)
  5170. // static function move_iassign($ilm_id)
  5171. //MOOC2014 -- final
  5172. /// Function for list iLM versions with all informations
  5173. // @return string Return an string with a table of iLM
  5174. static function view_ilm ($ilmid, $from) {
  5175. global $DB;
  5176. $iassign_ilm = $DB->get_record('iassign_ilm', array('id' => $ilmid));
  5177. // Faz a leitura do tipo de iLM e realiza a chamada à classe adequada
  5178. $typec = strtolower($iassign_ilm->type);
  5179. require_once 'ilm_handlers/' . $typec . '.php';
  5180. $retorno = $typec::view_ilm($ilmid, $from);
  5181. return $retorno;
  5182. }
  5183. /// Function for get form variables for add, edit, or copy iLM params
  5184. // @param int $ilm_param_id Id of iLM param
  5185. // @param string $action String with the action
  5186. // @return object Return an object with forms variables
  5187. static function add_edit_copy_param ($ilm_param_id, $action) {
  5188. global $DB;
  5189. require_once('params_form.php');
  5190. $iassign_ilm_config = $DB->get_record('iassign_ilm_config', array('id' => $ilm_param_id));
  5191. $param = new stdClass();
  5192. $param->action = $action;
  5193. $param->ilm_param_id = $ilm_param_id;
  5194. $type = optional_param('type', NULL, PARAM_TEXT); //MOOC2014
  5195. if ($type == NULL && $iassign_ilm_config) //MOOC2014
  5196. $type = $iassign_ilm_config->param_type;
  5197. if ($action == 'add') {
  5198. $param->title = get_string('add_ilm', 'iassign');
  5199. $param->iassign_ilmid = $ilm_param_id;
  5200. $param->param_name = "";
  5201. $param->param_value = "";
  5202. $param->description = "";
  5203. $param->visible = 1;
  5204. }
  5205. elseif ($action == 'edit') {
  5206. if ($iassign_ilm_config) {
  5207. $param->title = get_string('edit_ilm', 'iassign');
  5208. $param->id = $iassign_ilm_config->id;
  5209. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5210. $param->param_type = $type; //MOOC2014
  5211. $param->param_name = $iassign_ilm_config->param_name;
  5212. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5213. $param->param_value = $iassign_ilm_config->param_value;
  5214. else //MOOC2014
  5215. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5216. $param->param_value = $iassign_ilm_config->param_value;
  5217. $param->description = $iassign_ilm_config->description;
  5218. $param->visible = $iassign_ilm_config->visible;
  5219. }
  5220. }
  5221. elseif ($action == 'copy') {
  5222. if ($iassign_ilm_config) {
  5223. $param->title = get_string('copy_ilm', 'iassign');
  5224. $param->iassign_ilmid = $iassign_ilm_config->iassign_ilmid;
  5225. $param->param_type = $type; //MOOC2014
  5226. $param->param_name = $iassign_ilm_config->param_name;
  5227. if ($type != 'choice' && $type != 'multiple') //MOOC2014
  5228. $param->param_value = $iassign_ilm_config->param_value;
  5229. else //MOOC2014
  5230. $param->param_value = str_replace(", ", "\n", $iassign_ilm_config->param_value); //MOOC2014
  5231. $param->description = $iassign_ilm_config->description;
  5232. $param->visible = $iassign_ilm_config->visible;
  5233. }
  5234. }
  5235. return $param;
  5236. } // static function add_edit_copy_param($ilm_param_id, $action)
  5237. /// Function for change visibility of iLM param
  5238. // @param int $ilm_param_id Id of iLM param
  5239. // @param int $status Indicator of change vibility (0 = hide, 1 = show)
  5240. static function visible_param ($ilm_param_id, $status) {
  5241. global $DB, $CFG;
  5242. if ($status == 0)
  5243. $visible = 1;
  5244. else
  5245. $visible = 0;
  5246. $newentry = new stdClass();
  5247. $newentry->id = $ilm_param_id;
  5248. $newentry->visible = $visible;
  5249. if (!$DB->update_record("iassign_ilm_config", $newentry))
  5250. error(get_string('error_edit_param', 'iassign'));
  5251. }
  5252. /// Function for save in database an new iLM param
  5253. // @param object $param An object with iLM params
  5254. static function add_param ($param) {
  5255. global $DB;
  5256. $newentry = new stdClass();
  5257. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5258. //MOOC2014 $newentry->param_name = $param->param_name;
  5259. $newentry->param_type = $param->param_type; //MOOC2014
  5260. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5261. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5262. $newentry->param_value = $param->param_value;
  5263. else //MOOC2014
  5264. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5265. $newentry->description = $param->description;
  5266. $newentry->visible = $param->visible;
  5267. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5268. if (!$newentry->id) {
  5269. print_error('error_add_param', 'iassign');
  5270. }
  5271. }
  5272. /// Function for save in database a iLM param edit
  5273. // @param object $param An object with iLM params
  5274. static function edit_param ($param) {
  5275. global $DB;
  5276. $updentry = new stdClass();
  5277. $updentry->id = $param->id;
  5278. $updentry->iassign_ilmid = $param->iassign_ilmid;
  5279. $updentry->param_type = $param->param_type; //MOOC2014
  5280. // $updentry->param_name = $param->param_name;
  5281. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5282. if ($updentry->param_type != 'choice' && $updentry->param_type != 'multiple') //MOOC2014
  5283. $updentry->param_value = $param->param_value;
  5284. else //MOOC2014
  5285. $updentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5286. $updentry->description = $param->description;
  5287. $updentry->visible = $param->visible;
  5288. if (!$DB->update_record("iassign_ilm_config", $updentry)) {
  5289. error(get_string('error_edit_param', 'iassign'));
  5290. }
  5291. }
  5292. /// Function for save in database a iLM param copy
  5293. // @param object $param An object with iLM params
  5294. static function copy_param ($param) {
  5295. global $DB;
  5296. $newentry = new stdClass();
  5297. $newentry->iassign_ilmid = $param->iassign_ilmid;
  5298. //$newentry->param_name = $param->param_name;
  5299. $newentry->param_name = iassign_utils::format_filename($param->param_name); //MOOC2014
  5300. if ($newentry->param_type != 'choice' && $newentry->param_type != 'multiple') //MOOC2014
  5301. $newentry->param_value = $param->param_value;
  5302. else //MOOC2014
  5303. $newentry->param_value = str_replace("\r\n", ", ", $param->param_value); //MOOC2014
  5304. $newentry->description = $param->description;
  5305. $newentry->visible = $param->visible;
  5306. $newentry->id = $DB->insert_record("iassign_ilm_config", $newentry);
  5307. if (!$newentry->id) {
  5308. print_error('error_add_param', 'iassign');
  5309. }
  5310. }
  5311. /// Function for delete iLM param of database
  5312. // @param int $param_id Id of iLM param
  5313. static function delete_param ($param_id) {
  5314. global $DB;
  5315. if (!$DB->delete_records("iassign_ilm_config", array('id' => $param_id))) {
  5316. print_error('error_delete_param', 'iassign');
  5317. }
  5318. }
  5319. } // class ilm_settings
  5320. /// Class for manage iLM files (editor).
  5321. class ilm_manager {
  5322. var $id; // course id
  5323. var $url;
  5324. var $from;
  5325. /// Constructor for the base ilm_manager class
  5326. // 3.1 update PHP 7.0 compatibility for all moodle versions
  5327. //D public function ilm_manager($id, $url, $from) { self::__construct($iassign, $cm, $course); }
  5328. function __construct ($id, $url, $from) {
  5329. $this->id = $id; // course id
  5330. $this->url = $url;
  5331. $this->from = $from;
  5332. }
  5333. /// Function to get iAssign content file in Moodle data (exercise)
  5334. // @calledby x function preview_ilm($iassign_ilm) :
  5335. // @calledby ilm_manager.php : with 'action=get' in '$ilm_manager_instance->get_file_ilm($ilmid, $fileid)'
  5336. function get_file_ilm () {
  5337. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5338. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5339. //$filename = optional_param('filename', NULL, PARAM_TEXT);
  5340. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5341. $md_file = $fs->get_file_by_id($fileid);
  5342. $ilm_content_file = $md_file->get_content();
  5343. return $ilm_content_file;
  5344. }
  5345. /// Function for creating a new file from the iLM online editor
  5346. // @calledby ilm_manager.php: case 'new': $ilm_manager_instance->ilm_editor_new();
  5347. function ilm_editor_new () {
  5348. global $CFG, $DB, $OUTPUT, $PAGE;
  5349. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5350. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5351. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5352. $context = context_course::instance($this->id);
  5353. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5354. // verify if the JAR file $PAGE->set_course($course); is registered in DB (table '*_iassign_ilm')
  5355. if (!$iassign) {
  5356. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifysuccess');
  5357. die();
  5358. }
  5359. $temp = explode(",", $iassign->extension);
  5360. $extension = $temp[0]; // default extension for this iLM
  5361. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o nome do arquivo (e.g. limpa brancos)
  5362. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5363. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 2
  5364. // $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW); // iLM 1
  5365. if ($stringArchiveContent != NULL) {
  5366. // $stringArchiveContent = $_POST['iLM_PARAM_ArchiveContent'];
  5367. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5368. //2016/02/16: $filename = optional_param('filename', NULL, PARAM_ALPHANUMEXT);
  5369. $filename = optional_param('filename', NULL, PARAM_RAW);
  5370. //Leo $filename = iassign_utils::format_filename($filename); //
  5371. $filename = iassign_utils::filter_filename_extension($filename, $extension); // here: class iassign_utils
  5372. //2019/02 It is not necessary, since 'iassign_utils::filter_filename_extension(...)' does all the work!
  5373. //2019/02 $arrayfilename = explode(".", $filename);
  5374. //2019/02 // if (count($arrayfilename) == 1) $filename = $arrayfilename[0] . '.' . $extension;
  5375. //2019/02 $count_dots = count($arrayfilename);
  5376. //2019/02 if ($count_dots > 0) { // at least one dot mark
  5377. //2019/02 $last_name = $arrayfilename[$count_dots - 1];
  5378. //2019/02 if ($last_name != $extension)
  5379. //2019/02 $filename = $filename . '.' . $extension;
  5380. //2019/02 }
  5381. //2019/02 else { // no extension...
  5382. //2019/02 $filename = $filename . '.' . $extension;
  5383. //2019/02 }
  5384. // Store the name of recent created file
  5385. $_SESSION['file_name'] = $filename;
  5386. //$this->write_file_iassign($string, $filename);
  5387. // Register and (by JS.alet(.)) inform the user about the result (and the final name of the file)
  5388. $this->write_file_iassign($stringArchiveContent, $filename); // class ilm_manager - inform the user about the file insertion result
  5389. die();
  5390. }
  5391. else { // if ($stringArchiveContent != NULL)
  5392. // iLM On-line editor
  5393. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5394. $str_get_iLM = "window.frames.iLM";
  5395. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5396. }
  5397. else { // otherwise it is JAR named 'iLM'
  5398. $str_get_iLM = "document.iLM";
  5399. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5400. }
  5401. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5402. $files = $fs->get_area_files($context->id, 'mod_iassign', 'activity');
  5403. $files_array = '';
  5404. foreach ($files as $value) {
  5405. if ($value->get_filename() != ".")
  5406. $files_array .= "'" . $value->get_filename() . "',";
  5407. }
  5408. $files_array .= "''";
  5409. $file = null;
  5410. $ia_content = "";
  5411. $filename = "";
  5412. $error_files_exists = get_string('error_file_exists', 'iassign');
  5413. $output = "<script type='text/javascript'>
  5414. //<![CDATA[
  5415. //D alert('locallib.php: ilm_editor_new');
  5416. function submit_iLM_Answer () {
  5417. var docFormOnLineEditor = document.formEnvio;
  5418. var resposta_exerc = new Array(3);
  5419. var valor_resposta = new Array(3);
  5420. var sessao = new Array(3);
  5421. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5422. resposta_exerc[0] = doc_iLM.getAnswer();
  5423. valor_resposta[0] = doc_iLM.getEvaluation();
  5424. docFormOnLineEditor.iLM_PARAM_ActivityEvaluation.value = valor_resposta[0];
  5425. docFormOnLineEditor.iLM_PARAM_ArchiveContent.value = resposta_exerc[0];
  5426. var files = new Array(" . $files_array . ");
  5427. var filename = docFormOnLineEditor.filename.value+'.'+'" . $extension . "';
  5428. if (docFormOnLineEditor.filename.value=='') {
  5429. // ERROR: the file name is empty
  5430. alert('" . get_string('error_file_null_iassign', 'iassign') . "');
  5431. return false;
  5432. }
  5433. // }
  5434. for (i=0; i<files.length; i++) {
  5435. if (files[i]==docFormOnLineEditor.filename.value || files[i]==filename) {
  5436. alert('" . $error_files_exists . "');
  5437. return false;
  5438. }
  5439. }
  5440. docFormOnLineEditor.submit();
  5441. return true;
  5442. }
  5443. //]]>
  5444. </script>\n";
  5445. $output .= "
  5446. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5447. $output .= $OUTPUT->box_start();
  5448. // Put text "File name" and the corresponding "input" to enter the file nama: "File name: [ ]"
  5449. $output .= "
  5450. <table width='100%' cellpadding='20'>
  5451. <tr><td>" . get_string('label_file_iassign', 'iassign') . " <input type='text' name='filename' size=50/>
  5452. <input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='" . $str_submitbutton_name . ";'/></td>
  5453. </tr>
  5454. </table>\n";
  5455. $output .= $OUTPUT->box_end();
  5456. $output .= "<center>\n";
  5457. // Prepare tag to load the iLM. In case of JAR it will prepare the tag "applet". In case of HTML5 will prepare an "iframe".
  5458. // Since it is the activity file, it is not necessary to use 'ilm_security'
  5459. $output_ilm = ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_new", "notSEND" => "true"));
  5460. $output .= $output_ilm;
  5461. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value='" . $ia_content . "'>
  5462. <input type='hidden' name='iLM_PARAM_ActivityEvaluation'>
  5463. </center>
  5464. </form>\n";
  5465. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5466. $PAGE->navbar->add($title);
  5467. $PAGE->set_title($title);
  5468. $PAGE->set_heading($title); // insert title above the navigation bar
  5469. print $OUTPUT->header();
  5470. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5471. print $output;
  5472. print $OUTPUT->footer();
  5473. }
  5474. die();
  5475. } // function ilm_editor_new()
  5476. /// Function for editing an file in online editor
  5477. // @calledby ilm_manager.php: case 'update': $ilm_manager_instance->ilm_editor_update($security['content'], $security['token'], $security['secure_id']);
  5478. function ilm_editor_update ($filename, $content_file, $token, $secure_id) {
  5479. global $CFG, $DB, $OUTPUT, $PAGE;
  5480. $ilmid = optional_param('ilmid', NULL, PARAM_INT); // iAssign ID
  5481. $dirid = optional_param('dirid', NULL, PARAM_INT);
  5482. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5483. $iassign = $DB->get_record("iassign_ilm", array("id" => $ilmid));
  5484. $returnurl = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=$this->id&dirid=$dirid&ilmid=$ilmid";
  5485. // If iLM is not registered, error!
  5486. if (!$iassign) {
  5487. print $OUTPUT->notification(get_string('error_confirms_ilm', 'iassign'), 'notifyproblem');
  5488. die;
  5489. }
  5490. //2017/03/12 //QUARANTINE agora vindo de 'ilm_manager.php' via os 3 parametros
  5491. //2017/03/12 $fs = get_file_storage(); // Get reference to all files in Moodle data // from Moodle data
  5492. //2017/03/12 $filename = ''; $end_file = ''; $file = $fs->get_file_by_id($fileid); if ($file) $filename = iassign_utils::format_filename($file->get_filename());
  5493. //D echo "locallib.php: ilm_editor_update(): filename=$filename<br/>\n";
  5494. //2016/02/16: IMPORTANTE trocar formatador para "nao formatado", pois esta destruindo o conteudo do arquivo
  5495. //2016/02/16: $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_ALPHANUMEXT);
  5496. $stringArchiveContent = optional_param('iLM_PARAM_ArchiveContent', NULL, PARAM_RAW);
  5497. //D echo "stringArchiveContent:$stringArchiveContent<br/>\n";
  5498. if ($stringArchiveContent != NULL) {
  5499. $this->update_file_iassign($stringArchiveContent, $filename, $fileid);
  5500. die();
  5501. } else { // if ($stringArchiveContent != NULL)
  5502. $end_file = '';
  5503. if ($content_file) {
  5504. // 2017/03/12 $token=''; $view=-1; $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $fileid . '&token=' . $token . '&view=' . $view; // need full path...
  5505. $end_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?id=' . $secure_id . '&action=update&token=' . $token . '&view=0'; // need full path...
  5506. }
  5507. $temp = explode(",", $iassign->extension);
  5508. $extension = $temp[0]; // default extension for this iLM
  5509. if ($extension == "html" || $extension == "ivph" || strtolower($iassign->type) == 'html5') { // if iLM is HTML5 is inside a frame
  5510. $str_get_iLM = "window.frames.iLM";
  5511. $str_submitbutton_name = "javascript:window.submit_iLM_Answer()";
  5512. } else { // otherwise it is JAR named 'iLM'
  5513. $str_get_iLM = "document.iLM";
  5514. $str_submitbutton_name = "submit_iLM_Answer()"; // to call 'submit_iLM_Answer()'
  5515. }
  5516. $output = "<script type='text/javascript'>
  5517. //<![CDATA[
  5518. function submit_iLM_Answer () {
  5519. var docFormEditor = document.formEnvio;
  5520. var activityAnswer; // to get activity answer (text)
  5521. var activityValue; // to get activity answer value (float)
  5522. var doc_iLM = " . $str_get_iLM . "; // 'window.frames.iLM' or 'document.iLM'
  5523. //activityAnswer = doc_iLM.getAnswer();
  5524. //activityValue = doc_iLM.getEvaluation();
  5525. activityAnswer = " . $str_get_iLM . ".getAnswer();
  5526. activityValue = " . $str_get_iLM . ".getEvaluation();
  5527. docFormEditor.iLM_PARAM_ActivityEvaluation.value = activityValue;
  5528. docFormEditor.iLM_PARAM_ArchiveContent.value = activityAnswer;
  5529. docFormEditor.submit();
  5530. return true;
  5531. }
  5532. //]]>
  5533. </script>\n";
  5534. // 2016/02/16: NOT necessary, since it is teacher editing (perhaps he only make an example as exercise)
  5535. // if (activityAnswer == -1) { // E.g. in iGeom it is possible to turn an example in exercise
  5536. // alert('" . get_string('error_null_iassign', 'iassign') . "'); // ERRO: O exercício esta vazio ou não foi alterado
  5537. // return true;
  5538. // }
  5539. $output .= "
  5540. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>\n";
  5541. $output .= $OUTPUT->box_start();
  5542. $output .= "
  5543. <table width='100%' cellpadding='20'>
  5544. <tr><td width='75%'>" . get_string('label_file_iassign', 'iassign') . "<b>$filename</b></td>
  5545. <td align='right' width='25%'><input type=button value='" . get_string('label_write_iassign', 'iassign') . "' title='' onclick='submit_iLM_Answer();'/>
  5546. <input type='hidden' name='filename' value='$filename'/></td>
  5547. <td>
  5548. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='javascript:window.location = \"$returnurl\";'/></td>
  5549. </tr>
  5550. </table>\n";
  5551. $output .= $OUTPUT->box_end();
  5552. $output .= " <center>\n";
  5553. // Since it is the activity file, it is not necessary to use 'ilm_security' (id_iLM_security)
  5554. $output .= ilm_settings::build_ilm_tags($ilmid, array("type" => "editor_update", "notSEND" => "false", "Proposition" => $end_file));
  5555. $output .= " <input type='hidden' name='iLM_PARAM_ArchiveContent' value=''>
  5556. <input type='hidden' name='iLM_PARAM_ActivityEvaluation' value=''>
  5557. </center>
  5558. </form>\n";
  5559. $title = get_string('title_editor_iassign', 'iassign') . " - " . $iassign->name . " " . $iassign->version; //MOOC2014
  5560. $PAGE->navbar->add($title);
  5561. $PAGE->set_title($title);
  5562. $PAGE->set_heading($title); // insert title above the navigation bar
  5563. print $OUTPUT->header();
  5564. //print $OUTPUT->heading("&nbsp;&nbsp;" . $title); // insert title below the navigation bar
  5565. print $output;
  5566. print $OUTPUT->footer();
  5567. } // else if ($stringArchiveContent != NULL)
  5568. die();
  5569. } // function ilm_editor_update()
  5570. /// Function for write iAssign file in Moodle data (exercise)
  5571. // @calledby ilm_editor_new(): $this->write_file_iassign($stringArchiveContent, $filename);
  5572. // @param string $stringArchiveContent Content of iassign file
  5573. // @param string $filename Filename of iassign file
  5574. function write_file_iassign ($stringArchiveContent, $filename) {
  5575. global $USER;
  5576. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5577. $context = context_course::instance($this->id);
  5578. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5579. $dirid = $this->get_dir_ilm('dirid');
  5580. $dir = $fs->get_file_by_id($dirid);
  5581. $fileinfo = array('contextid' => $context->id, // ID of course
  5582. 'component' => 'mod_iassign', // usually = table name
  5583. 'filearea' => 'activity', // usually = table name
  5584. 'itemid' => 0, // usually = ID of row in table
  5585. 'filepath' => '/', // any path beginning and ending whith '/'
  5586. 'userid' => $USER->id,
  5587. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5588. 'filename' => $filename); // any filename
  5589. // Create file containing text. '$stringArchiveContent'
  5590. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5591. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent);
  5592. // sucess_write -> 'Interactive assignment successfully registered under the name: '
  5593. // 'Tarea interactiva registrada exitosamente bajo el nombre:'
  5594. // 'Activité interactive enregistrée avec succès sous le nom:';
  5595. // 'Atividade interativa gravada com sucesso sob o nome:'
  5596. $output = "
  5597. <script type='text/javascript'>
  5598. //<![CDATA[
  5599. alert('" . get_string('sucess_write', 'iassign') . " " . $filename . "');
  5600. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5601. //]]>
  5602. </script>";
  5603. print $output;
  5604. die();
  5605. }
  5606. /// Function for write iAssign file in Moodle data (exercise)
  5607. // @param string $stringArchiveContent Content of iassign file
  5608. // @param string $filename Filename of iassign file
  5609. // @param int $itemid Itemid of iassign file
  5610. function update_file_iassign ($stringArchiveContent, $filename, $fileid) {
  5611. global $OUTPUT, $USER;
  5612. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5613. $context = context_course::instance($this->id);
  5614. $dirid = $this->get_dir_ilm('dirid');
  5615. if ($stringArchiveContent != (-1)) {
  5616. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5617. $file = $fs->get_file_by_id($fileid);
  5618. if (!$file) {
  5619. print $OUTPUT->notification(get_string('error_view_ilm', 'iassign'), 'notifyproblem');
  5620. die;
  5621. }
  5622. $fileinfo = array('contextid' => $context->id, // ID of context
  5623. 'component' => 'mod_iassign', // usually = table name
  5624. 'filearea' => 'activity', // usually = table name
  5625. 'itemid' => 0, // usually = ID of row in table
  5626. 'filepath' => $file->get_filepath(), // any path beginning and ending with '/'
  5627. 'userid' => $USER->id,
  5628. 'author' => $USER->firstname . ' ' . $USER->lastname,
  5629. 'license' => 'allrightsreserved', // allrightsreserved
  5630. 'timecreated' => $file->get_timecreated(),
  5631. 'filename' => $file->get_filename()); // any filename
  5632. $file->delete();
  5633. //TODO Verificar se apenas esta' inserindo nova referencia em 'files' (NAO deve duplicar no Moodle Data)
  5634. $file_course = $fs->create_file_from_string($fileinfo, $stringArchiveContent); //$string
  5635. }
  5636. $output = "<script type='text/javascript'>
  5637. //<![CDATA[
  5638. alert('" . get_string('sucess_update', 'iassign') . "');\n
  5639. window.location='" . $this->url . "&dirid=$dirid&ilmid=$ilmid';
  5640. //]]>
  5641. </script>";
  5642. print $output;
  5643. die();
  5644. }
  5645. /// Function for create an tag for iAssign filter
  5646. // @calledby function preview_ilm($iassign_ilm) : $tag_filter = $this->tag_ilm($fileid);
  5647. // @calledby function tinymce_ilm($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5648. // @calledby function editor_ilm($fileid, $editor) : $tag_filter = $this->tag_ilm($fileid);
  5649. // @calledby function atto_ilm ($fileid) : $tag_filter = $this->tag_ilm($fileid);
  5650. // @param int $fileid Id of file
  5651. // @return string Return an string with an tag of iassign filter
  5652. function tag_ilm ($fileid) {
  5653. global $DB;
  5654. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5655. $width = '600';
  5656. $height = '400';
  5657. $file = $fs->get_file_by_id($fileid);
  5658. $filetype = explode(".", $file->get_filename());
  5659. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1, "parent" => 0));
  5660. foreach ($iassign_ilm as $value) {
  5661. $extensions = explode(",", $value->extension);
  5662. if (in_array($filetype[1], $extensions)) {
  5663. $width = $value->width;
  5664. $height = $value->height;
  5665. }
  5666. }
  5667. return("<p>&lt;ia toolbar=disable width=$width height=$height &gt;$fileid&lt;/ia&gt;</p>");
  5668. }
  5669. /// Function for delete iAssign file in Moodle data (exercise)
  5670. function delete_file_ilm () {
  5671. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5672. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5673. $fileid = optional_param('fileid', NULL, PARAM_RAW);
  5674. $file = $fs->get_file_by_id($fileid);
  5675. if ($file)
  5676. $file->delete();
  5677. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5678. die();
  5679. }
  5680. /// Function for delete selected iAssign file in Moodle data (exercise)
  5681. function delete_selected_ilm () {
  5682. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5683. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5684. $context = context_course::instance($this->id);
  5685. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5686. $dirid = $this->get_dir_ilm('dirid');
  5687. foreach ($files_id as $file_id) {
  5688. $file = $fs->get_file_by_id($file_id);
  5689. if ($file) {
  5690. if (!$file->is_directory())
  5691. $file->delete();
  5692. else {
  5693. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5694. foreach ($files_delete as $value)
  5695. $value->delete();
  5696. $file->delete();
  5697. }
  5698. }
  5699. }
  5700. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  5701. die();
  5702. }
  5703. /// Function for duplicate iAssign file from "online" edition
  5704. // @callby JavaScript function 'duplicate_ilm(ilmid, filename, fileid)' bellow
  5705. function duplicate_file_ilm () {
  5706. global $USER, $COURSE;
  5707. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5708. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5709. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5710. $filename = optional_param('filename', NULL, PARAM_RAW);
  5711. $file = $fs->get_file_by_id($fileid);
  5712. $context = context_course::instance($this->id);
  5713. $fileinfo = array(
  5714. 'contextid' => $context->id, // ID of context
  5715. 'component' => 'mod_iassign', // usually = table name
  5716. 'filearea' => 'activity', // usually = table name
  5717. 'itemid' => 0, // usually = ID of row in table
  5718. 'filepath' => $this->get_dir_ilm('dir_base'), // any path beginning and ending in /
  5719. 'userid' => $USER->id,
  5720. 'author' => $USER->firstname . ' ' . $USER->lastname, 'license' => 'allrightsreserved', // allrightsreserved
  5721. 'timecreated' => $file->get_timecreated(), 'filename' => $filename); // any filename
  5722. $newfile = $fs->create_file_from_string($fileinfo, $file->get_content());
  5723. redirect(new moodle_url($this->url . "&dirid=" . $this->get_dir_ilm('dirid') . "&ilmid=" . $ilmid));
  5724. die();
  5725. }
  5726. /// Function for rename iAssign file
  5727. function rename_file_ilm () {
  5728. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5729. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5730. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5731. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5732. $file = $fs->get_file_by_id($fileid);
  5733. $file->rename($this->get_dir_ilm('dir_base'), $filename);
  5734. //MOOC2014 redirect(new moodle_url($this->url . "&dirid=" . $dir_parent . "&ilmid=$ilmid"));
  5735. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5736. //D echo "locallib.php: rename_file_ilm; ilmid=$ilmid, dirid=" . $this->get_dir_ilm('dirid') . "<br/>\n"; //
  5737. die();
  5738. }
  5739. /// Function for get iassign file for iassign form
  5740. function add_ilm () {
  5741. $fileid = optional_param('fileid', NULL, PARAM_INT);
  5742. $filename = optional_param('filename', NULL, PARAM_TEXT);
  5743. $output = "
  5744. <script type='text/javascript'>
  5745. //<![CDATA[
  5746. var iassign_file_link = window.opener.document.getElementById('iassign_file_link');
  5747. iassign_file_link.innerHTML = '$filename';
  5748. window.opener.document.forms['mform1'].file.value='$fileid';
  5749. window.opener.document.forms['mform1'].filename.value='$filename';
  5750. window.close();
  5751. //]]>
  5752. </script>";
  5753. print $output;
  5754. die();
  5755. }
  5756. /// Function for preview iAssign file from iAssign Repository (it uses iAssign filter)
  5757. // @see /iassign_filter/filter.php : function 'filter($text, array $options = array())' and exit (do not continue bellow)
  5758. // @see ilm_manager.php : $ilm_manager_instance->preview_ilm();
  5759. function preview_ilm ($courseid, $iassign_ilm) {
  5760. global $OUTPUT, $CFG, $USER;
  5761. $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5762. $title = get_string('modulename', 'iassign'); // iAssign
  5763. print $OUTPUT->header();
  5764. print $OUTPUT->box_start();
  5765. $javascript = "
  5766. <!-- iAssign preview iLM content / LInE - http://line.ime.usp.br -->
  5767. <script type='text/javascript'>
  5768. //<![CDATA[
  5769. function submit_close () {
  5770. window.opener.location.reload();
  5771. window.close();
  5772. }
  5773. //]]>
  5774. </script>\n";
  5775. // Use iAssin filter to change "&lt;ia toolbar=disable width=800 height=600 &gt;45&lt;/ia&gt;"
  5776. // to the complete "applet" tag
  5777. // Version previous to: 2016/02/16: do not present menus' options - similar to the filter
  5778. //TODO: E' melhor apresentar o iMA completo, sem usar o filtro com opcao "<param name='SOH_ADD' value='ADD'>"
  5779. //TODO: Talvez seja melhor colocar opcao no filtro para evitar opcao 'ADD'!
  5780. //TODO: Here reaches '/iassign_filter/filter.php : function 'filter($text, array $options = array())' with parameter 'originalformat=0' (in glossary is 1)
  5781. //TODO: then, I changed '/iassign_filter/filter.php' (functions 'filter(...) to avoid 'SOH_ADD' if 'originalformat=0'
  5782. $ilm_name = substr(strtolower($iassign_ilm->name), 0, 6);
  5783. if ($ilm_name != "ivprog") {
  5784. //MOOC2014 $tag_filter = format_text($this->tag_ilm($fileid));
  5785. $tag_filter = $this->tag_ilm($fileid); // build the iAssign filter tag, something like: <ia toolbar=disable width=800 height=600 >58</ia>
  5786. $tag_filter_filtered = format_text($tag_filter, FORMAT_MOODLE, array('overflowdiv' => true, 'allowid' => true)); // Moodle 3.X
  5787. } else {
  5788. require_once($CFG->dirroot . '/mod/iassign/ilm_security.php');
  5789. $content_or_id_from_ilm_security = $this->get_file_ilm();
  5790. $timecreated = time();
  5791. $token = md5($timecreated);
  5792. $id_iLM_security = ilm_security::write_iLM_security($USER->id, $timecreated, -1, $content_or_id_from_ilm_security); // insert in 'iassign_security'
  5793. $param = 'id=' . $id_iLM_security . '&ilmid=' . $iassign_ilm->id . '&token=' . $token . '&view=0';
  5794. $url_file = $CFG->wwwroot . '/mod/iassign/ilm_security.php?action=preview&' . $param;
  5795. $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)
  5796. }
  5797. $html = "
  5798. <form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5799. <table border='1'>
  5800. <tr><td>
  5801. <!-- iLM calls : begin -->\n" . $tag_filter_filtered . "\n
  5802. <!-- iLM calls : end -->
  5803. </td></tr>
  5804. </table>
  5805. <table>
  5806. <tr>
  5807. <td align='center'>
  5808. <input type=button value='" . get_string('close', 'iassign') . "' title='' onclick='submit_close();' />
  5809. </td></tr>
  5810. </table>
  5811. </form>\n";
  5812. print $javascript . $html;
  5813. print $OUTPUT->box_end();
  5814. //NAO echo format_string($html); // Moodle 3.X
  5815. die();
  5816. } // function preview_ilm($courseid, $iassign_ilm)
  5817. //r_ function preview_ilm ($iassign_ilm)
  5818. //r_ /// Function for preview iassign file from iassign filter.
  5819. //r_ function preview_ilm() {
  5820. //r_ $fileid = optional_param('fileid', NULL, PARAM_TEXT);
  5821. //r_ $tag_filter = $this->tag_ilm($fileid);
  5822. //r_ $javascript = "<script type='text/javascript'>
  5823. //r_ //<![CDATA[
  5824. //r_ function submit_close() { window.opener.location.reload(); window.close(); }
  5825. //r_ //]]>
  5826. //r_ </script>";
  5827. //r_ $html = "<html><head></head><body><form name='formEnvio' id='formEnvio' method='post' enctype='multipart/form-data'>
  5828. //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>
  5829. //r_ </table></form></body></html>";
  5830. //r_ echo $javascript . format_text($html);
  5831. //r_ die;
  5832. //r_ }
  5833. /// Function for export an package (zip) of iassign files
  5834. function export_files_ilm () {
  5835. global $CFG;
  5836. $context = context_course::instance($this->id);
  5837. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  5838. $zip_filename = $CFG->dataroot . '/temp/backup-iassign-files-' . date("Ymd-Hi") . '.zip';
  5839. $zip = new zip_archive();
  5840. $zip->open($zip_filename);
  5841. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5842. foreach ($files_id as $file_id) {
  5843. $file = $fs->get_file_by_id($file_id);
  5844. if (!$file->is_directory())
  5845. $zip->add_file_from_string($file->get_filename(), $file->get_content());
  5846. else {
  5847. $zip->add_directory($file->get_filepath());
  5848. $files_zip = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  5849. foreach ($files_zip as $value) {
  5850. if (!$value->is_directory())
  5851. $zip->add_file_from_string($value->get_filepath() . $value->get_filename(), $value->get_content());
  5852. else
  5853. $zip->add_directory($value->get_filepath());
  5854. }
  5855. }
  5856. }
  5857. $zip->close();
  5858. header("Pragma: public");
  5859. header("Expires: 0");
  5860. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  5861. header("Cache-Control: private", false);
  5862. header("Content-Type: application/zip");
  5863. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  5864. header("Content-Transfer-Encoding: binary");
  5865. header("Content-Length: " . @filesize($zip_filename));
  5866. set_time_limit(0);
  5867. @readfile("$zip_filename") || die("File not found.");
  5868. unlink($zip_filename);
  5869. exit;
  5870. }
  5871. /// Function of execute a command in button editor tinymce
  5872. // @param int $fileid Id of file
  5873. function tinymce_ilm ($fileid) {
  5874. $tag_filter = $this->tag_ilm($fileid);
  5875. $output = "<script type='text/javascript'>
  5876. //<![CDATA[
  5877. var tag_filter = '$tag_filter';
  5878. if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) {
  5879. // all right, insert it
  5880. } else {
  5881. alert('Error trying to insert iLM content (tinymce_ilm " + $fileid + ")');
  5882. }
  5883. // window.close();
  5884. //]]>
  5885. </script>\n";
  5886. print $output;
  5887. die();
  5888. }
  5889. //TODO sugestao para uso de apenas uma funcao para chamar os editores, cortando 17 linhas de codigo
  5890. /// Function to add content to the Editor Window
  5891. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5892. // @param int $fileid Id of file
  5893. function editor_ilm ($fileid, $editor) {
  5894. $tag_filter = $this->tag_ilm($fileid); // Prepare tag like: <ia toolbar=disable width=800 height=600>ID</ia>
  5895. $output1 = "<script type='text/javascript'>
  5896. //<![CDATA[
  5897. var tag_filter = '$tag_filter';\n";
  5898. if ($editor == 'atto') {
  5899. $output2 = " if (window.opener.document.execCommand('insertHTML', false, tag_filter)) { } // all right, insert it";
  5900. } elseif ($editor == 'tinyMCE') {
  5901. $output2 = " if (window.opener.tinyMCE.execCommand('mceiAssignReturn', tag_filter)) { } // all right, insert it";
  5902. } else
  5903. $output2 = "";
  5904. $output3 = " else { console.log('Error trying to insert iLM content (atto_ilm " . $fileid . ")'); }
  5905. window.close();
  5906. //]]>
  5907. </script>\n";
  5908. //D var_dump($output);
  5909. print $output1 . $output2 . $output3;
  5910. die();
  5911. }
  5912. /// Function to add content to the Atto Editor Window
  5913. // Updated: Marcio Passos - marciopassosbel[at]gmail[dot]com :: 07 / Jul / 2016
  5914. // @param int $fileid Id of file
  5915. function atto_ilm ($fileid) {
  5916. global $CFG, $DB;
  5917. $tag_filter = $this->tag_ilm($fileid);
  5918. $output = "<script type='text/javascript'>
  5919. //<![CDATA[
  5920. var tag_filter = '$tag_filter';
  5921. if (window.opener.document.execCommand('insertHTML', false, tag_filter)) {
  5922. // all right, insert iLM tag to this editor
  5923. } else {
  5924. // error trying to insert
  5925. alert('Error trying to insert iLM content (atto_ilm " + $fileid + ")');
  5926. }
  5927. //window.close();
  5928. //]]>
  5929. </script>\n";
  5930. print $output;
  5931. die();
  5932. }
  5933. /// Function for get path and info of directories: dirid, dir_base, dir_parent, dir_home
  5934. // @param string $key Key for return information
  5935. // @return Ambigous <unknown, number, string, NULL> Return an information requested
  5936. function get_dir_ilm ($key) {
  5937. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5938. $context = context_course::instance($this->id);
  5939. $dirid = optional_param('dirid', 0, PARAM_INT);
  5940. $dir_home = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base = '/', '.');
  5941. if ($dirid == 0) {
  5942. $dir = ($dir_home = $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base));
  5943. $dirid = $dir->get_id();
  5944. }
  5945. else {
  5946. $dir = $fs->get_file_by_id($dirid);
  5947. $dir_base = $dir->get_filepath();
  5948. }
  5949. $dir_parent = $dir->get_parent_directory();
  5950. $data = array('dirid' => $dirid, 'dir_base' => $dir_base, 'dir_parent' => ($dir_parent == NULL ? 0 : $dir_parent->get_id()), 'dir_home' => $dir_home->get_id());
  5951. return $data[$key];
  5952. }
  5953. /// Function for create an new dir
  5954. function new_dir_ilm () {
  5955. global $USER;
  5956. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5957. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5958. $dir_base = $this->get_dir_ilm('dir_base');
  5959. $context = context_course::instance($this->id);
  5960. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5961. $fs->create_directory($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", $USER->id);
  5962. $dir_base = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base . $dirname . "/", '.');
  5963. $dir_base->set_author($USER->firstname . ' ' . $USER->lastname);
  5964. redirect(new moodle_url($this->url . '&dirid=' . $this->get_dir_ilm('dirid') . '&ilmid=' . $ilmid));
  5965. }
  5966. /// Function for delete an dir
  5967. function delete_dir_ilm () { //
  5968. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5969. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5970. $context = context_course::instance($this->id);
  5971. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5972. $dir_parent = $this->get_dir_ilm('dir_parent');
  5973. if ($dir) {
  5974. if ($dir->is_directory()) {
  5975. $files_delete = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5976. foreach ($files_delete as $value)
  5977. $value->delete();
  5978. $dir->delete();
  5979. }
  5980. }
  5981. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  5982. die();
  5983. }
  5984. /// Function for rename an dir
  5985. function rename_dir_ilm () {
  5986. $fs = get_file_storage(); // Get reference to all files in Moodle data
  5987. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  5988. $context = context_course::instance($this->id);
  5989. $dir = $fs->get_file_by_id($this->get_dir_ilm('dirid'));
  5990. $dir_parent = $this->get_dir_ilm('dir_parent');
  5991. $dirname = optional_param('dirname', NULL, PARAM_TEXT);
  5992. $pathname = explode("/", substr($dir->get_filepath(), 0, strlen($dir->get_filepath()) - 1));
  5993. if ($dir->is_directory()) {
  5994. $files_rename_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir->get_filepath(), true, true);
  5995. foreach ($files_rename_path as $value)
  5996. $value->rename(str_replace($pathname[count($pathname) - 1], $dirname, $value->get_filepath()), $value->get_filename());
  5997. $dir->rename(str_replace($pathname[count($pathname) - 1], $dirname, $dir->get_filepath()), $dir->get_filename());
  5998. }
  5999. redirect(new moodle_url($this->url . '&dirid=' . $dir_parent . '&ilmid=' . $ilmid));
  6000. die();
  6001. }
  6002. /// Function for move an dir and your content for other dir
  6003. function selected_move_ilm () {
  6004. global $PAGE, $OUTPUT, $CFG;
  6005. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6006. $context = context_course::instance($this->id);
  6007. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6008. $dirid = $this->get_dir_ilm('dirid');
  6009. $dir_base = $this->get_dir_ilm('dir_base');
  6010. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6011. $code_javascript_ilm = "
  6012. <script type='text/javascript'>
  6013. //<![CDATA[
  6014. function getRadiobutton () {
  6015. var radioButtons = document.getElementsByTagName('input');
  6016. var param = '';
  6017. for (var counter=0; counter < radioButtons.length; counter++) {
  6018. if (radioButtons[counter].type.toUpperCase()=='RADIO' && radioButtons[counter].checked == true && radioButtons[counter].name == 'selected_dir')
  6019. param = radioButtons[counter].value;
  6020. }
  6021. return param;
  6022. }
  6023. function move_selected_ilm () {
  6024. var msgAnswer;
  6025. if (getRadiobutton() != '') {
  6026. msgAnswer = confirm('" . get_string('question_move_dir', 'iassign') . "');
  6027. if (msgAnswer)
  6028. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=move&ilmid=" . $ilmid . "&dirid=" . $dirid . "&files_id=" .
  6029. optional_param('files_id', '', PARAM_TEXT) . "&dir_move='+getRadiobutton();
  6030. }
  6031. else
  6032. alert('" . get_string('error_dir_not_selected_to_move', 'iassign') . "');
  6033. }
  6034. function cancel_selected_ilm () {
  6035. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6036. }
  6037. //]]>
  6038. </script>\n";
  6039. $title = get_string('move_files', 'iassign');
  6040. $PAGE->set_title($title);
  6041. $PAGE->set_pagelayout('base');
  6042. print $OUTPUT->header();
  6043. print $OUTPUT->heading($title);
  6044. $dir_paths = array();
  6045. print $OUTPUT->box_start();
  6046. print "<center>";
  6047. foreach ($files_id as $file_id) {
  6048. $file = $fs->get_file_by_id($file_id);
  6049. if ($file) {
  6050. if (!$file->is_directory())
  6051. print "<p>" . iassign_icons::insert('file') . "&nbsp;" . $file->get_filepath() . $file->get_filename() . "</p>";
  6052. else {
  6053. print "<p>" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6054. array_push($dir_paths, $file->get_filepath());
  6055. }
  6056. }
  6057. }
  6058. print $OUTPUT->heading(get_string('select_move_ilm', 'iassign'), 3, 'move', 'move_files');
  6059. if ($dir_base != '/') {
  6060. $check_select = "<input name='selected_dir' type='radio' value='" . $this->get_dir_ilm('dir_home') . "'/>";
  6061. print $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;/<br>";
  6062. }
  6063. $files_tree = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, '/', true, true, 'filepath');
  6064. foreach ($files_tree as $file) {
  6065. if ($file->is_directory() && $file->get_filepath() != $dir_base) {
  6066. $is_parent = false;
  6067. foreach ($dir_paths as $dir) {
  6068. $path = explode("/", $dir);
  6069. array_pop($path);
  6070. $path[count($path) - 1] = '';
  6071. $path = implode("/", $path);
  6072. $is_parent |= (strpos($file->get_filepath(), $dir) === false ? false : true);
  6073. $is_parent |= ($file->get_filepath() != $path ? false : true);
  6074. }
  6075. if ($is_parent == false) {
  6076. $check_select = "<input name='selected_dir' type='radio' value='" . $file->get_id() . "'/>";
  6077. print "<p>" . $check_select . "&nbsp;" . iassign_icons::insert('dir') . "&nbsp;" . $file->get_filepath() . "</p>";
  6078. }
  6079. }
  6080. }
  6081. print "<p><input type='button' value='" . get_string('ok') . "' onclick='move_selected_ilm();'/>&nbsp;&nbsp;&nbsp;&nbsp;";
  6082. print "<input type='button' value='" . get_string('cancel') . "' onclick='cancel_selected_ilm();'/></p>";
  6083. print "</center>";
  6084. print $OUTPUT->box_end();
  6085. print $OUTPUT->footer();
  6086. print $code_javascript_ilm;
  6087. die;
  6088. }
  6089. /// Function for move files for an dir
  6090. function move_files_ilm () {
  6091. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6092. $context = context_course::instance($this->id);
  6093. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6094. $dirid = $this->get_dir_ilm('dirid');
  6095. $dir_move = $fs->get_file_by_id(optional_param('dir_move', 0, PARAM_INT));
  6096. $files_id = explode(",", optional_param('files_id', '', PARAM_TEXT));
  6097. foreach ($files_id as $file_id) {
  6098. $file = $fs->get_file_by_id($file_id);
  6099. if ($file) {
  6100. if ($file->is_directory()) {
  6101. $pathname = explode("/", $file->get_filepath());
  6102. $files_move_path = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $file->get_filepath(), true, true);
  6103. foreach ($files_move_path as $value) {
  6104. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/' . str_replace($file->get_filepath(), '', $value->get_filepath());
  6105. $value->rename($path_move, $value->get_filename());
  6106. //echo($value->get_filepath().$value->get_filename()." - $path_move".$value->get_filename()."<br>");
  6107. }
  6108. $path_move = $dir_move->get_filepath() . $pathname[count($pathname) - 2] . '/';
  6109. //echo($file->get_filepath().$file->get_filename()." - $path_move".$file->get_filename()."<br>");
  6110. $file->rename($path_move, $file->get_filename());
  6111. } else {
  6112. //echo($file->get_filepath().$file->get_filename()." -> ".$dir_move->get_filepath().$file->get_filename()."<br>");
  6113. $file->rename($dir_move->get_filepath(), $file->get_filename());
  6114. }
  6115. }
  6116. }
  6117. //die;
  6118. redirect(new moodle_url($this->url . '&ilmid=' . $ilmid . '&dirid=' . $dirid));
  6119. die();
  6120. } // function move_files_ilm()
  6121. /// Function for recover files in use on all activities of a course
  6122. function recover_files_ilm () {
  6123. global $DB, $USER;
  6124. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6125. $courseid = optional_param('id', NULL, PARAM_INT);
  6126. $dirid = $this->get_dir_ilm('dirid');
  6127. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6128. $contextfile = context_course::instance($this->id);
  6129. $iassigns = $DB->get_records("iassign", array("course" => $courseid));
  6130. foreach ($iassigns as $iassign) {
  6131. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("iassignid" => $iassign->id));
  6132. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6133. $cm = get_coursemodule_from_instance("iassign", $iassign->id, $courseid);
  6134. $context = context_module::instance($cm->id);
  6135. $files = $fs->get_area_files($context->id, 'mod_iassign', 'exercise', $iassign_statement_activity_item->file);
  6136. if ($files) {
  6137. foreach ($files as $value) {
  6138. $extension = explode(".", $value->get_filename());
  6139. if (!$value->is_directory()) {
  6140. $fileinfo = array('contextid' => $contextfile->id,
  6141. 'component' => 'mod_iassign',
  6142. 'filearea' => 'activity',
  6143. 'itemid' => 0,
  6144. 'filepath' => $this->get_dir_ilm('dir_base'),
  6145. 'userid' => $USER->id,
  6146. 'author' => $USER->firstname . ' ' . $USER->lastname,
  6147. 'license' => 'allrightsreserved',
  6148. 'timecreated' => time(),
  6149. 'filename' => $iassign_statement_activity_item->name . "." . $extension[1]); // any filename
  6150. $newfile = $fs->create_file_from_string($fileinfo, $value->get_content());
  6151. }
  6152. }
  6153. } // if ($files)
  6154. } // foreach ($iassign_statement_activity_list as $iassign_statement_activity_item)
  6155. } // foreach ($iassigns as $iassign)
  6156. redirect(new moodle_url($this->url . '&dirid=' . $dirid . '&ilmid=' . $ilmid));
  6157. die();
  6158. } // function recover_files_ilm()
  6159. /// Auxiliary function the get all files in a given context
  6160. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6161. // @return [array_contextid_files_thisauthor[], array_contextid_files_otherauthors[], array_contextid_files_otherauthors_userid[]]
  6162. //TODO Falta separar os arquivos listados, apresentar primeiro aqueles do autor e depois os demais.
  6163. //TODO Nao devemos listar aqueles que estao sem permissao (license == 'allrightsreserved')
  6164. function get_files_in_context (&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid) {
  6165. // s_iassign_statement: id name iassignid type_iassign proposition author_name author_modified_name iassign_ilmid
  6166. // (NAO s_iassign_statement.file = s_files.id)
  6167. $fs = get_file_storage(); // Get reference to all files in Moodle data
  6168. $dir_base = $this->get_dir_ilm('dir_base');
  6169. $files_course = $fs->get_directory_files($contextid, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6170. $countf = 0;
  6171. $array_files_id = array(); // all files from this context
  6172. foreach ($files_course as $item_fc) { // license = not "allrightsreserved" AND is not from this author => present it
  6173. //$filename = $item_fc->get_filename();
  6174. //$filepath = $item_fc->get_filepath();
  6175. //$fileid = $item_fc->get_id(); // get file ID (in *_iassign_statement table)
  6176. $fileuserid = $item_fc->get_userid(); // get user.id of the author
  6177. // $array_files_aux[] = $item_fc;
  6178. $itemid = $item_fc->get_id();
  6179. if (!in_array($itemid, $array_files_id)) {
  6180. //TODO Avoid to insert twice - necessary since it has been inserting 2 copies in iassign_statement
  6181. if ($fileuserid == $userid)
  6182. $filesfrommine[] = $item_fc;
  6183. else
  6184. $filesfromothers[] = $item_fc;
  6185. $array_files_id[] = $itemid;
  6186. $countf++;
  6187. }
  6188. }
  6189. //D echo "get_files_in_context: dir_base=$dir_base, contextid=$contextid, #array_files_id=".count($array_files_id) . " = $countf<br/>";
  6190. return $countf;
  6191. } // function get_files_in_context(&$filesfrommine, &$filesfromothers, $contextid, $extension, $userid)
  6192. // Function to get all iLM files from the same "file type": (usually) files under the same directory
  6193. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6194. function get_all_ilm_files_by_fileid ($fileid) {
  6195. global $DB, $USER;
  6196. // $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6197. //TODO Criar coluna 'authorid'
  6198. $str_query = "SELECT * FROM {iassign_statement} " .
  6199. " WHERE file = " . $fileid . " ORDER BY author_name, timecreated DESC";
  6200. $array_iassign_ilm = $DB->get_records_sql($str_query);
  6201. return $array_iassign_ilm;
  6202. }
  6203. //NN
  6204. //NN
  6205. // Build string with JavaScript code with function to edit/remove/double iLM files
  6206. // @calledby view_files_ilm($iassign_ilm_class, $extension, $start = 0)
  6207. function get_string_JavaScript_functions ($dirid, $ilmid, $files_array, $dirs_array) {
  6208. global $CFG;
  6209. $error_files_exists = get_string('error_file_exists', 'iassign');
  6210. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6211. $code_javascript_ilm = "
  6212. <script type='text/javascript'>
  6213. //<![CDATA[
  6214. function preview_ilm (fileid, ilmid) { //JavaScript function
  6215. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6216. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6217. }
  6218. function update_ilm (ilmid, fileid) { //JavaScript function
  6219. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6220. }
  6221. function delete_ilm (ilmid, fileid) { //JavaScript function
  6222. var msgAnswer;
  6223. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6224. if (msgAnswer) {
  6225. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6226. }
  6227. }
  6228. function delete_selected_ilm () { //JavaScript function
  6229. var msgAnswer;
  6230. var param = getCheckbox();
  6231. if (param.join() != '') {
  6232. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6233. if (msgAnswer)
  6234. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6235. }
  6236. else
  6237. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6238. }
  6239. function add_ilm_iassign (ilmid, filename, fileid) { //JavaScript function
  6240. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6241. }
  6242. function duplicate_ilm (ilmid, filename, fileid) { //JavaScript function
  6243. var filenamecopy;
  6244. var i;
  6245. var files = new Array(" . $files_array . ");
  6246. do {
  6247. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6248. } while (filenamecopy == '');
  6249. if (filenamecopy == null)
  6250. return false;\n
  6251. else {
  6252. for (i=0;i<files.length;i++) {
  6253. if (files[i]==filenamecopy) {
  6254. alert('" . $error_files_exists . "');
  6255. return false;\n
  6256. }
  6257. }\n" .
  6258. // @see: function 'duplicate_file_ilm()' above
  6259. "
  6260. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6261. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6262. } // else
  6263. }
  6264. function rename_ilm (ilmid, filename, fileid) { //JavaScript function
  6265. var filenamecopy;
  6266. var i;
  6267. var files = new Array($files_array);
  6268. do {
  6269. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6270. } while (filenamecopy == '');
  6271. if (filenamecopy == null)
  6272. return false;
  6273. else {
  6274. for (i=0;i<files.length;i++) {
  6275. if (files[i]==filenamecopy) {
  6276. alert('" . $error_files_exists . "');
  6277. return false;
  6278. }
  6279. }
  6280. 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;
  6281. }
  6282. }
  6283. function export_files_ilm () { //JavaScript function
  6284. var param = getCheckbox();
  6285. if (param.join() != '')
  6286. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6287. else
  6288. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6289. }
  6290. function select_all_ilm () { //JavaScript function
  6291. var checkBoxes = document.getElementsByTagName('input');
  6292. var selectAll = document.getElementById('select_all');
  6293. for (var counter=0; counter < checkBoxes.length; counter++) {
  6294. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6295. checkBoxes[counter].checked = selectAll.checked;
  6296. }
  6297. }
  6298. function getCheckbox () { //JavaScript function
  6299. var checkBoxes = document.getElementsByTagName('input');
  6300. var param = new Array();
  6301. for (var counter=0; counter < checkBoxes.length; counter++) {
  6302. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6303. param.push(checkBoxes[counter].value);
  6304. }
  6305. return param;
  6306. }
  6307. function new_dir_ilm () { //JavaScript function
  6308. var dirname = '';
  6309. var i;
  6310. var dirs = new Array(" . $dirs_array . ");
  6311. do {
  6312. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6313. } while (dirname == '');
  6314. if (dirname == null)
  6315. return false;\n
  6316. else {
  6317. for (i=0;i<dirs.length;i++) {
  6318. if (dirs[i]==dirname) {
  6319. alert('" . $error_dir_exists . "');
  6320. return false;\n
  6321. }
  6322. }
  6323. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6324. }
  6325. }
  6326. function delete_dir_ilm (ilmid, dirid) { //JavaScript function
  6327. var msgAnswer;
  6328. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6329. if (msgAnswer) {
  6330. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6331. }
  6332. }
  6333. function rename_dir_ilm (ilmid, dirname, dirid) { //JavaScript function
  6334. var dirnamecopy;
  6335. var i;
  6336. var dirs = new Array($dirs_array);
  6337. do {
  6338. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6339. } while (dirnamecopy == '');
  6340. if (dirnamecopy == null)
  6341. return false;\n
  6342. else {
  6343. for (i=0;i<dirs.length;i++) {
  6344. if (dirs[i]==dirnamecopy) {
  6345. alert('" . $error_dir_exists . "');
  6346. return false;\n
  6347. }
  6348. }
  6349. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6350. }
  6351. }
  6352. function move_selected_ilm (ilmid) { //JavaScript function
  6353. var param = getCheckbox();
  6354. if (param.join() != '')
  6355. 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();
  6356. else
  6357. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6358. }
  6359. function recover_files_ilm () { //JavaScript function
  6360. var msgAnswer;
  6361. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6362. if (msgAnswer) {
  6363. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6364. }
  6365. }
  6366. window.onload = function() { //JavaScript function
  6367. var xPosition = 0;
  6368. var yPosition = 0;
  6369. element=document.getElementById('new_file');
  6370. while(element) {
  6371. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6372. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6373. element = element.offsetParent;
  6374. }
  6375. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6376. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6377. location.hash = '#new_file';
  6378. };
  6379. //]]>
  6380. </script>\n"; // end of $code_javascript_ilm
  6381. return $code_javascript_ilm;
  6382. } // function get_string_JavaScript_functions($dirid, $ilmid, $files_array, $dirs_array)
  6383. /// List iassign files from course directory
  6384. // @calledby ilm_manager.php : $ilm_manager_instance->view_files_ilm($iassign_ilm->extension);
  6385. function view_files_ilm ($iassign_ilm_class, $extension) {
  6386. global $CFG, $DB, $USER, $OUTPUT;
  6387. $fs = get_file_storage();
  6388. $context = context_course::instance($this->id);
  6389. $ilmid = optional_param('ilmid', NULL, PARAM_INT);
  6390. $dirid = $this->get_dir_ilm('dirid');
  6391. $dir_base = $this->get_dir_ilm('dir_base');
  6392. $files_course = $fs->get_directory_files($context->id, 'mod_iassign', 'activity', 0, $dir_base, false, true, 'filename');
  6393. //D echo "locallib.php: view_files_ilm: context->id=" . $context->id . ", dir_base=$dir_base, #files_course=" . count($files_course) . "<br/>";
  6394. //D foreach ($files_course as $onefile) echo $onefile->get_id().", ".$onefile->get_filepath().", ".$onefile->get_filename()."<br/>";
  6395. $files_array = '';
  6396. foreach ($files_course as $value) {
  6397. if (!$value->is_directory())
  6398. $files_array .= "'" . $value->get_filename() . "',";
  6399. }
  6400. $files_array .= "''";
  6401. $error_files_exists = get_string('error_file_exists', 'iassign');
  6402. $dirs_array = '';
  6403. foreach ($files_course as $value) {
  6404. if ($value->is_directory()) {
  6405. $pathname = explode("/", substr($value->get_filepath(), 0, strlen($value->get_filepath()) - 1));
  6406. $dirs_array .= "'" . $pathname[count($pathname) - 1] . "',";
  6407. }
  6408. }
  6409. $dirs_array .= "''";
  6410. $error_dir_exists = get_string('error_dir_exists', 'iassign');
  6411. // TODO Rever o preview pois só deixar ver uma vez.
  6412. $code_javascript_ilm = "
  6413. <script type='text/javascript'>
  6414. //<![CDATA[
  6415. function preview_ilm (fileid, ilmid) {
  6416. var param = '" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=preview&fileid='+fileid+'&ilmid='+ilmid;
  6417. var preview_ilm=window.open(param,'','menubar=0,location=0,scrollbars,status,resizable,width=900 height=700');
  6418. }
  6419. function update_ilm (ilmid, fileid) {
  6420. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=update&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6421. }
  6422. function delete_ilm (ilmid, fileid) {
  6423. var msgAnswer;
  6424. msgAnswer = confirm('" . get_string('delete_file', 'iassign') . "');
  6425. if (msgAnswer) {
  6426. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete&ilmid='+ilmid+'&dirid=" . $dirid . "&fileid='+fileid;
  6427. }
  6428. }
  6429. function delete_selected_ilm () {
  6430. var msgAnswer;
  6431. var param = getCheckbox();
  6432. if (param.join() != '') {
  6433. msgAnswer = confirm('" . get_string('delete_files', 'iassign') . "');
  6434. if (msgAnswer)
  6435. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=selected_delete&dirid=" . $dirid . "&files_id='+param.join();
  6436. }
  6437. else
  6438. alert('" . get_string('er_file_not_selected_to_delete', 'iassign') . "');
  6439. }
  6440. function add_ilm_iassign (ilmid, filename, fileid) {
  6441. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=addilm&ilmid='+ilmid+'&fileid='+fileid+'&filename='+filename;
  6442. }
  6443. function duplicate_ilm (ilmid, filename, fileid) {
  6444. var filenamecopy;
  6445. var i;
  6446. var files = new Array($files_array);
  6447. do {
  6448. filenamecopy = prompt ('" . get_string('duplicate_file', 'iassign') . "',filename);
  6449. } while (filenamecopy == '');
  6450. if (filenamecopy == null)
  6451. return false;\n
  6452. else {
  6453. for (i=0;i<files.length;i++) {
  6454. if (files[i]==filenamecopy) {
  6455. alert('$error_files_exists');
  6456. return false;\n
  6457. }
  6458. }\n" .
  6459. // @see: function 'duplicate_file_ilm()' above
  6460. "
  6461. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?" .
  6462. "from=" . $this->from . "&id=" . $this->id . "&action=duplicate&ilmid=' + ilmid + '&dirid=" . $dirid . "&fileid=' + fileid + '&filename=' + filenamecopy;
  6463. } // else
  6464. }
  6465. function rename_ilm (ilmid, filename, fileid) {
  6466. var filenamecopy;
  6467. var i;
  6468. var files = new Array($files_array);
  6469. do {
  6470. filenamecopy = prompt('" . get_string('rename_file', 'iassign') . "',filename);
  6471. } while (filenamecopy == '');
  6472. if (filenamecopy == null)
  6473. return false;
  6474. else {
  6475. for (i=0;i<files.length;i++) {
  6476. if (files[i]==filenamecopy) {
  6477. alert('$error_files_exists');
  6478. return false;
  6479. }
  6480. }
  6481. 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;
  6482. }
  6483. }
  6484. function export_files_ilm () {
  6485. var param = getCheckbox();
  6486. if (param.join() != '')
  6487. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=export&dirid=" . $dirid . "&files_id='+param.join();
  6488. else
  6489. alert('" . get_string('er_file_not_selected_to_export', 'iassign') . "');
  6490. }
  6491. function select_all_ilm () {
  6492. var checkBoxes = document.getElementsByTagName('input');
  6493. var selectAll = document.getElementById('select_all');
  6494. for (var counter=0; counter < checkBoxes.length; counter++) {
  6495. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].name == 'selected_file')
  6496. checkBoxes[counter].checked = selectAll.checked;
  6497. }
  6498. }
  6499. function getCheckbox () {
  6500. var checkBoxes = document.getElementsByTagName('input');
  6501. var param = new Array();
  6502. for (var counter=0; counter < checkBoxes.length; counter++) {
  6503. if (checkBoxes[counter].type.toUpperCase()=='CHECKBOX' && checkBoxes[counter].checked == true && checkBoxes[counter].name == 'selected_file')
  6504. param.push(checkBoxes[counter].value);
  6505. }
  6506. return param;
  6507. }
  6508. function new_dir_ilm () {
  6509. var dirname = '';
  6510. var i;
  6511. var dirs = new Array($dirs_array);
  6512. do {
  6513. var dirname = prompt ('" . get_string('question_new_dir', 'iassign') . "', '');
  6514. } while (dirname == '');
  6515. if (dirname == null)
  6516. return false;\n
  6517. else {
  6518. for (i=0;i<dirs.length;i++) {
  6519. if (dirs[i]==dirname) {
  6520. alert('$error_dir_exists');
  6521. return false;\n
  6522. }
  6523. }
  6524. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=new_dir&ilmid=" . $ilmid . "&dirid=" . $dirid . "&dirname='+dirname;
  6525. }
  6526. }
  6527. function delete_dir_ilm (ilmid, dirid) {
  6528. var msgAnswer;
  6529. msgAnswer = confirm('" . get_string('question_delete_dir', 'iassign') . "');
  6530. if (msgAnswer) {
  6531. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=delete_dir&ilmid='+ilmid+'&dirid='+dirid;
  6532. }
  6533. }
  6534. function rename_dir_ilm (ilmid, dirname, dirid) {
  6535. var dirnamecopy;
  6536. var i;
  6537. var dirs = new Array($dirs_array);
  6538. do {
  6539. dirnamecopy = prompt ('" . get_string('question_rename_dir', 'iassign') . "',dirname);
  6540. } while (dirnamecopy == '');
  6541. if (dirnamecopy == null)
  6542. return false;\n
  6543. else {
  6544. for (i=0;i<dirs.length;i++) {
  6545. if (dirs[i]==dirnamecopy) {
  6546. alert('$error_dir_exists');
  6547. return false;\n
  6548. }
  6549. }
  6550. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=rename_dir&ilmid='+ilmid+'&dirid='+dirid+'&dirname='+dirnamecopy;
  6551. }
  6552. }
  6553. function move_selected_ilm (ilmid) {
  6554. var param = getCheckbox();
  6555. if (param.join() != '')
  6556. 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();
  6557. else
  6558. alert('" . get_string('er_file_not_selected_to_move', 'iassign') . "');
  6559. }
  6560. function recover_files_ilm () {
  6561. var msgAnswer;
  6562. msgAnswer = confirm('" . get_string('question_recover_files', 'iassign') . "');
  6563. if (msgAnswer) {
  6564. window.location='" . $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&action=recover&ilmid=" . $ilmid . "&dirid=" . $dirid . "';
  6565. }
  6566. }
  6567. window.onload = function() {
  6568. var xPosition = 0;
  6569. var yPosition = 0;
  6570. element=document.getElementById('new_file');
  6571. while(element) {
  6572. xPosition += (element.offsetLeft - element.scrollLeft + element.clientLeft);
  6573. yPosition += (element.offsetTop - element.scrollTop + element.clientTop);
  6574. element = element.offsetParent;
  6575. }
  6576. document.getElementById('new_file').style.top = '' + (yPosition - 400) + 'px';
  6577. document.getElementById('new_file').style.right = '' + 0 + 'px';
  6578. location.hash = '#new_file';
  6579. };
  6580. //]]>
  6581. </script>\n";
  6582. $output = "";
  6583. $select_all = "";
  6584. $count_files = 0;
  6585. $extensions_allow = array();
  6586. $iassign_ilm = $DB->get_records('iassign_ilm', array("enable" => 1)); // extensions for all iLM...
  6587. foreach ($iassign_ilm as $item_iassign_ilm)
  6588. $extensions_allow = array_merge($extensions_allow, explode(",", $item_iassign_ilm->extension));
  6589. foreach ($files_course as $value) {
  6590. $filename = $value->get_filename();
  6591. $filepath = $value->get_filepath();
  6592. $pathname = explode("/", substr($filepath, 0, strlen($filepath) - 1));
  6593. $pathname = $pathname[count($pathname) - 1];
  6594. $fileid = $value->get_id();
  6595. $tmp = explode(".", $filename);
  6596. if (count($tmp)>1) // avoid error if the file has no extension
  6597. $filetype = $tmp[1];
  6598. else // probably error...
  6599. $filetype = '';
  6600. $author = $value->get_author();
  6601. $timemodified = date("d/m/Y H:i:s", $value->get_timemodified());
  6602. $timecreated = date("d/m/Y H:i:s", $value->get_timecreated());
  6603. $extensions = explode(",", $extension);
  6604. if (in_array(strtolower($filetype), $extensions) || $value->is_directory() || $this->from == 'block' || $this->from == 'tinymce' || $this->from == 'atto') {
  6605. $count_files ++;
  6606. // buscar fileid nas tabelas do iassign
  6607. $list_filein_use = "";
  6608. $iassign_statement_activity_list = $DB->get_records("iassign_statement", array("file" => $fileid));
  6609. if ($iassign_statement_activity_list) {
  6610. foreach ($iassign_statement_activity_list as $iassign_statement_activity_item) {
  6611. $list_filein_use .= $iassign_statement_activity_item->name . "</br>\n";
  6612. }
  6613. }
  6614. $iassign_ilm = $DB->get_record("iassign_ilm", array('extension' => $filetype, 'id' => $ilmid, 'enable' => '1'));
  6615. if (!$iassign_ilm) {
  6616. $iassign_ilm = new stdClass();
  6617. $iassign_ilm->id = $ilmid;
  6618. }
  6619. // Do not use $var inside "..." - problem with some "unusual" operational system
  6620. $url = $CFG->wwwroot . "/pluginfile.php/" . $value->get_contextid() . "/mod_iassign/activity";
  6621. $fileurl = $url . '/' . $value->get_itemid() . $filepath . $filename;
  6622. $dirurl = new moodle_url($this->url) . '&ilmid=' . $iassign_ilm->id . '&dirid=' . $fileid;
  6623. $straux = $CFG->wwwroot . "/mod/iassign/ilm_manager.php?from=" . $this->from . "&id=" . $this->id . "&fileid=" . $fileid . "&";
  6624. $link_add_ilm_iassign = "&nbsp;&nbsp;<a href='" . $straux . "action=addilm&filename=$filename&nbsp;&nbsp;&nbsp;'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6625. $link_add_ilm_tinymce = "&nbsp;&nbsp;<a href='" . $straux . "action=tinymceilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6626. $link_add_ilm_atto = "&nbsp;&nbsp;<a href='" . $straux . "action=attoilm'>" . iassign_icons::insert('add_ilm_iassign') . "</a>\n";
  6627. $check_select = "";
  6628. $link_rename = "";
  6629. $link_delete = "";
  6630. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6631. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6632. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6633. $link_duplicate = "&nbsp;&nbsp;<a href='#' onclick='duplicate_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" .
  6634. iassign_icons::insert('duplicate_iassign') . "</a>\n";
  6635. $link_edit = "&nbsp;&nbsp;" . iassign_icons::insert('no_edit_iassign');
  6636. $link_filter = "&nbsp;&nbsp;<a href='#' onclick='preview_ilm(" . $fileid . "," . $ilmid . ");'>" . iassign_icons::insert('preview_iassign') . "</a>\n";
  6637. if ($value->get_userid() == $USER->id) {
  6638. if ($iassign_statement_activity_list) {
  6639. $check_select = "";
  6640. $link_edit = iassign_icons::insert('edit_iassign_disable');
  6641. $link_delete = "&nbsp;&nbsp;" . iassign_icons::insert('delete_iassign_disable');
  6642. $link_rename = "";
  6643. } else {
  6644. $check_select = "<input name='selected_file' type='checkbox' value='$fileid'/>\n";
  6645. $link_edit = "&nbsp;&nbsp;<a href='#' onclick='update_ilm(\"$iassign_ilm->id\", $fileid)'>" . iassign_icons::insert('edit_iassign') . "</a>\n";
  6646. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_iassign') . "</a>\n";
  6647. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_ilm(\"$iassign_ilm->id\", \"$filename\"," . $fileid . ");'>" . iassign_icons::insert('rename_iassign') . "</a>\n";
  6648. }
  6649. }
  6650. if (!in_array($filetype, $extensions_allow)) {
  6651. $link_edit = "";
  6652. $link_add_ilm_iassign = "";
  6653. $link_add_ilm_tinymce = "";
  6654. $link_add_ilm_atto = "";
  6655. $link_filter = "";
  6656. }
  6657. if ($value->is_directory()) {
  6658. $link_delete = "&nbsp;&nbsp;<a href='#' onclick='delete_dir_ilm(\"$iassign_ilm->id\", $fileid);'>" . iassign_icons::insert('delete_dir') . "</a>\n";
  6659. $link_rename = "&nbsp;&nbsp;<a href='#' onclick='rename_dir_ilm(\"$iassign_ilm->id\", \"" . $pathname . "\"," . $fileid . ");'>" . iassign_icons::insert('rename_dir') . "</a>\n";
  6660. $output .= "<tr><td>$check_select$link_rename$link_delete</td>
  6661. <td><a href='$dirurl' title='" . get_string('dir', 'iassign') . $pathname . "'>" . iassign_icons::insert('dir') . '&nbsp;' . $pathname . "</a></td>
  6662. <td><center>$author</center></td>
  6663. <td><center>$timecreated</center></td>
  6664. <td><center>$timemodified</center></td></tr>\n";
  6665. }
  6666. else if ($this->from == 'iassign') {
  6667. $new_id = "";
  6668. $new_class = "";
  6669. if (isset($_SESSION['file_name']) && $filename == $_SESSION['file_name']) {
  6670. $new_class = "<div id='new_file' style='position: absolute;'></div>"; unset($_SESSION['file_name']);
  6671. $new_id = "id='id_new_blink' style='background-color: hsl(244,61%,90%);'";
  6672. }
  6673. $output .= "<tr $new_id><td>$new_class $check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_iassign</td>
  6674. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6675. <td><center>$author</center></td>
  6676. <td><center>$timecreated</center></td>
  6677. <td><center>$timemodified</center></td></tr>\n";
  6678. }
  6679. else if ($this->from == 'block') {
  6680. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter</td>
  6681. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6682. <td><center>$author</center></td>
  6683. <td><center>$timecreated</center></td>
  6684. <td><center>$timemodified</center></td></tr>\n";
  6685. }
  6686. else if ($this->from == 'tinymce') {
  6687. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_tinymce</td>
  6688. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6689. <td><center>$author</center></td>
  6690. <td><center>$timecreated</center></td>
  6691. <td><center>$timemodified</center></td></tr>\n";
  6692. }
  6693. else if ($this->from == 'atto') {
  6694. $output .= "<tr><td>$check_select$link_rename$link_delete$link_duplicate$link_edit$link_filter$link_add_ilm_atto</td>
  6695. <td><a href='$fileurl' title='" . get_string('download_file', 'iassign') . "$filename'>$filename</a></td>
  6696. <td><center>$author</center></td>
  6697. <td><center>$timecreated</center></td>
  6698. <td><center>$timemodified</center></td></tr>\n";
  6699. }
  6700. }
  6701. }
  6702. $basename = explode("/", substr($dir_base, 0, strlen($dir_base) - 1));
  6703. $dir_base = "";
  6704. $header = "";
  6705. // echo "locallib.php: view_files_ilm(iassign_ilm_class,extension): iassign_ilm_class->extension=" . $iassign_ilm_class->extension . ", extension=" . $extension. "<br/>\n";
  6706. // Get all files in the course context with the associated iLM extension (e.g., iLM=iVProgH => extension "*ivph")
  6707. foreach ($basename as $value) {
  6708. $dir_base .= $value . "/";
  6709. $dir_id = $fs->get_file($context->id, 'mod_iassign', 'activity', 0, $dir_base, '.');
  6710. if ($dir_id) {
  6711. if ($value == "") {
  6712. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6713. $header .= "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "Home'>Home</a>\n";
  6714. } else {
  6715. $fileurl = new moodle_url($this->url) . '&dirid=' . $dir_id->get_id() . '&ilmid=' . $ilmid;
  6716. $header .= "&nbsp;" . $OUTPUT->rarrow() . "&nbsp;<a href='$fileurl' title='" . get_string('dir', 'iassign') . "$dir_base'>$value</a>\n";
  6717. }
  6718. }
  6719. } // foreach ($basename as $value)
  6720. $html = $OUTPUT->heading(iassign_icons::insert('open_dir') . $header, 2, 'dirtitle', 'iassign');
  6721. $select_all = "<input id='select_all' type='checkbox' onclick='select_all_ilm();'/>\n";
  6722. $html .= "
  6723. <table id='outlinetable' class='generaltable boxaligncenter' cellpadding='5' width='100%'>
  6724. <tr><th class='header c1' width='20%'>$select_all " . get_string('functions', 'iassign') . "</th>
  6725. <th class='header c1' width='*'>" . get_string('file', 'iassign') . "</th>
  6726. <th class='header c1' width='10%'>" . get_string('author', 'iassign') . "</th>
  6727. <th class='header c1' width='10%'>" . get_string('file_created', 'iassign') . "</th>
  6728. <th class='header c1' width='10%'>" . get_string('file_modified', 'iassign') . "</th>\n " . $output . "
  6729. </table>\n";
  6730. $html .= "<form id='form_buttons' method='post' enctype='multipart/form-data'>\n";
  6731. $html .= "<table width='100%'><tr>\n";
  6732. $html .= "<td width='80%'><input type='button' value='" . get_string('new_dir', 'iassign') . "' onClick='new_dir_ilm();'>\n";
  6733. if ($count_files != 0) {
  6734. $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";
  6735. $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";
  6736. $html .= "<input type='button' value='" . get_string('file_ilm_export', 'iassign') . "' onClick='export_files_ilm();'>\n";
  6737. }
  6738. $html .= "</td><td width='100%' align='right'><input type='button' value='" . get_string('file_ilm_recover', 'iassign') . "' onClick='recover_files_ilm();'>\n";
  6739. $html .= $OUTPUT->help_icon('file_ilm_recover', 'iassign') . "</td></tr></table>\n";
  6740. $html .= "</form>\n";
  6741. print $code_javascript_ilm;
  6742. print $html;
  6743. } // function view_files_ilm($extension)
  6744. } // class ilm_manager
  6745. /// Class to insert of icons
  6746. class iassign_icons {
  6747. static function insert ($icon) {
  6748. global $CFG;
  6749. $string = '<img src="' . $CFG->wwwroot . '/mod/iassign/icon/' . $icon . '.gif" title="' . get_string($icon, 'iassign') . '" alt="' . get_string($icon, 'iassign') . '"/>'; // "\n"
  6750. return $string;
  6751. }
  6752. }
  6753. /// Class with util functions for plugin manage
  6754. class iassign_utils {
  6755. /// Function to return the filename extension
  6756. // @param string The $filename as an string
  6757. // @return string Return an string (last group after '.')
  6758. static function filename_extension ($filename) {
  6759. if ($filename == null || $filename == '') {
  6760. return null;
  6761. }
  6762. $itens = explode('.', $filename);
  6763. $num = count($itens);
  6764. if ($num < 2) {
  6765. return null;
  6766. }
  6767. return $itens[$num - 1];
  6768. }
  6769. /// Use the PHP class/package ZipArchive to create a Zip file
  6770. // The version 1 with ZipArchive (with '$zip->addFile(...)') is NOT working:
  6771. // 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
  6772. // @param $full_path_zip_filename, $vet_student_filename, $vet_student_content
  6773. static function register_temporary_file ($full_path_zip_filename, $vet_student_filename, $vet_student_content) {
  6774. //1 $zip = new ZipArchive(); //TODO this version uses '$zip->addFile(...)' and it is NOT working!
  6775. $zip = new zip_archive(); //2
  6776. $res = $zip->open($full_path_zip_filename);
  6777. $total_vet = count($vet_student_filename);
  6778. for ($ii=0; $ii<$total_vet; $ii++) {
  6779. // $zip->addFile($vet_student_filename[$ii], $vet_student_content[$ii]); //1 to ZipArchive
  6780. $zip->add_file_from_string($vet_student_filename[$ii], $vet_student_content[$ii]); //2 to zip_archive
  6781. }
  6782. $ret = $zip->close();
  6783. iassign_utils::download_file($full_path_zip_filename);
  6784. $filenameZip = $zip->filename;
  6785. return array($ret, $zip);
  6786. }
  6787. static function download_file ($zip_filename) {
  6788. header("Pragma: public");
  6789. header("Expires: 0");
  6790. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  6791. header("Cache-Control: private", false);
  6792. header("Content-Type: application/zip");
  6793. header("Content-Disposition: attachment; filename=\"" . basename($zip_filename) . "\";");
  6794. header("Content-Transfer-Encoding: binary");
  6795. header("Content-Length: " . @filesize($zip_filename));
  6796. set_time_limit(0);
  6797. @readfile("$zip_filename") || die("File not found.");
  6798. unlink($zip_filename);
  6799. }
  6800. /// Function for format filename remove special caracters
  6801. // @param string $text String for clean
  6802. // @param boolean $is_lowercase Boolean for apply lowercase in filename
  6803. // @return string Return an string in clean format
  6804. static function format_filename ($text) {
  6805. if ($text != '.') {
  6806. //D $text = htmlspecialchars(urldecode($text));
  6807. //D echo "locallib.php: format_filename: $text<br/>";
  6808. if (is_object($text)) // with iAssign did not filtered text from JSON format
  6809. $text = json_decode($text)->{current_language()};
  6810. // $text = htmlspecialchars($text); // not good ideia, it results strange at 'iassign_ilm' field
  6811. $array1 = array("(", ")", ",", "/", "\\", "!", "@", "#", "$", "&", "*", "+", "!", "?", ".", " ",
  6812. "á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "ẽ", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü",
  6813. "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç");
  6814. $array2 = array("", "", "_", "_", "_", "", "", "", "", "", "", "", "", "", "_", "_",
  6815. "a", "a", "a", "a", "a", "e", "e", "e", "e", "e", "i", "i", "i", "i", "o", "o", "o", "o", "o", "u", "u", "u", "u",
  6816. "c", "A", "A", "A", "A", "A", "E", "E", "E", "E", "I", "I", "I", "I", "O", "O", "O", "O", "O", "U", "U", "U", "U", "C");
  6817. // E.g. text = "exerc_midpoint.course.geo"
  6818. // 0123456789012345678901234
  6819. $index_lastposition = strrpos($text, "."); // Find the position of the last occurrence of a substring in a string (21)
  6820. $text2 = substr($text, 0, $index_lastposition); // Erase the final point and its extension ("exerc_midpoint.course")
  6821. $ext = substr($text, $index_lastposition); // Point with extention (".geo")
  6822. $text = str_replace(".", "", $text2) . $ext; // Clear any other point and redefine the name ("exerc_midpoint.course.geo")
  6823. $text = str_replace($array1, $array2, $text); // Replace any letter with accent mark under the UTF8 format
  6824. //$ext = strrpos($text, ".");
  6825. //$text = str_replace(".", "", substr($text, 0, $ext)).substr($text, $ext);
  6826. //$text = str_replace($array1, $array2, $text);
  6827. }
  6828. return $text;
  6829. }
  6830. /// Function to filter characters to the file name to iLM content
  6831. // @param string $text String for clean
  6832. // @param string $ext String ot the extension of the iLM
  6833. // @return string Return an string in clean format
  6834. static function filter_filename_extension ($filename, $ext) {
  6835. if ($filename != '.') {
  6836. $arrFrom = array("=","~","`","!","@","$","%","^","&","*","(",")");
  6837. $arrTo = array("_","","","","","","","","","","","","");
  6838. $filename = str_replace($arrFrom, $arrTo, $filename);
  6839. //D echo "locallib.php: filter_filename_extension: 1 : " . $filename . "<br/>";
  6840. $filenameF = preg_replace('/[^\x20-\x7E]/','', $filename); // only ASCII - https://stackoverflow.com/questions/8781911/remove-non-ascii-characters-from-string
  6841. $index_lastposition = strrpos($filenameF, "."); // find the position of the last occurrence of a substring in a string (21)
  6842. if (!isset($index_lastposition) || $index_lastposition=="" || $index_lastposition<0) // Just in case (logic of function 'strrpos(...)' change, ensure to preserve name without '.'
  6843. $index_lastposition = strlen($filenameF);
  6844. $text = substr($filenameF, 0, $index_lastposition); // erase the final point and its extension ("exerc_midpoint.course")
  6845. $text = str_replace(".", "_", $text); // erase all other "."
  6846. $existext = substr($filenameF, $index_lastposition); // get the possibly extension
  6847. $filenameF = $text . "." . $ext; // no matter, use the prefiz with oficial extension
  6848. }
  6849. else
  6850. $filenameF = 'file_without_name.' . $ext; // Just in case... if the use do not enter a valid name, only entered '.'!
  6851. return $filenameF;
  6852. }
  6853. /// Function for format pathname remove special caracters
  6854. // @param string $text String for clean
  6855. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6856. // @return string Return an string in clean format
  6857. static function format_pathname ($text, $is_lowercase = true) {
  6858. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6859. $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", "-", "_", "", "", "");
  6860. $text = str_replace($array1, $array2, $text);
  6861. if ($is_lowercase)
  6862. $text = strtolower($text);
  6863. return $text;
  6864. }
  6865. /// Function for format file name from iLM original name
  6866. // @param string $text String to build the file neam
  6867. // @param boolean $is_lowercase Boolean for apply lowercase in pathname
  6868. // @return string Return an string in clean format
  6869. static function filename_from_iLM_name ($ilm_name, $is_lowercase = true) {
  6870. $array1 = array("á", "à", "â", "ã", "ä", "é", "è", "ê", "ë", "í", "ì", "î", "ï", "ó", "ò", "ô", "õ", "ö", "ú", "ù", "û", "ü", "ç", "Á", "À", "Â", "Ã", "Ä", "É", "È", "Ê", "Ë", "Í", "Ì", "Î", "Ï", "Ó", "Ò", "Ô", "Õ", "Ö", "Ú", "Ù", "Û", "Ü", "Ç", "@", " ", "!", "?", ".");
  6871. $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", "-", "_", "", "", "");
  6872. $index_firstposition_blank = strpos($ilm_name, " ");
  6873. if ($index_firstposition_blank) { // truncate the name!
  6874. $ilm_name = substr($ilm_name, 0, $index_firstposition_blank);
  6875. }
  6876. $index_firstposition_dots = strpos($ilm_name, ":");
  6877. if ($index_firstposition_dots) { // truncate the name!
  6878. $ilm_name = substr($ilm_name, 0, $index_firstposition_dots);
  6879. }
  6880. $namefiltered = str_replace($array1, $array2, $ilm_name);
  6881. if ($is_lowercase)
  6882. $namefiltered = strtolower($namefiltered);
  6883. return $namefiltered;
  6884. }
  6885. /// Function for insert version in the filename
  6886. // @param string $filename Name of file
  6887. // @return string Return the filename with version
  6888. static function version_filename ($filename) {
  6889. $array_filename = explode('.', $filename);
  6890. if (count($array_filename) > 1)
  6891. $filename = $array_filename[0] . '-' . date("Ymd-His") . '.' . $array_filename[1];
  6892. else
  6893. $filename = $array_filename[0] . '-' . date("Ymd-His");
  6894. return $filename;
  6895. }
  6896. //TODO Retirar quando atualizar todo os iassign que estão com a tag &lt;ia_uc&gt;
  6897. static function remove_code_message ($string) {
  6898. $array = explode("&lt;ia_uc&gt;", $string);
  6899. return $array[0];
  6900. }
  6901. }
  6902. // class iassign_utils
  6903. /// Class with language functions for plugin manage
  6904. class iassign_language {
  6905. /// Function for return text in language or get default language (en)
  6906. // @param string $lang Code of language
  6907. // @param string $description JSON text content all languages
  6908. // @return string Return an string in the language selected
  6909. static function get_description_lang ($lang, $descriptions) {
  6910. $description_lang = "";
  6911. $description = json_decode($descriptions);
  6912. if ($description == null) {
  6913. $description_lang = $descriptions;
  6914. }
  6915. else {
  6916. if (isset($description->{$lang}))
  6917. $description_lang = $description->{$lang};
  6918. else
  6919. if (isset($description->en)) //MOOC2014
  6920. $description_lang = $description->en;
  6921. else //MOOC2014
  6922. $description_lang = "en"; //MOOC2014
  6923. }
  6924. return $description_lang;
  6925. }
  6926. /// Function for return all language supported by iLM
  6927. // @param string $descriptions JSON text content all languages
  6928. // @return string Return as string with all languages
  6929. static function get_all_lang ($descriptions) {
  6930. $langs = "";
  6931. $description = json_decode($descriptions);
  6932. if ($description) {
  6933. foreach ($description as $key => $value) {
  6934. $langs .= $key . " ; ";
  6935. }
  6936. $langs = substr($langs, 0, strlen($langs) - 3);
  6937. }
  6938. return $langs;
  6939. }
  6940. /// Function for convert json in xml //MOOC2014
  6941. // @param string $json JSON text
  6942. // @return string Return as string with xml tags
  6943. static function json_to_xml ($json) {
  6944. $xml = "";
  6945. $json = json_decode($json);
  6946. foreach ($json as $key => $value) {
  6947. $xml .= "\n <" . $key . ">" . $value . "</" . $key . ">";
  6948. }
  6949. return $xml;
  6950. }
  6951. }
  6952. // class iassign_language
  6953. /// Class with log functions for plugin manage.
  6954. class iassign_log {
  6955. /// Function for insert log event
  6956. // @param string $action Code action of event
  6957. // @param string $information Text for describe action of event
  6958. // @param int $cmid Id of context module
  6959. // @param int $ilmid Id of iLM
  6960. static function add_log ($action, $information = "", $cmid = 0, $ilmid = 0) {
  6961. global $COURSE, $CFG, $USER, $DB;
  6962. $newentry = new stdClass();
  6963. $newentry->time = time();
  6964. $newentry->userid = $USER->id;
  6965. $newentry->ip = $_SERVER['REMOTE_ADDR'];
  6966. $newentry->course = $COURSE->id;
  6967. $newentry->cmid = $cmid;
  6968. $newentry->ilmid = $ilmid;
  6969. $newentry->action = $action;
  6970. $newentry->info = $information;
  6971. $newentry->language = current_language();
  6972. $newentry->user_agent = $_SERVER['HTTP_USER_AGENT'];
  6973. if (ini_get("browscap") && function_exists('get_browse')) {
  6974. $browser = get_browse(null, true);
  6975. $newentry->javascript = $browser['javascript'];
  6976. $newentry->java = $browser['javaapplets'];
  6977. }
  6978. if (!$newentry->id = $DB->insert_record("iassign_log", $newentry))
  6979. print_error('error_add_log', 'iassign');
  6980. } // static function add_log($action, $information = "", $cmid = 0, $ilmid = 0)
  6981. } // class iassign_log